Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I use Elasticsearch's geo_point and geo_shape types at the same time?

Here is our document:

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

We'd like to do a geo_shape search with a _geo_distance sort, both against the same geometry field. The former requiresgeo_shape types while the latter requires geo_point.

These two indexes succeed individually, but not together:

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

and

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

So far we've tried these and failed:

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

also

"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 create this index properly?

like image 950
Matt Janssen Avatar asked Apr 24 '15 19:04

Matt Janssen


1 Answers

If scripting is enabled then you could achieve it via specifying transforms in mapping

would look something on these lines :

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"
      }
   }
}
like image 191
keety Avatar answered Oct 02 '22 15:10

keety