Elastic search depreciated classes


(javaSuperMaster) #1

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


QueryBuilder.add(BoolQueryBuilder) is undefined for the type
(David Pilato) #2

Calling should clause is more appropriate IMO.


(javaSuperMaster) #3

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


(David Pilato) #4

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.


(javaSuperMaster) #5

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

(David Pilato) #6

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.


(javaSuperMaster) #7

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

(David Pilato) #8

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

Java - build query due to the many fields
(javaSuperMaster) #9
QueryBuilders.boolQuery().filter(QueryBuilders.rangeQuery("location.lon").gte(form.getMinLng()).lte(form.getMaxLng()));

Its works for me, is it right way?


(javaSuperMaster) #10

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


(David Pilato) #11

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.


(javaSuperMaster) #12

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


(David Pilato) #13

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.


(javaSuperMaster) #14

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


(David Pilato) #15

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)


(javaSuperMaster) #16

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


(David Pilato) #17

Sounds like I did not release 5.0 o_O...

May be use spring-elasticsearch 5.0-SNAPSHOT ?


(javaSuperMaster) #18

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


(David Pilato) #19

I don't know if this can help:

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


(system) #20

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