The problem with these queries is that they are rather long… But to do the red or black AND S and M query you just do a second should block; basically something like below.

{
"query": {
"bool": {
"filter": [
{
"bool": {
"should": [
{
"nested": {
"path": "keyword_facets",
"query": {
"bool": {
"filter": [
{ "term": { "keyword_facets.facet_name": "size" } },
{ "term": { "keyword_facets.facet_value": "S" } }
]
}
}
}
},
{
"nested": {
"path": "keyword_facets",
"query": {
"bool": {
"filter": [
{ "term": { "keyword_facets.facet_name": "size" } },
{ "term": { "keyword_facets.facet_value": "M" } }
]
}
}
}
}
]
}
},
{
"bool": {
"should": [
{
"nested": {
"path": "keyword_facets",
"query": {
"bool": {
"filter": [
{ "term": { "keyword_facets.facet_name": "color" } },
{ "term": { "keyword_facets.facet_value": "black" } }
]
}
}
}
},
{
"nested": {
"path": "keyword_facets",
"query": {
"bool": {
"filter": [
{ "term": { "keyword_facets.facet_name": "color" } },
{ "term": { "keyword_facets.facet_value": "red" } }
]
}
}
}
}
]
}
}
]
}
}
}

Written by

Broad infrastructure, development, and soft-skill background

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store