Say if I have stories and articles obout stars in the sky, and I also have the position of the stars. If I want to get the stories of stars in one area of the sky, one approach would be using geo query to find starts in one area, and then use term query to find stories and articles about these stars. In the above mentioned approach, the client need to send one request to Elasticsearch, wait for the response, and then send another query. My question is is it possible to do this in only one query using say scripting. Please be aware that I can't put the star position and stories in one document to simplify the situation since there is only one single position of one star, but there maybe many stories, I don't want to repeat the position in each of the story document.
Essentially, you're asking if Elasticsearch performs joins, and the answer is "no." There are a few things somewhat related though that may be interesting depending on your specifics, including why you
don't want to repeat the position in each of the story document.
One is the terms lookup query.
The third, as you mention, is to perform multiple queries.
Looking at your requirement the best way forward will be to use parent/child or nested model as mentioned by @shanec
Using the above way you will not have to repeat the star location as it will become part of parent document. Now you can use single parent/child or nested query with geo filter to meet you expected result.
The stories here are actually some kind of events and will come into the system continuously, so if I use nested fields, the inner fields will be multiple valued and new values will be added all the time, take this into consideration, is nested still a good choice?
As i understand data is getting index in real time, you will have to re-index the nested doc again with the new field changes or with the newly added event. Just keep a check on the size of single nested doc, for this you can have a cleaning process to remove not required events.
If the above does not suite your requirement then you will have to repeat the location in star. This way you will need a single query with geo filter. Also there is no problem in repeating the values in each story as ES will be able to handle it.
This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.