1

I'm experiencing some very strange behavior from Elasticsearch. I am using geo_bounding_box to search the area visible in Google Maps. I have data in New York and San Fransisco. New York behaves as expected. San Fransisco does not, which is confusing me.

When searching in San Fransisco, I have to invert the longitude for east and west in order for data to be returned.

Searching in New York works just fine

New York (Normal)

// New York
"geo_bounding_box" : {
    "location.coordinates": {
        "top_right": [40.75595545633613,-73.85303608398436],
        "bottom_left": [40.64820096366504,-74.03156391601561]
    }
}

San Fran (Normal)

// San Fransisco (Normal)
"geo_bounding_box": {
    "location.coordinates": {
        "top_right": [37.79734048601642,-122.39438402099609],
        "bottom_left": [37.7692568462339,-122.4390159790039]
    }
}

San Fran (Inverted)

// San Fransisco (Swapped)
"geo_bounding_box": {
    "location.coordinates": {
        "top_right": [37.79734048601642,-122.4390159790039],
        "bottom_left": [37.7692568462339,-122.39438402099609]
    }
}

As you can see, swapping the longitude values returns results but it does not make any sense because we are searching outside of the bounding box.

I am using elasticsearch Version: 1.4.4

[EDIT] This is an example of geo data stored in the San Fransisco area

"location": {
    "coordinates": [37.7876027, -122.4215609],
    "type": "Point"
 }
1

It looks like you are putting coordinates into the array in the wrong order. The order is [lon, lat], not [lat, lon].

So you probably wanted:

"geo_bounding_box": {
    "location.coordinates": {
        "top_right": [-122.39438402099609, 37.79734048601642],
        "bottom_left": [-122.4390159790039, 37.7692568462339]
    }
}

Also, it would be more conventional to do top_left and bottom_right...

Edit based your update to the question: The input coordinates also need to be in [lon, lat] order for an array. As noted in the guide, this is a common problem.

  • So I switch the lon and lat values and that does not work. Does the data need to be indexed this way? I added an example of how data is stored in the original post. – digitaldavenyc Dec 4 '15 at 16:26
  • This also does not explain why data loads normally in NY and inverted in SF – digitaldavenyc Dec 4 '15 at 16:33
  • Updated. As to why NY and not SF, its hard to say without seeing all the data. Perhaps the compound errors sometimes cancel, sometimes not. – BradHards Dec 4 '15 at 22:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.