Mixing terms and ranges in post_filter


#1

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


#2

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  } } 
				  }		  
				] 
			}       
         }
      ]
    }
  }

(Nik Everett) #3
  "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 are the docs for bool and these are the docs for minimum_should_match.


#4

that does work too - thanks Nik!


(system) #5

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