Suppose I have an index which looks like this:
# dummy index
PUT nested
{
"mappings": {
"properties": {
"address": {
"type": "nested",
"properties": {
"city": {
"type": "text"
},
"street": {
"type": "text"
}
}
}
}
}
}
and some documents in there
# dummy data
POST _bulk
{"index": {"_index": "nested", "_id": "1"}}
{"address":[{"city": "Berlin", "street": "Goethestrasse"}]}
{"index": {"_index": "nested", "_id": "2"}}
{"address":[{"city": "Berlin", "street": "Schillerallee"}]}
{"index": {"_index": "nested", "_id": "3"}}
{"address":[{"city": "Frankfurt", "street": "Goethestrasse"}]}
{"index": {"_index": "nested", "_id": "4"}}
{"address":[{"city": "Frankfurt", "street": "Schillerallee"}]}
{"index": {"_index": "nested", "_id": "5"}}
{"address":[{"city": "Berlin", "street": "Goethestrasse"}, {"city": "Frankfurt", "street": "Goethestrasse"}]}
{"index": {"_index": "nested", "_id": "6"}}
{"address":[{"city": "Berlin", "street": "Goethestrasse"}, {"city": "Frankfurt", "street": "Schillerallee"}]}
{"index": {"_index": "nested", "_id": "7"}}
{"address":[{"city": "Berlin", "street": "Schillerallee"}, {"city": "Frankfurt", "street": "Goethestrasse"}]}
{"index": {"_index": "nested", "_id": "8"}}
{"address":[{"city": "Berlin", "street": "Schillerallee"}, {"city": "Frankfurt", "street": "Schillerallee"}]}
How can I use a nested query on this index to find all documents with one or more addresses from an array of addresses? So if I'm inputting
{"address":[{"city": "Berlin", "street": "Goethestrasse"}, {"city": "Frankfurt", "street": "Schillerallee"}]}
I'm looking for docs with addresses that match either or both of the input addresses: 1, 4 and 6 (if scoring is possible, obviously 6 would be ranked higher). One approach would be to use a query builder, but if a solution with mustache templates is possible, we'd prefer that.
Edit: As it seems this is very similar to Matching by array elements