小编典典

使用Java API在Elasticsearch中创建索引并添加映射会丢失分析器错误

elasticsearch

代码在Scala中。它与Java代码极为相似。

我们的地图索引器用于创建索引的代码:https :
//gist.github.com/a16e5946b67c​​6d12b2b8

上面的代码用于创建索引和映射的实用程序:https :
//gist.github.com/4f88033204cd761abec0

Java给出的错误:https :
//gist.github.com/d6c835233e2b606a7074

运行代码并获取错误后http://elasticsearch.domain/maps/_settings的响应:https
://gist.github.com/06ca7112ce1b01de3944

JSON文件:https
//gist.github.com/bbab15d699137f04ad87
https://gist.github.com/73222e300be9fffd6380

附件是我正在加载的json文件。我已经确认它正在加载正确的json文件,并将其作为字符串正确输出到.loadFromSource和.setSource中。

有什么想法为什么即使在_settings中也找不到分析器?如果我通过curl运行这些json文件,它们可以正常工作并正确设置映射。


阅读 564

收藏
2020-06-22

共1个答案

小编典典

我用来创建索引的代码(可在此处找到:使用JavaAPI定义自定义ElasticSearchAnalyzer正在索引中创建设置,例如:

“ index.settings.analysis.filter.my_snow.type:” stemmer“,”

它在设置路径中有设置。

我将索引代码更改为以下内容以解决此问题:

def createIndex(client: Client, indexName: String, indexFile: String) {
  //Create index
    client.admin().indices().prepareCreate(indexName)
    .setSource(Utils.loadFileAsString(indexFile))
    .execute()
    .actionGet()
}
2020-06-22