[ 
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 2:09 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* 

Via a Groovy script that we embed, ES can return a distance for each search hit.
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




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* 

Via a Groovy script that we embed, ES can return a distance for each search hit.
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)

Reply via email to