8.15.0 Migration and RangeQuery builder

Hi all,

We are using Elasticsearch in our software. We are migrating from version 8.10.1 to 8.15.1.

We had this code in our software :

rangeQueryBuilder = new RangeQuery.Builder()
.field(fieldName)
.gte(JsonData.of(criterion.getCriteriaSimple().getMinValue()))
.lte(JsonData.of(criterion.getCriteriaSimple().getMaxValue()));

but in 8.15.0 version, this is no more field method from RangeQuery.Build.

I didn't find any help on the web.

Can anyone tell me how to migrate this code properly since 8.15.x version ?

Thank you by advance

Here's how I'm doing Range queries in 8.15:

Does this help?

Hi,

Thank you very much for your answer. Unfortunaly, in my case, i just wonder how to replace the field method ? What becomes fieldName ? (my problem is that .field(fieldName) doesn't exist anymore)

private Query.Builder resolveFilterSimple(CriteriaFilter criterion) {
        String fieldName = null;
        if (criterion.getCriteriaSimple().getField() != null) {
            fieldName = criterion.getCriteriaSimple().getField();
        }
        StringBuilder query;

        //Echappe TOUS les caratères spéciaux
        final String totallyEscapedCriterion = escapeReserved(criterion.getCriteriaSimple().getValue().toString());
        //Echappe seulement les \
        final String criterionWithEscapedSlashes = onlyEscapeSlash(criterion.getCriteriaSimple().getValue().toString());
        RangeQuery.Builder rangeQueryBuilder;
        switch (criterion.getCriteriaSimple().getOperator()) {
            case BETWEEN:
                rangeQueryBuilder = new RangeQuery.Builder()
                        .field(fieldName)
                        .gte(JsonData.of(criterion.getCriteriaSimple().getMinValue()))
                        .lte(JsonData.of(criterion.getCriteriaSimple().getMaxValue()));
                return (Query.Builder) new Query.Builder().range(rangeQueryBuilder.build());

Bonjour !

I don't see the problem TBH. You have to use number now as I shown in the previous example.

RangeQuery rangeQuery = RangeQuery.of(rq -> 
  rq.number(nrq ->
    nrq.field(fieldName)
       .from(JsonData.of(criterion.getCriteriaSimple().getMinValue()))
       .to(JsonData.of(criterion.getCriteriaSimple().getMaxValue()))));

Does this work?

Code is now ok, but problem is sometimes value is not a number, but a date a something else. How can i determine this value type

I believe the value type will depend on the field type you are running the query against. The IDE is proposing this:

If it's a number, use number.
If it's a date, use date.
If it's a String, use term.
If it's "unknown", use untyped.