# Elastcisearch

**URL:** <https://discuss.elastic.co/t/elastcisearch/321319>\
**Category:** Elasticsearch\
**Tags:** language-clients\
**Created:** [December 15, 2022, 2:46pm UTC](https://discuss.elastic.co/t/elastcisearch/321319 "2022-12-15T14:46:51Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sarthak\_Agarwal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sarthak_agarwal/32/110339_2.png) [@Sarthak\_Agarwal](https://discuss.elastic.co/u/Sarthak_Agarwal)\
**Post date:** [December 15, 2022, 2:46pm UTC](https://discuss.elastic.co/t/elastcisearch/321319/1 "2022-12-15T14:46:51Z")

</div>

I am using the last Java Client API for Elasticsearch 7.17.5.  
I have a boolean query builder and I want to add conditions before checking if a must clause is already there or not. But the issue is that I can build the query builder only 1 time.  
How can I check if a clause is already there without actually calling .build method ?

Or Is it possible to add clause to **BoolQuery** object that we get after calling build.

```auto
       BoolQuery.Builder b = QueryBuilders.bool();
		
		b.filter(QueryBuilders.matchAll().build()._toQuery());
		
		if(b.build().must().isEmpty())
			b.must(QueryBuilders.matchAll().build()._toQuery());
		
		System.out.println(b.build());

```

This gives [UnsupportedOperationException]

```auto
		b.build().must().add(QueryBuilders.matchAll().build()._toQuery())

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [January 12, 2023, 2:47pm UTC](https://discuss.elastic.co/t/elastcisearch/321319/2 "2023-01-12T14:47:10Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
