# 8.15.0 Migration and RangeQuery builder

**URL:** <https://discuss.elastic.co/t/8-15-0-migration-and-rangequery-builder/366627>\
**Category:** Elasticsearch\
**Created:** [September 16, 2024, 2:45pm UTC](https://discuss.elastic.co/t/8-15-0-migration-and-rangequery-builder/366627 "2024-09-16T14:45:01Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gerald\_PONT](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gerald_pont/32/137622_2.png) [@Gerald\_PONT](https://discuss.elastic.co/u/Gerald_PONT)\
**Post date:** [September 16, 2024, 2:45pm UTC](https://discuss.elastic.co/t/8-15-0-migration-and-rangequery-builder/366627/1 "2024-09-16T14:45:01Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [September 16, 2024, 10:03pm UTC](https://discuss.elastic.co/t/8-15-0-migration-and-rangequery-builder/366627/2 "2024-09-16T22:03:09Z")

</div>

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

> <https://github.com/dadoonet/elasticsearch-java-client-demo/blob/23f563470a5df81fb07d74982787c4e0eedcdaef/src/test/java/fr/pilato/test/elasticsearch/hlclient/EsClientIT.java#L427-L440>

Does this help?

---

<div class="post-metadata">

**Author:** ![Gerald\_PONT](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gerald_pont/32/137622_2.png) [@Gerald\_PONT](https://discuss.elastic.co/u/Gerald_PONT)\
**Post date:** [September 17, 2024, 6:35am UTC](https://discuss.elastic.co/t/8-15-0-migration-and-rangequery-builder/366627/3 "2024-09-17T06:35:13Z")

</div>

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)

```auto
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());

```

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [September 17, 2024, 8:29am UTC](https://discuss.elastic.co/t/8-15-0-migration-and-rangequery-builder/366627/4 "2024-09-17T08:29:39Z")

</div>

Bonjour !

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

```auto
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?

---

<div class="post-metadata">

**Author:** ![Gerald\_PONT](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gerald_pont/32/137622_2.png) [@Gerald\_PONT](https://discuss.elastic.co/u/Gerald_PONT)\
**Post date:** [September 17, 2024, 9:47am UTC](https://discuss.elastic.co/t/8-15-0-migration-and-rangequery-builder/366627/5 "2024-09-17T09:47:27Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [September 17, 2024, 1:49pm UTC](https://discuss.elastic.co/t/8-15-0-migration-and-rangequery-builder/366627/6 "2024-09-17T13:49:40Z")

</div>

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

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/b/5/b5f5b3cd4e08c0f1bf126033695236745fbcb777.jpeg)

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`.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [October 11, 2024, 5:44pm UTC](https://discuss.elastic.co/t/8-15-0-migration-and-rangequery-builder/366627/7 "2024-10-11T17:44:44Z")

</div>

`untyped` should help:

```
RangeQuery rangeQuery = RangeQuery.of(rq -> 
            rq.untyped(nf -> nf
                    .field(fieldName)
                    . from(criterion.getCriteriaSimple().getMinValue()))
                    . to(criterion.getCriteriaSimple().getMaxValue()))
            )))).build();

```

---

<div class="post-metadata">

**Author:** ![Gerald\_PONT](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gerald_pont/32/137622_2.png) [@Gerald\_PONT](https://discuss.elastic.co/u/Gerald_PONT)\
**Post date:** [October 11, 2024, 8:14pm UTC](https://discuss.elastic.co/t/8-15-0-migration-and-rangequery-builder/366627/8 "2024-10-11T20:14:34Z")

</div>

Yes, it works perfectly with untyped.

Thank you very much for your help!
