# Apply filter for each match clause

**URL:** https://discuss.elastic.co/t/apply-filter-for-each-match-clause/79677
**Category:** Elasticsearch
**Created:** [March 23, 2017, 3:35am UTC](https://discuss.elastic.co/t/apply-filter-for-each-match-clause/79677 "2017-03-23T03:35:37Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![thiru](https://avatars.discourse-cdn.com/v4/letter/t/b9e5f3/32.png) [@thiru](https://discuss.elastic.co/u/thiru)
#### Post date: [March 23, 2017, 3:35am UTC](https://discuss.elastic.co/t/apply-filter-for-each-match-clause/79677/1 "2017-03-23T03:35:37Z")

</div>

Hi ,  
I am using Elastic search 5.1 and I have built two indexes say brand and products index . I do a search on the brand index using these fields  
1.Brand  
2.Brand extension  
3. Local brand .  
I take top 10 results from the brand query and used as the filter for the products index search  
For each brand result I am sending a query to products index Hence I am doing 10 searches on the products index and getting top 10 for every request . which returns 100 documents in total

How to combine all the 10 search query into a single search query ?

Say I have these two results from brand query as

Result 1

1. BRAND =PEPSI
2. LOCALBRAND =PEPSI
3. BRANDEXT=DIET PEPSI  
Result 2
4. BRAND =PEPSI123
5. LOCALBRAND =PEPSI COMPANY
6. BRANDEXT=DIET PEPSI234

How do I modify this below filter query ? i.e for the same match clause I have to apply result 1 combination and result2 combination as the filters

{  
"query": {  
"bool": {  
"should": {  
"match": {  
"ITEMDESCRIPTION": "COCA COLA 1 liter BOTEL"  
}  
},  
"filter": [  
{  
"term": {  
"BRANDEXT": "DIET COKE "  
}  
},  
{  
"term": {  
"LOCALBRAND": "COKE"  
}  
},  
{  
"term": {  
"BRAND": "COCA COLA"  
}  
}  
]  
}  
}  
}

---

<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: [April 20, 2017, 3:35am UTC](https://discuss.elastic.co/t/apply-filter-for-each-match-clause/79677/2 "2017-04-20T03:35:40Z")

</div>

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