I\'m looking for a way to do exact array matches in elastic search. Let\'s say these are my documents:
{\"id\": 1, \"categories\" : [\"c\", \"d\
I found a solution for our usage case that appears to work. It relies on two filters and the knowledge of how many categories we want to match against. We make use of a terms filter and a script filter to check the size of the array. In this example, marketBasketList is similar to your categories entry.
{
"query": {
"bool": {
"must": [
{
"match": {
"siteId": 4
}
},
{
"match": {
"marketBasketList": {
"query": [
10,
11
],
"operator": "and"
}
}
}
]
},
"boost": 1,
"filter": {
"and": {
"filters": [
{
"script": {
"script": "doc['marketBasketList'].values.length == 2"
}
},
{
"terms": {
"marketBasketList": [
10,
11
],
"execution": "and"
}
}
]
}
}
}
}