I'm looking to make a filter for ecommerce product filtering. Each request toES will have at least a must filter for the category match, and then optional filtering for attributes. Let's say Colour and Size. But, colour and size must both match one of the selected values. If the selected colours are blue and red, those are an OR, but if sizes M and L is selected, the results should return products that are either (blue OR red), AND size (M OR L). My filter as it is:
"query":{
"filtered":{
"filter":{
"bool":{
"must":[
{
"term":{
"categories":4838
}
},
{
"bool":{
"should":[
{
"bool":{
"must":[
{
"bool":{
"should":[
{
"term":{
"Colour":"White"
}
},
{
"term":{
"Colour":"Black"
}
},
{
"term":{
"Colour":"Blue"
}
}
]
}
}
]
}
},
{
"bool":{
"must":[
{
"bool":{
"should":[
{
"term":{
"Size":"M"
}
},
{
"term":{
"Size":"L"
}
}
]
}
}
]
}
}
]
}
}
]
}
}
}
}
This filter returns shoulds for all of them. I get all products where the colour is white, black or blue, or where the size is M or L.
Summing it up how it should be:
in a single attribute it's all ORs and it expands the search, but when another attribute is selected, it becomes an AND between those attributes, but still ORs within them.