I come from a related database background and something like this would be so simple there, but I can't figure this out. I've been trying to learn Elasticsearch for a week or so and I'm trying to figure out what I think is a nested query. Here's some sample data:
PUT /myindex/pets/_mapping
{
"pets": {
"properties": {
"name": {
"type": "string"
},
"pet": {
"type": "nested",
"properties": {
"name": {"type": "string"}
}
}
}
}
}
POST /myindex/pets/
{"pet": {"name": "rosco"}, "name": "sam smith"}
POST /myindex/pets/
{"pet": {"name": "patches"}, "name": "sam smith"}
POST /myindex/pets
{"pet": {"name": "rosco"}, "name": "jack mitchell"}
What would the query look like that only returns documents matching:
- owner name is "sam smith"
- pet name is "rosco"
I've tried a mixmatch of bool, match, nested, filtered/filter type queries, but I just keep getting errors. Stuff like this stands out in the errors:
nested: ElasticsearchParseException[Expected field name but got START_OBJECT \"nested\"];
Here was the query:
GET /myindex/pets/_search
{
"query": {
"match": {
"name": "sam smith"
},
"nested": {
"path": "pet",
"query": {
"match": {
"pet.name": "rosco"
}
}
}
}
}
I'm beginning to think that I just can't target something this specific due to the relevant nature of Elasticsearch.
Any ideas?