elastic / elasticsearch-java

Official Elasticsearch Java Client
Apache License 2.0
409 stars 239 forks source link

Error When Creating Index with SynonymsSet in Elasticsearch #862

Closed Roy-onout closed 1 month ago

Roy-onout commented 1 month ago

Java API client version

8.15.0

Java version

17

Elasticsearch Version

8.15.0

Problem description

I'm encountering an error while trying to create an Elasticsearch index using a custom synonym filter. The error occurs when setting up the index with a synonymsSet for the synonymGraph filter. Below is the Kotlin code snippet used for creating the index:

        val createIndexRequest = CreateIndexRequest.Builder()
            .index(indexName)
            .settings(
                IndexSettings.Builder()
                    .analysis {
                        it.filter("synonyms_filter") { filter ->
                            filter.definition {
                                it.synonymGraph { synonym ->
                                    synonym.synonymsSet("os_synonyms_sample")
                                }
                                it
                            }
                        }
                        it.analyzer(EsConstants.SYNONYM_ANALYZER) { analyzer ->
                            analyzer.custom { custom ->
                                custom.filter("synonyms_filter")
                                custom.tokenizer(EsConstants.NORI_TOKENIZER)
                                custom
                            }
                        }
                        it
                    }.build()
            )
            .mappings { mapping ->
                EsProduct.mappings(mapping)
            }.build()

The following error is encountered during execution:

Handler dispatch failed: java.lang.NoSuchMethodError: 'co.elastic.clients.elasticsearch._types.analysis.SynonymGraphTokenFilter$Builder co.elastic.clients.elasticsearch._types.analysis.SynonymGraphTokenFilter$Builder.synonymsSet(java.lang.String)'
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1104) ~[spring-webmvc-6.1.5.jar:6.1.5]
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:979) ~[spring-webmvc-6.1.5.jar:6.1.5]
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1014) ~[spring-webmvc-6.1.5.jar:6.1.5]
    at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:903) ~[spring-webmvc-6.1.5.jar:6.1.5]

Steps to Reproduce Create a synonyms set using the /_synonyms API with the name os_synonyms_sample. Attempt to create an index with the above Kotlin code, which includes a custom analyzer and synonym graph filter.

Expected Behavior The index should be created successfully with the synonym filter applied using the specified synonym set.

Actual Behavior A NoSuchMethodError is thrown, indicating that the synonymsSet method is not found in the SynonymGraphTokenFilter$Builder class.