Elastic search depreciated classes

i want to migrate elastic search from 2.x to 6.x.

In this process created new indexed and loaded data from DB to ES 6.x but in service layer(java) facing some issue like below

orQueryBuilder.add(QueryBuilders.termQuery("middleSchoolInd", "true"))

orQueryBuilder is depreciated so can i use code like below

QueryBuilders.boolQuery().filter(QueryBuilders.termQuery("highSchoolInd", "true"));

Calling should clause is more appropriate IMO.

so modified my code as

private void addSchoolAgeFilters(BoolQueryBuilder orQueryBuilder, SchoolSearchForm form) { // actual code

//below code is actual code
if (form.isMiddle()) {

       // orQueryBuilder.add(QueryBuilders.termQuery("middleSchoolInd", "true"));

//modified code as below, is it right?
orQueryBuilder.should(QueryBuilders.termQuery("middleSchoolInd", "true"));
}

Please format your code using </> icon as explained in this guide. It will make your post more readable.

Or use markdown style like:

```
CODE
```

It looks good to me.

Getting this error "The method add(RangeQueryBuilder) is undefined for the type QueryBuilder"

 private void addLocationFilter(QueryBuilder andQueryBuilder, SchoolSearchForm form) {
          
      	andQueryBuilder.add(QueryBuilders.rangeQuery("location.lat").gte(form.getMinLat()).lte(form.getMaxLat()));
        andQueryBuilder.add(QueryBuilders.rangeQuery("location.lon").gte(form.getMinLng()).lte(form.getMaxLng()));
    }

That's true. QueryBuilder does not have a add() method.

It's unclear what kind of result you want to have. But if you have a BoolQueryBuilder, you can use filter(xxx) and add any filter you want (your range query).

BTW this is super weird that you are doing "manual" filtering on lat/lon as we have dedicated geo_point fields and specific queries for them.

Commented code is old error code , next to commented code is new code which cleared error, please suggest is it right?

  private void addAllSchoolFilters(QueryBuilder andQuery, SchoolSearchForm form) {
        if (form.hasAgeFilter()) {
        	// OrQueryBuilder orQb = QueryBuilders.orQuery();
        	 BoolQueryBuilder orQb = QueryBuilders.boolQuery();
        	this.addSchoolAgeFilters(orQb, form);
        	
           // andQuery.add(orQb);
            QueryBuilders.boolQuery().filter(orQb);
        }

 private void addLocationFilter(QueryBuilder andQueryBuilder, SchoolSearchForm form) {//andQueryBuilder.add(QueryBuilders.rangeQuery("location.lat").gte(form.getMinLat()).lte(form.getMaxLat()));
        	QueryBuilders.boolQuery().filter(QueryBuilders.rangeQuery("location.lat").gte(form.getMinLat()).lte(form.getMaxLat()));
        		
           //andQueryBuilder.add(QueryBuilders.rangeQuery("location.lon").gte(form.getMinLng()).lte(form.getMaxLng()));
        	QueryBuilders.boolQuery().filter(QueryBuilders.rangeQuery("location.lon").gte(form.getMinLng()).lte(form.getMaxLng()));
        }

It's unclear to me what you are getting in QueryBuilder andQuery or QueryBuilder andQueryBuilder.

Anyway, you can write something like:

client.search(new SearchRequest()
    .source(new SearchSourceBuilder().query(
            QueryBuilders.boolQuery()
                .filter(QueryBuilders.rangeQuery("location.lat").gte(0).lte(0))
                .filter(QueryBuilders.rangeQuery("location.lon").gte(0).lte(0))
    ))
);
QueryBuilders.boolQuery().filter(QueryBuilders.rangeQuery("location.lon").gte(form.getMinLng()).lte(form.getMaxLng()));

Its works for me, is it right way?

Is there any url to check for the depreciated/replacement classes and methods to migrate to ES 6.1.0 for java api

It looks ok. But as I said it's a strange way to query for location points.

BTW this is super weird that you are doing "manual" filtering on lat/lon as we have dedicated geo_point fields and specific queries for them.

Ok Thanks, Please let me know is there any url for check the depreciated/replacement classes and methods to migrate to ES 6.1.0 for java api from ES 2.3.4

No. Not from 2.x to 6.x.
But if you are using the 5.6 version, then I think that most of the deprecated methods as marked as @Deprecated.

Spring doesn't support elasticsearch 6.1.0 right?

We have to use Rest client , customised code written by our self? Base on the below url

Indeed. I did not update the project for a long time. I just opened

Note that it might be possible to use the older version by also adding:

        <dependency>
            <groupId>fr.pilato.elasticsearch</groupId>
            <artifactId>elasticsearch-beyonder</artifactId>
            <version>5.1</version>
        </dependency>
        <dependency>
            <groupId>org.elasticsearch.client</groupId>
            <artifactId>elasticsearch-rest-client</artifactId>
            <version>6.1.2</version>
        </dependency>

(Not tested though)

1 Like

getting this error after tried to integrate spring and elastic search

 <dependency>
            <groupId>fr.pilato.elasticsearch</groupId>
            <artifactId>elasticsearch-beyonder</artifactId>
            <version>5.1</version>
        </dependency>
        <dependency>
            <groupId>org.elasticsearch.client</groupId>
            <artifactId>elasticsearch-rest-client</artifactId>
            <version>6.1.2</version>
        </dependency>
         <dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-elasticsearch</artifactId>
            <version>3.0.2.RELEASE</version>  </dependency>
            
         <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-elasticsearch</artifactId>
        <version>3.0.3.RELEASE</version>
    </dependency>
    
		<dependency>
			<groupId>fr.pilato.spring</groupId>
			<artifactId>spring-elasticsearch</artifactId>
			<version>2.1.0</version>
		</dependency>

Error occured processing XML
'org.springframework.data.jpa.repository.config.JpaRepositoryConfigExtension.getRepositoryFactoryBeanClassName()Ljava/
lang/String;'. See Error Log for more details

Sounds like I did not release 5.0 o_O...

May be use spring-elasticsearch 5.0-SNAPSHOT ?

Is there any other way to implement elasticsearch 6.x with spring ?

I don't know if this can help:

You can produce your own bean here with the rest Client I think.

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