Skip to content

Conversation

@nknize
Copy link
Contributor

@nknize nknize commented Dec 16, 2016

LatLonPoint polygon query in Lucene 6 supports multipolygons and polygons with holes. This PR exposes this capability through the ES query DSL by adding multipolygon support to the GeoPolygonQueryBuilder parser such that the following can now be parsed:

"query" : {
  "geo_polygon" : {
    "track.location" :{
      "multipolygon": [ [ [
        [-70, 40],
        [-80, 30],
        [-90, 20]
      ] ] ]
    }
  }
}

To maintain backcompat the following is still supported:

"query" : {
  "geo_polygon" : {
    "track.location" :{
      "points": [ 
        [-70, 40],
        [-80, 30],
        [-90, 20]
      ] 
    }
  }
}

The GeoPolygonQueryBuilder now creates a Polygon object and passes it to LatLonPoint.newPolygonQuery.

NOTE:

  • Performs minimal polygon validation (e.g., enforcing minimum number of points, validating coordinates).
  • Dateline crossing is not supported.

TODO:

  • update docs with multipolygon support

closes #20789

@nknize nknize added :Analytics/Geo Indexing, search aggregations of geo points and shapes :Query DSL v5.2.0 WIP labels Dec 16, 2016
@nknize nknize requested a review from mikemccand December 16, 2016 18:00
Copy link
Contributor

@mikemccand mikemccand left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @nknize, I left a bunch of small comments.

It would be nice if ES would accept a standard GeoJson multipolygon: Lucene has a simple parser for this, taking String and returning Polygon[] ... I think that'd be easier for people to use than a triple-nested array of lon/lat points ... but we should do that separately.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm do we also do lon then lat elsewhere in the ES APIs? This is very confusing ... Lucene standardized on lat then lon a while back!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In strings, the first value is the latitude ("lat,lon"), but in arrays, the first value is the longitude as per geojson (http://geojson.org/) spec ([lon, lat]). @nknize please correct me if I am wrong.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you include the actual points in the exc message to aid users debugging?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, lat and lon are not used in this outer scope, only down inside the nested for loop? Can you move their declaration (the double[]) down there?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same for shellLat and shellLon?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe assert poly.size() > 0?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add some context to this exception so the user knows what part of their request was wrong?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like these tests are a single polygon? Can you also test that holes are parsed & executed correctly, and more than one polygon too?

@dakrone
Copy link
Member

dakrone commented Aug 15, 2017

@nknize is this PR still a WIP? Is there someone else that should review it?

@clintongormley clintongormley added :Search/Search Search-related issues that do not fall into other categories and removed :Query DSL labels Feb 14, 2018
@nknize nknize self-assigned this Mar 26, 2018
@islamjaidul
Copy link

I am sorry to say that I cannot use this way, it shows
[parsing_exception] [geo_polygon] query does not support [multipolygon], with { line=1 & col=162 }

Elastic search version - 6.2.4
How may I use multipolygon, could you guys please tell me

@pcsanwald
Copy link
Contributor

@polyfractal @nknize has this PR been supplanted by a different PR that provides the same functionality? if so, can you close please?

LatLonPoint polygon query in Lucene 6 supports multipolygons and polygons with holes. This commit exposes this capability within elasticsearch.
@nknize nknize force-pushed the GeoPoint_MultiPolygon branch from 8ec8e65 to 0cd36c5 Compare February 6, 2019 16:31
@polyfractal
Copy link
Contributor

Quick update on this. Nick rebased the PR onto master, looks like there are some CI failures related to backwards compatibility. In general the PR is almost done but probably needs some more testing and better/more informative exception messages.

Nick doesn't have time to push this PR over the finish line right now, but we think it's still important so I'm going to mark this as a help-me issue. Would make a good first issue for someone wanting to get involved with Geo, since most of the hard work is already done :)

@polyfractal polyfractal added the help wanted adoptme label Feb 7, 2019
@nknize nknize added the good first issue low hanging fruit label Mar 7, 2019
@nknize
Copy link
Contributor Author

nknize commented Mar 7, 2019

This is a good first issue for anyone interested in picking up some ES geo knowledge. The only thing missing is to add support for GeoJSON using lucene's Polygon.fromGeoJSON method. Should be pretty straightforward.. just pass the GeoJSON string to that method and it will create the Polygon[] for you.

@ioanlucut
Copy link

Hello!

What is the status of this PR?

@nathancday
Copy link

If no one is working on this in 2020, I'm gonna pick it up and try to get it finalized

@nknize
Copy link
Contributor Author

nknize commented Apr 18, 2020

Thank you for the offer @nathancday but there is a 99% likelihood that we will be deprecating and removing geo_polygon query in favor of the added support for geo_shape queries on geo_point field types that was added in #53774 (which supports all geometry (and multipart) types). If that's the case then this PR is no longer needed and will be closed without merge.

@rjernst rjernst added Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) Team:Search Meta label for search team labels May 4, 2020
@jimczi jimczi removed :Search/Search Search-related issues that do not fall into other categories Team:Search Meta label for search team labels Jan 15, 2021
@iverase
Copy link
Contributor

iverase commented Feb 9, 2021

I am going to close this as it does not apply any longer.

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 >enhancement good first issue low hanging fruit help wanted adoptme Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) team-discuss WIP

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Polygon query for geo_point field should pass the multi-polygon to LatLonPoint