[
https://issues.apache.org/jira/browse/USERGRID-926?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14976446#comment-14976446
]
David Johnson edited comment on USERGRID-926 at 10/27/15 5:28 PM:
------------------------------------------------------------------
Here are two possible designs for adding distance to the results of a
"geo-query" i.e. one with a "within" clause.
*1) Rely on ES to calculate distance from within-point to each entity*
*1a) If query is sorted by distance*
- Do an ES sort by distance query and specify that you want distance for each
hit.
-
https://www.elastic.co/guide/en/elasticsearch/guide/current/sorting-by-distance.html
*1b) If query is not sorted by distance*
- Use ES scripting to calculate distance within ES
-
http://stackoverflow.com/questions/9295118/return-distance-in-elasticsearch-results
-
https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-scripting.html
With either *1a* or *1b*: How do we get the distance into the response entities?
- Add flag to parsed query to indicate if query is geo-query
- Get distance from ES results, put the number into our CandidateResult object
- When we fetch each entity:
- We insert the ‘distance’ field in the entity with the value from the
CandidateResult (should be done in CandidateEntityFilter?)
Problems with scripting approach:
- Increased load on ES because it is executing a Groovy script for each geo
query
- Security issues? there was a vulnerability in the ES Groovy plugin
*2) Add Usergrid code to calculate distance from within-point to each entity*
How do we get distance into the response entities?
- When we load entities in response to a query we need to know:
- If the query is a geo-query and if so
-- The coordinates of the point specified in the within clause of the query
-- (how do we get this information into CandidateEntityFilter?)
- Based on the point and the ‘location' field of each object that we load we
can calculate distance
- And insert a ‘distance’ field into each entity object
What about the cursor problem?
i.e. when executing a query from a cursor, how do we know that the original
query was a geo-query and how will we know the “within” point? One solution is
to embed the within point into the cursor that we generate.
Problems with this approach:
- Is more complicated that relying on ES, is it really worth it
- Is our calculation going to be the same as the one ElasticSearch did for
geo-sorting?
-- If not, there may be some discrepancies
- To match ElasticSearch’s calculations we will need to add dependencies or
copy/paste code from ES
*3) Hybrid-approach*
This might be necessary if using ES scripting causes too much load or performs
slowly.
- For queries not sorted by distance, use Usergrid code to calculate distance.
- For queries sorted by distance, rely on ES.
was (Author: djohnson):
Here are two possible designs for adding distance to the results of a
"geo-query" i.e. one with a "within" clause.
*1) Rely on ES to calculate distance from within-point to each entity*
*1a) If query is sorted by distance*
- Do an ES sort by distance query and specify that you want distance for each
hit.
-
https://www.elastic.co/guide/en/elasticsearch/guide/current/sorting-by-distance.html
*1b) If query is not sorted by distance*
- Use ES scripting to calculate distance within ES
-
http://stackoverflow.com/questions/9295118/return-distance-in-elasticsearch-results
-
https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-scripting.html
With either *1a* or *1b*: How do we get the distance into the response entities?
- Add flag to parsed query to indicate if query is geo-query
- Get distance from ES results, put the number into our CandidateResult object
- When we fetch each entity:
- We insert the ‘distance’ field in the entity with the value from the
CandidateResult (should be done in CandidateEntityFilter?)
Problems with scripting approach:
- Increased load on ES because it is executing a Groovy script for each geo
query
- Security issues? there was a vulnerability in the ES Groovy plugin
*2) Add Usergrid code to calculate distance from within-point to each entity*
How do we get distance into the response entities?
- When we load entities in response to a query we need to know:
- If the query is a geo-query and if so
-- The coordinates of the point specified in the within clause of the query
-- (how do we get this information into CandidateEntityFilter?)
- Based on the point and the ‘location' field of each object that we load we
can calculate distance
- And insert a ‘distance’ field into each entity object
What about the cursor problem?
i.e. when executing a query from a cursor, how do we know that the original
query was a geo-query and how will we know the “within” point? One solution is
to embed the within point into the cursor that we generate.
Problems with this approach:
- Is more complicated that relying on ES, is it really worth it
- Is our calculation going to be the same as the one ElasticSearch did for
geo-sorting?
-- If not, there may be some discrepancies
- To match ElasticSearch’s calculations we will need to add dependencies or
copy/paste code from ES
> Include distances in geoquery responses
> ---------------------------------------
>
> Key: USERGRID-926
> URL: https://issues.apache.org/jira/browse/USERGRID-926
> Project: Usergrid
> Issue Type: Story
> Reporter: Jeffrey
> Assignee: David Johnson
> Fix For: 2.1.1
>
>
> The best place for this would be in the metadata of the results, in
> metadata.distance perhaps.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)