Ich habe mehrere Indizes, um Daten von Firebase zu Elasticsearch zu indizieren.Elasticsearch verwendet keine Vorlage und Zuordnung beim Indexieren von Daten aus Firebase
Ich verwende client.indices.putTemplate
, um Vorlage in die Elasticsearch zu setzen. Das wird erfolgreich gespeichert, aber dasselbe wird nicht verwendet, wenn der Indexer mit dem Indizieren der Daten beginnt.
meine Indexer verwendet:
initTemplate(account) {
this.eSClient.indices.putTemplate({
name: account.type,
body: account.template,
}, (error, response) => {
if (error) {
console.error('error while storing template ', error);
} else {
console.log('template stored', response);
}
});
}
Konto ist ein Ziel:
account: {
type: 'account',
index: 'accounts',
template: accountsTemplate,
}
schließlich accountsTemplate ist die eigentliche Vorlage mit den folgenden Daten:
{
"template": "account*",
"settings" : {
"number_of_shards" : 1
},
"mappings" : {
"account" : {
"properties" : {
"email" : {
"type" : "string"
}
}
}
}
}
, wenn ich den Indexer laufe Es indiziert nicht basierend auf der gespeicherten Vorlage und gibt den Fehler
failed to index accounts/account/ff946b57-517a-4b88-a322-5b590e6a40c9: [index_not_found_exception] no such index, with { resource.type=index_expression
{\"root_cause\":[{\"type\":\"index_not_found_exception\",\"reason\":\"no such index\"
Ich sehe sogar, dass die Vorlage gespeichert wird.
curl -XGET localhost:9200/_template/account?pretty
der Indexer:
this.elasticSearchClient.index({
index: this.index,
type: this.type,
id: key,
body: data }, (error, response) => {
if (callback) {
callback(error, response);
}
});
Referenzen:
using elasticssearch client to create indices
Creating an empty index in elasticsearch in node.js
Where do I put the mapping files for Elasticsearch?
Ich bin mir nicht sicher, aber versuchen Sie 'this.elasticSearchClient.create' anstelle von' this.elasticSearchClient.index' – blackmamba
https://www.elastic.co/guide/en/elasticsearch/client/javascript- api/current/api-reference.html Vergleichen Sie die .index- und .create-Funktion – blackmamba