1

I am upgrading the elasticsearch version from 8.14.3 to 8.15.3 and there are some issues with this query-

return new RangeQuery.Builder() .field(fieldName) .gte(JsonData.of(dateToday)) .build() ._toQuery;

Here, .field seems to be deprecated. Is there any other way to rewrite the query in the new version?

4 Answers 4

0

You need to use as defined below as it is changed in latest version:

new DateRangeQuery.Builder().field("fieldName").gte("dateToday").build()._toRangeQuery();

You can check more into Elastic JavaDoc.

Sign up to request clarification or add additional context in comments.

Comments

0

you have to try the RangeQueryBuilders.

import co.elastic.clients.elasticsearch._types.query_dsl.RangeQueryBuilders;

RangeQueryBuilders.term(term -> term.field("fieldName").gte(dateToday))._toQuery();

Comments

0

Since there is a change in the RangeQuery class since version 8.15, you need to use the term method that implies DateRangeQuery, a new class that has the .field that you are looking:

new RangeQuery.Builder().date(_0 -> _0
            .field("fieldName")
            .gte("value")
        ).build()._toQuery();

Comments

0

I updated my Spring Data Elasticsearch Project main Spring boot version 3.3.3 to 3.5.7 after that my Queries weren't working. I found out how to make it work. u can use it with minimal code change solution:

Your Example :

  • Error Code:

new RangeQuery.Builder().field(fieldName).gte(JsonData.of(dateToday)).build()

  • How To Fix:

new RangeQuery.Builder().untyped(v -> v.field(fieldName).gte(JsonData.of(dateToday)).build()

My Example :

  • Error Code:

Query.of(q -> q.range(r -> r.field(fieldName).gt(asJsonData(values.get(0)))));

  • How To Fix:

Query.of(q -> q.range(r -> r.untyped(rn -> rn.field(fieldName).gt(asJsonData(values.get(0))))));

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.