0

我有多个索引来索引从 Firebase 到 Elasticsearch 的数据。

我正在使用client.indices.putTemplate将模板放入弹性搜索中。已成功保存,但在索引器开始索引数据时未使用相同的内容。

我的索引器使用:

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 是一个对象:

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

最后 accountsTemplate 是具有以下数据的实际模板:

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

当我运行索引器时,它不会根据保存的模板进行索引,并给出错误为

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

我什至看到模板已保存。

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

索引器:

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

参考:

使用 elasticssearch 客户端创建索引
在 node.js 中的 elasticsearch 中创建一个空索引我在
哪里放置 Elasticsearch 的映射文件?

4

1 回答 1

0

弹性搜索映射文档说:当您在调用中传递索引名称并为该索引提供映射时,首先创建索引,然后将映射馈送到该索引。

但是,在 elasticsearch.js 中,这是一个问题。用于此的 API 尚未实现。

我已经为它创建了一个 PR 并等待响应。

理想情况下,对我来说,映射是问题所在,并且分叉这使我的工作完成。

如果有人想使用此功能,您可以使用我的repo

于 2016-09-15T19:22:11.787 回答