代码在 Scala 中。它与 Java 代码极为相似。
我们的 map 索引器用于创建索引的代码:https://gist.github.com/a16e5946b67c6d12b2b8
上述代码用于创建索引和映射的实用程序: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 文件,它们可以正常工作并正确设置映射。
最佳答案
我用来创建索引的代码(可在此处找到:Define custom ElasticSearch Analyzer using Java API)在索引中创建如下设置:
"index.settings.analysis.filter.my_snow.type: "词干分析器","
它在设置路径中有设置。
我将索引代码更改为以下内容以解决此问题:
def createIndex(client: Client, indexName: String, indexFile: String) {
//Create index
client.admin().indices().prepareCreate(indexName)
.setSource(Utils.loadFileAsString(indexFile))
.execute()
.actionGet()
}
关于java - 使用 java api 在 Elasticsearch 中创建索引和添加映射会导致缺少分析器错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14608196/