# Mixing terms and ranges in post\_filter

**URL:** <https://discuss.elastic.co/t/mixing-terms-and-ranges-in-post-filter/66056>\
**Category:** Elasticsearch\
**Created:** [November 15, 2016, 5:53am UTC](https://discuss.elastic.co/t/mixing-terms-and-ranges-in-post-filter/66056 "2016-11-15T05:53:38Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![midget2000x](https://avatars.discourse-cdn.com/v4/letter/m/bbe5ce/32.png) [@midget2000x](https://discuss.elastic.co/u/midget2000x)\
**Post date:** [November 15, 2016, 5:53am UTC](https://discuss.elastic.co/t/mixing-terms-and-ranges-in-post-filter/66056/1 "2016-11-15T05:53:38Z")

</div>

I am trying to figure out how to apply multiple post\_filters (like when a user selects multiple facets/aggregations)

```
  "post_filter": {
    "bool": {
      "must": [
        {
          "terms": { "category": ["Jewelry Collections", "Rings"] }
        },
        {
          "terms": { "size_jewelry": ["6.5", "7"] }
        },        
        {
          "range": { "price": [{ "gte": 0, "lte": 100 },{ "gte": 100, "lte": 200 }] }
        }
      ]
    }
  }

```

That obviously doesn't work. Basically, I'm trying to this:

category="Jewelry Collections" OR "Rings"  
AND  
size\_jewelry="6.5" OR "7"  
AND  
price =0-100 OR price 100-200

Any help appreciated

---

<div class="post-metadata">

**Author:** ![midget2000x](https://avatars.discourse-cdn.com/v4/letter/m/bbe5ce/32.png) [@midget2000x](https://discuss.elastic.co/u/midget2000x)\
**Post date:** [November 15, 2016, 5:06pm UTC](https://discuss.elastic.co/t/mixing-terms-and-ranges-in-post-filter/66056/2 "2016-11-15T17:06:38Z")

</div>

I \* think\* I found the answer:

```
  "post_filter": {
    "bool": {
      "must": [
        {
          "terms": { "category": ["Celtic Jewelry Collections", "Solvar Jewelry"] }
        },
        {
          "terms": { "size_jewelry": ["6.5"] }
        },
		{
        	"bool": {
				"should" : [ 
				  { 
					"range": { "price": { "gte": 0, "lte": 200 } } 
				  },
				  { 
					"range": { "price": { "gte": 200, "lte": 400 } } 
				  }		  
				] 
			}       
         }
      ]
    }
  }
```

---

<div class="post-metadata">

**Author:** ![nik9000](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nik9000/32/44947_2.png) [@nik9000](https://discuss.elastic.co/u/nik9000)\
**Post date:** [November 15, 2016, 5:22pm UTC](https://discuss.elastic.co/t/mixing-terms-and-ranges-in-post-filter/66056/3 "2016-11-15T17:22:39Z")

</div>

```auto
  "post_filter": {
    "bool": {
      "must": [
        {
          "terms": { "category": ["Celtic Jewelry Collections", "Solvar Jewelry"] }
        },
        {
          "terms": { "size_jewelry": ["6.5"] }
        }
      ]
      "should" : [ 
        { 
	  "range": { "price": { "gte": 0, "lte": 200 } } 
	},
	{ 
	  "range": { "price": { "gte": 200, "lte": 400 } } 
	}		  
      ],
      "minimum_should_match": 1
    }
  }

```

Ought to work as well. [These](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-bool-query.html) are the docs for `bool` and [these](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-minimum-should-match.html) are the docs for `minimum_should_match`.

---

<div class="post-metadata">

**Author:** ![midget2000x](https://avatars.discourse-cdn.com/v4/letter/m/bbe5ce/32.png) [@midget2000x](https://discuss.elastic.co/u/midget2000x)\
**Post date:** [November 15, 2016, 6:04pm UTC](https://discuss.elastic.co/t/mixing-terms-and-ranges-in-post-filter/66056/4 "2016-11-15T18:04:55Z")

</div>

that does work too - thanks Nik!

---

<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:** [December 13, 2016, 6:04pm UTC](https://discuss.elastic.co/t/mixing-terms-and-ranges-in-post-filter/66056/5 "2016-12-13T18:04:58Z")

</div>

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