The example is extracted from Elasticsearch reference: https://www.elastic.co/guide/en/elasticsearch/reference/5.3/nested.html
My index is similar to this. The only difference is user.first and user.last are keyword type so I can use filter on them.
PUT my_index
{
"mappings": {
"my_type": {
"properties": {
"user": {
"type": "nested"
}
}
}
}
}
PUT my_index/my_type/1
{
"group" : "fans",
"user" : [
{
"first" : "John",
"last" : "Smith"
},
{
"first" : "Alice",
"last" : "White"
}
]
}
What is the query I should use to get documents that match the above array (exactly two items, one item is John Smith, one item is Alice White) in two situations:
- Order doesn't matter
- Order matters
After searching, the best way to achieve Order doesn't matter is: indexing a Count field.
See: Elasticsearch Equal Exactly
The reason is: