具有自定义设置的ElasticSearch高级API创建索引返回错误

时间:2019-01-23 15:33:01

标签: java elasticsearch

我正在尝试使用here中所述的自定义设置来创建广告索引。我正在使用ElasticSearch 6.3

这是我的代码:

public CreateIndexResponse createIndex(@NotNull String indexName) throws IOException {
        CreateIndexRequest request = new CreateIndexRequest();
        request.index(indexName);
        Settings.Builder settingsBuilder =
                Settings.builder()
                        .put("settings.analysis.filter.autocomplete_filter.type", "edge_ngram")
                        .put("settings.analysis.filter.autocomplete_filter.min_gram", "1")
                        .put("settings.analysis.filter.autocomplete_filter.max_gram", "10")
                        .put("settings.analysis.analyzer.autocomplete.type", "custom")
                        .put("settings.analysis.analyzer.autocomplete.tokenizer", "standard")
                        .putList("settings.analysis.analyzer.autocomplete.filter", "lowercase", "autocomplete_filter");
        request.settings(settingsBuilder);
        return elasticSearchClient.indices().create(request, RequestOptions.DEFAULT);
    }

不过我有这个例外情况:

  

ElasticsearchStatusException [Elasticsearch异常   [type = illegal_argument_exception,原因=未知设置   [index.settings.analysis.analyzer.autocomplete.filter]请检查   是否已安装任何必需的插件,或检查重大更改   删除设置的文档]]

我正在使用AWS ElasticSearch实例。我更喜欢使用构建器而不是普通的JSON来创建我的设置请求。 我在做错什么吗?

1 个答案:

答案 0 :(得分:0)

我发现了问题。似乎密钥不能包含settings前缀。

工作代码如下:

public CreateIndexResponse createIndex(@NotNull String indexName) throws IOException {
    CreateIndexRequest request = new CreateIndexRequest();
    request.index(indexName);
    Settings.Builder settingsBuilder =
            Settings.builder()
                    .put("analysis.filter.autocomplete_filter.type", "edge_ngram")
                    .put("analysis.filter.autocomplete_filter.min_gram", "1")
                    .put("analysis.filter.autocomplete_filter.max_gram", "10")
                    .put("analysis.analyzer.autocomplete.type", "custom")
                    .put("analysis.analyzer.autocomplete.tokenizer", "standard")
                    .putList("analysis.analyzer.autocomplete.filter", "lowercase", "autocomplete_filter");
    request.settings(settingsBuilder);
    return elasticSearchClient.indices().create(request, RequestOptions.DEFAULT);
}