Hi, I'm trying to get docs that contain the exact specified terms. Terms query doesn't match because it also returns docs with additional terms.
Create index :
PUT my-index
{
"mappings": {
"properties": {
"my-field" : {
"type" : "keyword"
}
}
}
}
Index a document:
PUT my-index/_doc/1
{
"my-field": ["A", "B"]
}
Index another document:
PUT my-index/_doc/2
{
"my-field": ["A", "B", "C"]
}
Use the terms query to find documents that containing A and B:
GET my-index/_search?pretty
{
"query":
{
"terms": {
"my-field": ["A", "B"]
}
}
}
Results :
{
"took" : 178,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 2,
"relation" : "eq"
},
"max_score" : 1.0,
"hits" : [
{
"_index" : "my-index",
"_type" : "_doc",
"_id" : "1",
"_score" : 1.0,
"_source" : {
"my-field" : [
"A",
"B"
]
}
},
{
"_index" : "my-index",
"_type" : "_doc",
"_id" : "2",
"_score" : 1.0,
"_source" : {
"my-field" : [
"A",
"B",
"C"
]
}
}
]
}
}
Elastic returns document 2 and document 1 because both contain A and B in my-field. It is the expected behavior, but I'd like to return only documents containing strictly A and B (if a doc contains A and B and C then it should be excluded from the results).
I've read the documentation (filters, aggregations, ...) but I can't find a way.
Thanks in advance for your help