Support nested element search with elasticsearch
At GFZ we had the question if if is possible to search only for the very own devices/platforms/etc. of a user. In general I would define "own" devices as those for which the user is a contact. So we would search in the contacts of a user to match the email address of the user currently logged in in the frontend.
This would lead us to a query like this:
http://backend/.../contacts?filter[contacts.email]=nils.brinckmann@gfz-potsdam.de
(then properly url encoded).
However, it seems that the elasticsearch data layer must also handle those cases - in this case with searching within the nested contacts.
An example query to the elastissearch for it would be:
url = 'http://smses:9200'
search_params = {"query": {"nested": {"path": "contacts", "query": {"bool": {"must": [{"match": {"contacts.email": "nils.brinckmann@gfz-potsdam.de"}}]}}}}
pprint.pprint(requests.get(url + '/device/_search', json=search_params).json())
This is different from a short name query as this (the one that we can currently build):
search_params = {"query": {"term": {"short_name": {"value": "AQG"}}}}
In general we can modify the first (nested) query to match more the later one that we build already:
search_params = {"query": {"nested": {"path": "contacts", "query": {"term": {"contacts.email": {"value": "nils.brinckmann@gfz-potsdam.de"}}}}}}
Task of this issue to extend the elastic search later to wrap the existing filters with those nested
and path
elements, so that we can filter for elements that contain the dot ("contacts.email").