Can a Filter be Applied with "OR" Logic?

I'm trying to mimic the functionality of another search engine. The functionality I want is that when a user selects a filter it first limits a search, as expected. However, I want to still return all possible aggregation values for the entire data set (not just the new filtered data set). When the user selects a subsequent filter it expands the number of results.

An Example of this functionality are Amazon's refinements:

When I select "Acer" it limits the results to only Acer. When I then select "HP" it expands the results to include Acer or HP.

I'm trying to utilize filters vs query because I don't want to affect relevance. Any ideas?

1 Like

Hi John. Check out post filters

Thanks. Post_filer might be what I want, but I can't seem to find any doc on using multiple post_filter conditions or passing an array to post_filter. Can you apply multiple post_filters?

I am hoping for something like:

"post_filter": [
    "term":{"color":"red"},
    "term":{"color":"blue"}
]

bool queries are the way to combine multiple query clauses using Boolean logic. An array of should clauses would be the way to OR clauses.

If you only have term clauses for the same field a shorter way of doing this is to just use a terms query.

Thanks again. I ended up with something like:

{
  "post_filter":{
      "bool":{
          "should":{
              {"term":{"color":"red"}},
              {"term":{"color":"blue"}}
          }
      }
  }
}

This has the effect I wanted for the color filter. I think I may need a mix of post_fitter and filter when combining multiple filters like "color" and "size".

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