# How to copy boolQueryBuilder?

**URL:** <https://discuss.elastic.co/t/how-to-copy-boolquerybuilder/191271>\
**Category:** Elasticsearch\
**Created:** [July 18, 2019, 7:57pm UTC](https://discuss.elastic.co/t/how-to-copy-boolquerybuilder/191271 "2019-07-18T19:57:12Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![pvsmpraveen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pvsmpraveen/32/50400_2.png) [@pvsmpraveen](https://discuss.elastic.co/u/pvsmpraveen)\
**Post date:** [July 18, 2019, 7:57pm UTC](https://discuss.elastic.co/t/how-to-copy-boolquerybuilder/191271/1 "2019-07-18T19:57:12Z")

</div>

I have a usecase where I have a boolQueryBuilder which is common across different type of queries.

Now for different queries, I need to add a different must() to the boolQueryBuilder.

basically, say i have a common boolQueryBuilder which is built to filter books with certain tags. Now among these when i get a request to select specific type1/type2.  
I have to do,  
boolQueryBuilder.must(type1) for request1  
boolQueryBuilder.must(type2) for request2 (which shouldnt have type1)

I tried deepcopy , serialize and deserialize but they are very very slow takes ~3seconds

I need type1 along with the tags in request1, and type2 along with tags in request2.

What is the better way to make use of the common builder i have instead of re-building the common queries again and again?

---

<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:** [August 15, 2019, 7:57pm UTC](https://discuss.elastic.co/t/how-to-copy-boolquerybuilder/191271/2 "2019-08-15T19:57:24Z")

</div>

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