# Operators on terms

**URL:** <https://discuss.elastic.co/t/operators-on-terms/35481>\
**Category:** Elasticsearch\
**Created:** [November 24, 2015, 7:41pm UTC](https://discuss.elastic.co/t/operators-on-terms/35481 "2015-11-24T19:41:22Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Juan\_Diego\_Calle](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/juan_diego_calle/32/6037_2.png) [@Juan\_Diego\_Calle](https://discuss.elastic.co/u/Juan_Diego_Calle)\
**Post date:** [November 24, 2015, 7:41pm UTC](https://discuss.elastic.co/t/operators-on-terms/35481/1 "2015-11-24T19:41:22Z")

</div>

I have an index with a type called vehicle, I am trying to create a bool query, so if the car built\_year is 2001 OR 2003 and if the car has extras like radio AND air conditioner.  
This is how I started  
{  
"query":{  
"bool":{  
"filter":  
[  
{  
"terms":{  
"built\_year": [2001,2003]  
},  
"terms":{  
"built\_year": [2001,2003]  
},  
{  
"match": {  
"attributes.extras.id": 5  
}  
},  
{  
"match": {  
"attributes.extras.id": 4  
}  
}  
]  
}  
}

It works as intended, but I was wondering if there is a better way of doing this, specially if I wanna use OR between filters instead of AND, or the right ways is to use nested queries?  
The basic idea is to do this programatically, so if I recieve an object filter and it comes with a property operator that has AND or OR values.

---

<div class="post-metadata">

**Author:** ![cbuescher](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cbuescher/32/60402_2.png) [@cbuescher](https://discuss.elastic.co/u/cbuescher)\
**Post date:** [November 25, 2015, 11:35am UTC](https://discuss.elastic.co/t/operators-on-terms/35481/2 "2015-11-25T11:35:14Z")

</div>

Hi,

looks okay, only as far as I see you don't need to duplicate the `terms` query (might be a typo?). Unfortunately there is no `operator` parameter for the terms query, so if you want to be more flexible in combining them, you need individual term queries and combine them with other `bool` queries. This can all be done inside a parent bool query filter clause.

---

<div class="post-metadata">

**Author:** ![Juan\_Diego\_Calle](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/juan_diego_calle/32/6037_2.png) [@Juan\_Diego\_Calle](https://discuss.elastic.co/u/Juan_Diego_Calle)\
**Post date:** [November 25, 2015, 3:01pm UTC](https://discuss.elastic.co/t/operators-on-terms/35481/3 "2015-11-25T15:01:50Z")

</div>

thanks a lot, yes this was a typo

---

<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:** [July 5, 2017, 11:35pm UTC](https://discuss.elastic.co/t/operators-on-terms/35481/4 "2017-07-05T23:35:52Z")

</div>


