0
votes

I'm trying to create ad index with custom settings as explained here. I'm using ElasticSearch 6.3

This is my code:

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);
    }

I've this exception though:

ElasticsearchStatusException[Elasticsearch exception [type=illegal_argument_exception, reason=unknown setting [index.settings.analysis.analyzer.autocomplete.filter] please check that any required plugins are installed, or check the breaking changes documentation for removed settings]]

I'm using a AWS ElasticSearch instance. I prefer to use the builder rather than plain JSON to create my settings request. Am I doing something wrong?

1

1 Answers

2
votes

I found the problem. It seems keys must not include the settings prefix.

The working code is so:

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);
}