I have documents that have a list of labels:
{
"fields": {
"label": [
"foo",
"bar",
"baz"
],
"name": [
"Document One"
],
"description" : "A fine first document",
"id" : 1
}
},
{
"fields": {
"label": [
"foo",
"dog"
],
"name": [
"Document Two"
],
"description" : "A fine second document",
"id" : 2
}
}
I have a list of terms:
[ "foo", "bar", "qux", "zip", "baz"]
I want a query that will return documents that have labels in the list of terms - but no other terms.
So given the list above, the query would return Document One, but not Document Two (because it has the term dog that is not in the list of terms.
I've tried doing a query using a not terms filter, like this:
POST /documents/_search?size=1000
{
"fields": [
"id",
"name",
"label"
],
"filter": {
"not": {
"filter" : {
"bool" : {
"must_not": {
"terms": {
"label": [
"foo",
"bar",
"qux",
"zip",
"baz"
]
}
}
}
}
}
}
}
But that didn't work.
How can I create a query that, given a list of terms, will match documents that only contain terms in the list, and no other terms? In other words, all documents should contain a list of labels that are a subset of the list of supplied terms.