Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GIS Query not working on ES as expected #9079

Closed
andyboagra opened this issue Dec 28, 2014 · 4 comments · Fixed by #9091
Closed

GIS Query not working on ES as expected #9079

andyboagra opened this issue Dec 28, 2014 · 4 comments · Fixed by #9091
Assignees
Labels
:Analytics/Geo Indexing, search aggregations of geo points and shapes

Comments

@andyboagra
Copy link

Issue raised:
Below is my request/ response. I am puzzled why do i get a polygon returned when it does not intersect w/ envelope defined in request. What am i missing? Appreciate quick response. Thanks,
Andy

Request:

_search
{"size": 51000,"query": { "geo_shape": { "POLYS": {"shape": {"type": "envelope", "coordinates": [[-118.58, 35.32],[-118.68, 35.30]]}, "relation": "intersects"}}}}

Response:

"took" : 1172,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"failed" : 0
},
"hits" : {
"total" : 94420,
"max_score" : 1.0,
"hits" : [ {
"_index" : "XXX",
"_type" : "XXX_data",
"_id" : "1234",
"_score" : 1.0,
"_source":{"POLYS":{"type":"Polygon","coordinates":[[[-117.7656797176,35.2420721325],[-117.766565557,35.2429646794],[-117.7675000712,35.2429532681],[-117.7661768866,35.2415486409],[-117.7661640858,35.2415341862],[-117.765523769,35.2419167046],[-117.7656797176,35.2420721325]]]}, "STATE": "XX", "ID": 1234 ,"COUNTY_NAME": "YY"}]}
}, {
"_index" : "XXX",
"_type" : "XXX_data",
"_id" : "1235",
"_score" : 1.0,
....
....

_mapping?pretty'

{
"XXX" : {
"mappings" : {
"XXX_data" : {
"properties" : {
"COUNTY_NAME" : {
"type" : "string"
},
"ID" : {
"type" : "long"
},
"POLYS" : {
"type" : "geo_shape",
"tree" : "quadtree",
"tree_levels" : 26
},
"STATE" : {
"type" : "string"
}
}
}
}
}
}

Reply from Peter Johnson:
I tried to fix this but you're right, it seems to be a bug. I've attached a full bug report which you might want to add to a new github issue.

https://gist.github.com/anonymous/c250d602d1e7fe6d3655
https://gist.github.com/missinglink/6e96f06e9e6032aa6416

I also tried using 'geohash' instead of 'quadtree' with the same result.

-P
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/f1c49b57-721d-4abd-bb1d-ac54631e543a%40googlegroups.com.

@andyboagra
Copy link
Author

The test case i have is a basic unit test case for the feature. To me it is not a corner case (may be i am mistaken). If anyone can recommend a workaround, that would help as well.

@missinglink
Copy link
Contributor

Hey @andyboagra I figured out what was going on, I actually had this issue a while back and it took some time for me to remember what the deal was.

The co-ordinates you specified for the envelope are in the wrong order, the docs say that the format "consists of coordinates for upper left and lower right points of the shape to represent a bounding rectangle".

You should be using:

"coordinates": [
  ["-118.68", "35.32"],
  ["-118.58", "35.30"]
]

... instead of

"coordinates": [
  ["-118.58", "35.32"],
  ["-118.68", "35.30"]
]

It's actually quite annoying that you don't get a warning, as changing the lat values throws InvalidShapeException inside spatial4j yet changing the lon doesn't.

I'm assuming that the envelope you created wraps all the way around the world and excludes only the small section you were trying to target, although I didn't spend the time investigating more.

Hope that helps, I'll try to write up a minimal testcase regarding the bbox validation and open a separate ticket.

If you can confirm this works this issue can probably be closed.

@clintongormley clintongormley added the :Analytics/Geo Indexing, search aggregations of geo points and shapes label Dec 29, 2014
@andyboagra
Copy link
Author

Works as expected based on Peter's suggestion.

nknize added a commit to nknize/elasticsearch that referenced this issue Dec 30, 2014
ShapeBuilder expected coordinates for Envelope types in strict Top-Left, Bottom-Right order. Given that GeoJSON does not enforce coordinate order (as seen in elastic#8672) clients could specify envelope bounds in any order and be compliant with the GeoJSON spec but not the ES ShapeBuilder logic. This change loosens the ShapeBuilder requirements on envelope coordinate order, reordering where necessary.

closes elastic#2544
closes elastic#9067
closes elastic#9079
closes elastic#9080
nknize added a commit that referenced this issue Dec 30, 2014
ShapeBuilder expected coordinates for Envelope types in strict Top-Left, Bottom-Right order. Given that GeoJSON does not enforce coordinate order (as seen in #8672) clients could specify envelope bounds in any order and be compliant with the GeoJSON spec but not the ES ShapeBuilder logic. This change loosens the ShapeBuilder requirements on envelope coordinate order, reordering where necessary.

closes #2544
closes #9067
closes #9079
closes #9080
nknize added a commit that referenced this issue Dec 30, 2014
ShapeBuilder expected coordinates for Envelope types in strict Top-Left, Bottom-Right order. Given that GeoJSON does not enforce coordinate order (as seen in #8672) clients could specify envelope bounds in any order and be compliant with the GeoJSON spec but not the ES ShapeBuilder logic. This change loosens the ShapeBuilder requirements on envelope coordinate order, reordering where necessary.

closes #2544
closes #9067
closes #9079
closes #9080
@nknize
Copy link
Contributor

nknize commented Dec 30, 2014

@andyboagra Great to hear you got it working! A patch has been pushed to self correct coordinate order on envelope shape type. Many thanks to both you and @missinglink for identifying this issue. Cheers!

mute pushed a commit to mute/elasticsearch that referenced this issue Jul 29, 2015
ShapeBuilder expected coordinates for Envelope types in strict Top-Left, Bottom-Right order. Given that GeoJSON does not enforce coordinate order (as seen in elastic#8672) clients could specify envelope bounds in any order and be compliant with the GeoJSON spec but not the ES ShapeBuilder logic. This change loosens the ShapeBuilder requirements on envelope coordinate order, reordering where necessary.

closes elastic#2544
closes elastic#9067
closes elastic#9079
closes elastic#9080
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Analytics/Geo Indexing, search aggregations of geo points and shapes
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants