Consider a very simple model where we have locations, and each place can have zero or more events. The location will have properties such as name, description, and location data (lon / lat). An event must be attached to one place (its parent element) and must have a name and description.
{ "location" : { "properties": { "name": { "type": "string", "boost": 2.0, "analyzer": "snowball" }, "description": { "type": "string", "analyzer": "snowball" }, "geo": { "type": "geo_point" }, "exhibits": { "type": "nested", "properties": { "name": { "type": "string", "boost": 2.0, "analyzer": "snowball" }, "description": { "type": "string", "analyzer": "snowball" } } } } } }
What I want to do is to request child documents (events) that perform a full-text search by their names and descriptions. I would like to get relevant events back and be able to also get their parent location name. I would also like to narrow down the results by location coordinates. I do not want to receive any events that do not match the request. Is this possible in Elastic Search? What types of queries should I use?
I tried to put events as an array property in the location (see above) and using the nested query, but it does not return the results I want (I think it returns the whole location, including all events, even those that do not match mine request). I tried putting events in a separate index (matching?) Providing the _parent property and then doing a top_children query in places, but I am not getting any results.
{ "exhibit": { "_parent": { "type": "locations" }, "properties": { "name": { "type": "string", "boost": 2.0, "analyzer": "snowball" }, "description": { "type": "string", "analyzer": "snowball" } } } }
Can anyone shed some light? I donโt know where to start ...
elasticsearch
Pawel krakowiak
source share