# Using BoolQuery.Builder with NativeQuery

**URL:** <https://discuss.elastic.co/t/using-boolquery-builder-with-nativequery/358363>\
**Category:** Elasticsearch\
**Tags:** language-clients\
**Created:** [April 28, 2024, 7:37am UTC](https://discuss.elastic.co/t/using-boolquery-builder-with-nativequery/358363 "2024-04-28T07:37:43Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ajt001](https://avatars.discourse-cdn.com/v4/letter/a/dbc845/32.png) [@ajt001](https://discuss.elastic.co/u/ajt001)\
**Post date:** [April 28, 2024, 7:37am UTC](https://discuss.elastic.co/t/using-boolquery-builder-with-nativequery/358363/1 "2024-04-28T07:37:43Z")

</div>

Hi. Maybe this is basic, but I can't find the answer.  
I used to have this code:

```auto
...
BoolQueryBuilder boolQueryBuilder = processElasticRequest()

NativeSearchQuery query = new NativeSearchQueryBuilder()
          .withQuery(boolQueryBuilder)
          .withPageable(req)
          .build();

```

I've upgraded and have this:

```auto

BoolQuery.Builder boolQueryBuilder = handleElasticRequest()

NativeQuery query = NativeQuery.builder()
                    .withQuery(boolQueryBuilder.build()._toQuery())
                    .withPageable(Pageable.unpaged())
                    .build();

```

However, that does not seem correct, and the results aren't returned. What have I done wrong?

Thanks!

---

<div class="post-metadata">

**Author:** ![ltrotta](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ltrotta/32/124003_2.png) [@ltrotta](https://discuss.elastic.co/u/ltrotta)\
**Post date:** [April 29, 2024, 8:54am UTC](https://discuss.elastic.co/t/using-boolquery-builder-with-nativequery/358363/2 "2024-04-29T08:54:25Z")

</div>

Hello!  
Sorry we can't help you with this one, NativeQuery is a spring data class, so I'm not sure what their requirements are for usage and integration with the elasticsearch java client.
