elastic icon indicating copy to clipboard operation
elastic copied to clipboard

Implement GeoShape query

Open guilherme-santos opened this issue 6 years ago • 6 comments

guilherme-santos avatar Nov 01 '18 16:11 guilherme-santos

Thank you very much for working on this!

When I add new queries, I typically use the Java source as a basis. It often has more fields than documented at the official manual. E.g. GeoShapeQueryBuilder.java has these fields, serializes in this way. Can you look into that and complete the query?

olivere avatar Nov 02 '18 06:11 olivere

Sure, I'll do it soon!

guilherme-santos avatar Nov 02 '18 13:11 guilherme-santos

I was toying around a bit with this, but I'm still not happy with the outcome. I'm experimenting a bit with different ShapeBuilders (as they call it in the Java source) that are used to create the inner shape object and its coordinates. Also, I'm trying to use the naming from the Java source, so indexedShapeIndex and indexedShapeType instead of index and typ etc. So I'll delay this a bit and hope to include it in the 6.2.15 release.

olivere avatar Dec 01 '18 11:12 olivere

What is the status of this PR? I really need GeoShape support :/

timonmasberg avatar Feb 01 '22 11:02 timonmasberg

@timonmasberg Creating all the different builders is a lot of work. It has been mentioned in several issues how one can do that. I'm struggling with time to do it for a while now.

The workaround is to build the query yourself. You can e.g. always use RawStringQuery like so:

q := elastic.NewRawStringQuery(`{
	"geo_shape": {
	  "location": {
	    "shape": {
	      "type": "envelope",
	      "coordinates": [ [ 13.0, 53.0 ], [ 14.0, 52.0 ] ]
	    },
	    "relation": "within"
	  }
	}`)
res, err := client.Search().
	Index("YOUR_INDEX_NAME").
	Query(q).
	Do(ctx)
...

... or build your own Query implementation.

olivere avatar Feb 01 '22 12:02 olivere

Okay, thank you!

timonmasberg avatar Feb 01 '22 13:02 timonmasberg