Lucene compatibility issue when trying to use spring data opensearch

Hello team,

Im running into org.apache.lucene compatibility issue when i try to use elastic and spring-data-opensearch in same project.

I’m using spring-data-opensearch dependency

org.opensearch.client
spring-data-opensearch
1.3.0

Source → GitHub - opensearch-project/spring-data-opensearch

Detailed description:

  1. When we add above dependency and trying try building query using QueryBuilders.wrapperQuery(query) I get error saying
    java.lang.NoSuchFieldError: LUCENE_8_8_2
    at org.opensearch.Version.(Version.java:74)
    at org.opensearch.core.common.io.stream.StreamOutput.(StreamOutput.java:107)
  2. Hence explicitly specified the LUCENE version like below to 8_8_2 but I get same above error all the way till I increase the version to 9.1.0

    org.apache.lucene
    lucene-core
    8.8.2
  3. Once moving to LUCENE_9_1_1 we get java.lang.NoSuchFieldError: LUCENE_7_0_0 like below from elastic
    org.apache.lucene error from elastic bean
    Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘elasticsearchTemplate’ defined in class path resource [org/springframework/boot/autoconfigure/data/elasticsearch/ElasticsearchDataConfiguration$RestClientConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate]: Factory method ‘elasticsearchTemplate’ threw exception; nested exception is java.lang.NoSuchFieldError: LUCENE_7_0_0
  4. When we remove elastic dependencies completely we get
    org.springframework.beans.factory.BeanDefinitionStoreException: Failed to read candidate component class: file [/Users/develop/opensearch/spring-client/opensearch-test/target/classes/com/opensearchtest/indexing/doc/UsageDocument.class]; nested exception is java.lang.NoClassDefFoundError: org/elasticsearch/index/VersionType
    Hence we were supposed to add the elastic dependency to our project.

    org.elasticsearch.client
    elasticsearch-rest-high-level-client
    7.4.2

Please let me know in case anyone face similar issue or suggest me an alternative way to include spring-data-opensearch.

Hello @Saravanan , I am afraid you could not use both at the same project - there are conflicting dependencies which OpenSearch and Elasticsearch use.

Hello @reta, Thanks for the response, I’m using couple of annotations like Id and Document which are all part of the elastic dependency. spring-boot opensearch is importing elastic version of 5.2.1 which is conflicting. I have projects that use both elastic and opensearch, works fine with opensearch client dependency. Only when i try to import spring-boot opensearch I’m running into mentioned issue.

Hello @Saravanan

I’m using couple of annotations like Id and Document which are all part of the elastic dependency.

This totally fine - Spring Data OpenSearch is built on top of Spring Data Elasticsearch, the problem is that you also have a dependencies on Elasticsearch client libraries and it causes issues (Spring Data OpenSearch excludes those and replaces with OpenSearch client). Hope it helps.

Thank you

Yes, That is where I get the incompatibility issue after I remove either one of the dependencies I get bean exception which I explained in #4

I am afraid the only way you could make it work is to find out the OpenSearch client version that at least is compatible (on dependencies level) with Elasticsearch client your are using. But again, this is very fragile and not something we would recommend doing.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.