# Using Elastic Search With ElasticsearchClient

**URL:** <https://discuss.elastic.co/t/using-elastic-search-with-elasticsearchclient/368710>\
**Category:** Elasticsearch\
**Tags:** language-clients\
**Created:** [October 12, 2024, 8:16am UTC](https://discuss.elastic.co/t/using-elastic-search-with-elasticsearchclient/368710 "2024-10-12T08:16:23Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![GANESHAN\_RAMAN](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ganeshan_raman/32/131511_2.png) [@GANESHAN\_RAMAN](https://discuss.elastic.co/u/GANESHAN_RAMAN)\
**Post date:** [October 12, 2024, 8:16am UTC](https://discuss.elastic.co/t/using-elastic-search-with-elasticsearchclient/368710/1 "2024-10-12T08:16:23Z")

</div>

Hi, Iam migrating from RestHighLevelClient to ElasticsearchClient and as part of this change i need to replace NativeSearchQuery and NativeSearchQueryBuilder with NativeQuery and NativeQueryBuilder  
But iam not able to pass the boolQueryBuilder to the existing withQuery API ,  
Can you please advise the right solution for this

Below is the pseudocode  
**Before Migrating:**

```auto
BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
 boolQueryBuilder.must(new TermsQueryBuilder(fieldName+".keyword", flVal));
NativeSearchQueryBuilder searchQueryBuilder = new NativeSearchQueryBuilder();	
searchQueryBuilder.withQuery(boolQueryBuilder); 
NativeSearchQuery queryn = searchQueryBuilder.build();
elasticsearchTemplate = new ElasticsearchTemplate(elasticsearchClient);
hits = elasticsearchTemplate.search(queryn, getMappedEntityClass(), IndexCoordinates.of(getIndexName()));

```

**After Migrating:**

```auto
BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
 boolQueryBuilder.must(new TermsQueryBuilder(fieldName+".keyword", flVal));
NativeQueryBuilder searchQueryBuilder = new NativeQueryBuilder();	
searchQueryBuilder.withQuery(boolQueryBuilder); // 

```

The above last line throws compilation exception,  
Can you please suggest the alternative for this so that the above current working logic works with NativeQueryBuilder and NativeQuery

Thanks,

---

<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 12, 2024, 10:51am UTC](https://discuss.elastic.co/t/using-elastic-search-with-elasticsearchclient/368710/2 "2024-10-12T10:51:27Z")

</div>

Are you speaking about Spring Elasticsearch data classes?

---

<div class="post-metadata">

**Author:** ![GANESHAN\_RAMAN](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ganeshan_raman/32/131511_2.png) [@GANESHAN\_RAMAN](https://discuss.elastic.co/u/GANESHAN_RAMAN)\
**Post date:** [October 14, 2024, 5:16am UTC](https://discuss.elastic.co/t/using-elastic-search-with-elasticsearchclient/368710/3 "2024-10-14T05:16:40Z")

</div>

Yes iam referring to the latest version of spring-data-elasticsearch and all other latest version of Elasticsearch where NativeSearchQuery and NativeQueryBuilder are being deprecated and iam forced to use NativeQuery and NativeQueryBuilder replacing HighLevelClient with ElasticsearchClient

---

<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 14, 2024, 5:29am UTC](https://discuss.elastic.co/t/using-elastic-search-with-elasticsearchclient/368710/4 "2024-10-14T05:29:38Z")

</div>

So may be you should ask on the spring data forums?

---

<div class="post-metadata">

**Author:** ![GANESHAN\_RAMAN](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ganeshan_raman/32/131511_2.png) [@GANESHAN\_RAMAN](https://discuss.elastic.co/u/GANESHAN_RAMAN)\
**Post date:** [October 14, 2024, 6:35am UTC](https://discuss.elastic.co/t/using-elastic-search-with-elasticsearchclient/368710/5 "2024-10-14T06:35:16Z")

</div>

Okay...Thanks..
