代码之家  ›  专栏  ›  技术社区  ›  drenda

ElasticSearch高级API使用自定义设置创建索引返回错误

  •  0
  • drenda  · 技术社区  · 5 年前

    我正试图用自定义设置创建广告索引,如前所述 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异常 [类型=非法参数异常,原因=未知设置 [index.settings.analysis.analyzer.autocomplete.filter]请检查 是否安装了任何必需的插件,或检查是否发生了中断更改 删除设置的文档]]

    我正在使用一个aws弹性搜索实例。我更喜欢使用构建器而不是简单的json来创建我的设置请求。 我做错什么了吗?

    1 回复  |  直到 5 年前
        1
  •  1
  •   drenda    5 年前

    我发现了问题。似乎钥匙不应该包括 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);
    }