Partial string match for nested value


(Tommc3) #1

If I have a document like this

{
"owner": {
"name": "joe",
"pet": {
"name": "rover",
"type": "dog"
}
}
}

And I want to search on all dogs with a name that starts with ro how could create a nested query on multiple fields?

I think I would query for some fields using a term query and other fields as a wildcard. Or maybe use ngram?


(John D. Ament) #2

I would probably first do a filter query on owner.pet.type = dog and then perform the query against owner.pet.name using a match query. You should probably set your mapping on type to be an exact match, but make owner.pet.name support ngrams. If you explicitly want start use prefix.


(system) #3