How can I use Elicsearch and geo_shape geoinformation types at the same time?

Here is our document :

{ "geometry" : { "type" : "Point", "coordinates" : [ -87.662682, 41.843014 ] } } 

We would like to do a geo_shape search using the _geo_distance , as in the same geometry field. The former requires geo_shape types, while the latter requires geo_point .

These two indexes are executed individually, but not together:

 "geometry": { "type": "geo_shape" } 

and

 "geometry": { "properties": { "coordinates": { "type": "geo_point" } } }, 

So far we have tried these and failed :

 "geometry": { "type": "geo_shape" }, "geometry.coordinates": { "type": "geo_point" }, 

and

 "geometry": { "copy_to": "geometryShape", "type": "geo_shape" }, "geometryShape": { "properties": { "coordinates": { "type": "geo_point" } } } 

also

 "geometry": { "copy_to": "geometryShape", "properties": { "coordinates": { "type": "geo_point" } } }, "geometryShape": { "type": "geo_shape" } 

Any ideas on how to properly create this index?

+6
source share
2 answers

If the script is included, you can achieve this by specifying transforms when matching

will look something like this:

 put test/test_type/_mapping { "transform": { "script": "if (ctx._source['geometry']['coordinates']) ctx._source['test'] = ctx._source['geometry']['coordinates']", "lang": "groovy" }, "properties": { "geometry": { "type": "geo_shape" }, "coordinates": { "type": "geo_point" } } } 
+3
source

I would go with function_score_query and your original mapping only to geo_shape. Elasticsearch documents indicate that distance counting is usually better than distance sorting.

In another note, did you check using geo_bounding_box with geo_point? I'm not sure if you are using the geo_shape type, but you can replicate it using the bounding box. See an example here .

0
source

Source: https://habr.com/ru/post/985907/


All Articles