elastic / elasticsearch-java

Official Elasticsearch Java Client
Apache License 2.0
408 stars 237 forks source link

I can't provide a set of synonyms when creating the analyzer #781

Closed powfyy closed 3 months ago

powfyy commented 4 months ago

Java API client version

8.13.2

Java version

17

Elasticsearch Version

8.12.2

Problem description

Hello, I read in the documentation: "Use synonyms_set configuration option to provide a synonym set created via Synonyms Management APIs:", but the SynonymGraphTokenFilter class does not have a corresponding field, there are only synonyms (String) and synonymsPath. How can I provide a set of synonyms?

private final ElasticsearchClient client;

client.indices().create(
        new CreateIndexRequest.Builder()
          .index(INDEX_PREFIX + "_" + name)
          .settings(new IndexSettings.Builder()
            .numberOfShards(SHARDS)
            .numberOfReplicas(REPLICAS)
            .analysis(new IndexSettingsAnalysis.Builder()
              .analyzer("search_analyzer", new Analyzer.Builder()
                .custom(new CustomAnalyzer.Builder()
                  .tokenizer("standard")
                  .filter("synonym_graph")
                  .build())
                .build())
              .filter("synonym_graph", new TokenFilter.Builder()
                .definition(new TokenFilterDefinition.Builder()
                  .synonymGraph(new SynonymGraphTokenFilter.Builder()

                    .updateable(true)
                    .build())
                  .build())
                .build())
              .build())
            .build())
          .build()
      );
avaudo commented 4 months ago

I am running into the same exact issue but with the .Net library. I have created the issue here:

https://github.com/elastic/elasticsearch-net/issues/8125

l-trotta commented 4 months ago

Hello, thanks for reporting this! The property is missing from the API specification which is used to generate the clients, so that's why this issue can also be found in the .NET one. We'll fix it and then regenerate the client to solve this.

l-trotta commented 4 months ago

also while waiting for a fix, here's how to shorten that request using the lambda version of the builders :D

        client.indices().create(c -> c
            .index(INDEX_PREFIX + "_" + name)
            .settings(s -> s
                .numberOfShards(SHARDS)
                .numberOfReplicas(REPLICAS)
                .analysis(an -> an
                    .analyzer("search_analyzer", anl -> anl
                        .custom(cu -> cu
                            .tokenizer("standard")
                            .filter("synonym_graph")))
                    .filter("synonym_graph", tf -> tf
                        .definition(def -> def
                            .synonymGraph(syn -> syn
                                .updateable(true))
                        )))));
powfyy commented 4 months ago

Thank you for your responsiveness <3

avaudo commented 4 months ago

Thank you. Do you know about how long this would take to be released?

l-trotta commented 4 months ago

That depends on the client, but it's usually the next version after the api spec has been fixed

l-trotta commented 3 months ago

fixed in 8.13.4!