2

When I add:

fields: [ "doc['Location'].lon" ]

to my query, the longitude value is different that what is shown in the document source.

Here you can see the results of a query where I fetched the doc['Latitude'].lon and .lat, and the _source.Latitude to compare:

https://gist.github.com/d9533170f1f50fd27e87 (note - these have been passed through json_decode in PHP, but the data is the same before using json_decode.)

I first noticed this when I was using "doc['field_name'].distance(lat, lon)" to try and add the distance as a field to my query. I tried both the "script_fields" and "fields" keys and each had the same result.

UPDATE: I noticed that the "doc['Location'].lon" is returning what I thought should be the doc['Location'].lat (the lat and lon are switched.)

1 Answer 1

5

The problem was that when using GeoJSON format (or using lat/long as an array) you have to switch the order of lat/lng to lng/lat.

I am rebuilding my index, but, in order to work around this I have used this query for now:

doc['Location'].distance( lon + 180, lat ) // Temporary bandaid

Once I've rebuilt the index with the correct values I'll switch back to:

doc['field_name'].distance(lat, lon) // The correct method
Sign up to request clarification or add additional context in comments.

1 Comment

David, yeah unfortunately this is a common problem when working with Spatial data. x,y != y,x and a lot of people here in the US often relate x to latitude.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.