I’m attempting to migrate a solr query to OpenSearch. It has many filters, and Solr has a nice feature where you can apply an exclude to a filter so it doesn’t mess up your facet counts. An example of this would be a shoe website where you select “size” and it still shows you the counts for the rest of the shoe sizes in the same request. The syntax in solr looks like the following:
&fq={!tag=tagA}fieldA:facetASelection
&facet.field={!ex=tagB}fieldB
The issue I’m looking for an answer to is this:
Is there a way to do this fairly easily in OpenSearch?
The only solution I’ve found so far is to use global aggregation and apply every other filter to the facet/aggregation. Which is not a great solution and gets very verbose.
I’ve attached a sample request below, which is working, but will be a REAL pain to implement if that’s my only option:
GET shoes/_search?size=0
{
"query": {
"bool": {
"must": [
{
"term": {
"ShoeType": {
"value": "Addidas"
}
}
}
]
}
},
"aggs": {
"AllShoeTypes": {
"global": {},
"aggs": {
"filteredShoeTypes": {
"filter": {
"bool": {
"must": [
{
"term": {
"Size": "10"
}
},
{
"term": {
"gender": "M"
}
}
]
}
},
"aggs": {
"ShoeType": {
"terms": {
"field": "shoeType"
}
}
}
}
}
}
}
}