0

I have multiple indices to index data from Firebase to Elasticsearch.

I am using client.indices.putTemplate to put template in the elasticsearch. which is successfully getting saved, but the same is not being used when the indexer starts to index the data.

my indexer uses :

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);
    }
  });
}

account is an object :

account: {
  type: 'account',
  index: 'accounts',
  template: accountsTemplate,
}

finally accountsTemplate is the actual template with the below data:

{
  "template": "account*",
  "settings" : {
      "number_of_shards" : 1
  },
  "mappings" : {
    "account" : {
      "properties" : {
        "email" : {
          "type" : "string"
        }
      }
    }
  }
}

when I run the indexer, it does not index based on the saved the template, and gives the error as

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\"

I even see that the template is saved.

curl -XGET localhost:9200/_template/account?pretty

the indexer:

this.elasticSearchClient.index({
  index: this.index,
  type: this.type,
  id: key,
  body: data }, (error, response) => {
  if (callback) {
    callback(error, response);
  }
});

References:

using elasticssearch client to create indices
Creating an empty index in elasticsearch in node.js
Where do I put the mapping files for Elasticsearch?

Community
  • 1
  • 1
Rohit
  • 71
  • 5
  • i am not sure about it but try using `this.elasticSearchClient.create` in place of `this.elasticSearchClient.index` – blackmamba Sep 09 '16 at 13:28
  • https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/api-reference.html compare .index and .create function – blackmamba Sep 09 '16 at 13:30

1 Answers1

0

The elastic search mapping document says that : when you pass the index name in the call, and provide the mapping for that index, then the index is first created and then the mapping is feeded to that index.

But, in elasticsearch.js, this is a problem. The API for this has not been implemented.

I have created a PR to it and waiting for the response.

Ideally, for me mapping was on of the issues, and forking this has made my work done.

if anyone wants to use this functionality, you can use my repo.

Rohit
  • 71
  • 5