# Bool filter in elastic search

**URL:** https://discuss.elastic.co/t/bool-filter-in-elastic-search/76033
**Category:** Elasticsearch
**Created:** [February 22, 2017, 12:47pm UTC](https://discuss.elastic.co/t/bool-filter-in-elastic-search/76033 "2017-02-22T12:47:31Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![prasad\_kp](https://avatars.discourse-cdn.com/v4/letter/p/dc4da7/32.png) [@prasad\_kp](https://discuss.elastic.co/u/prasad_kp)
#### Post date: [February 22, 2017, 12:47pm UTC](https://discuss.elastic.co/t/bool-filter-in-elastic-search/76033/1 "2017-02-22T12:47:31Z")

</div>

I am using the bool query but while using the terms in bool I am getting the max clause issue of 1024 to overcome this I want to change my bool query in the filter bool query

```
if ( !poNo.isEmpty() && poNo.length()>0 )
	bool.must( QueryBuilders.queryStringQuery("*"+poNo+"*").defaultField("poNo"));
if ( orderIds!=null )
bool.must(QueryBuilders.termsQuery("id", orderIds));

```

Here the ordersIds is an array ant it may contain more than 1024 orderIds , flnow I want to change this bool query to the filter bool query.

I have used the filter

FilterBuilder fl = FilterBuilders.boolFilter().must(FilterBuilders.termsFilter("id",orderIds ));

But here I can't dynamically append the must clause as **fl.** doesn't have option of must /should /must not

---

<div class="post-metadata">

### Author: ![prasad\_kp](https://avatars.discourse-cdn.com/v4/letter/p/dc4da7/32.png) [@prasad\_kp](https://discuss.elastic.co/u/prasad_kp)
#### Post date: [February 22, 2017, 2:07pm UTC](https://discuss.elastic.co/t/bool-filter-in-elastic-search/76033/2 "2017-02-22T14:07:22Z")

</div>

HI Guys  
I have solved my issue by using the filtered query

bool.must(QueryBuilders.filteredQuery(null, FilterBuilders.termsFilter("id", orderIds)));

Here by using this m not getting the max clause issue, clause does the filter also has the clause of any value as of bool 1024

---

<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: [March 22, 2017, 2:07pm UTC](https://discuss.elastic.co/t/bool-filter-in-elastic-search/76033/3 "2017-03-22T14:07:27Z")

</div>

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