0

I wan to make use of elastic search shape queries which work well with spring-data-es so far. The problem is when creating the index from my java application the automatic mapping looks like this:

 "shape" : {
    "properties" : {
       "coordinates" : {
          "type" : "double"
       },
       "type" : {
          "type" : "string"
       }
    }
}

So it just Indexes all my coordinates as double array while I need this:

"shape": {
  "type": "geo_shape",
  "tree": "quadtree",
  "precision": "5m"
}

So. How to implement a custom mapping? There is a annotation called @GeoPointField which makes a GeoPoint mapping. That one looks not to complicated so implementing this by myself shouldn't be to much of a problem but I can't find the implementation for the annotation and so I'm kinda stuck. Also ok would be to use: ElasticSearchTemplate.putMapping(indexName, type, mapping) but I can't find what to put into mapping as its Type Object.

1 Answer 1

1

I've ran into the exact same issue a while ago and the problem is that Spring Data ES (as of May 11th, 2016) doesn't support geo shapes. As can be seen in DATAES-169, the issue hasn't gotten much traction yet.

For this reason, I've forked the official spring-data-elasticsearch repository and decided to implement it myself.

I've made it work for polygons and circles, but I haven't pushed my code yet. I intend to support all shapes before pushing and submitting a PR. Stay tuned...

Sign up to request clarification or add additional context in comments.

13 Comments

Indexing and retrieving is no Problem. I just cannot get the mapping to work. If I create the index myself with the correct Mapping the spatial queries all work. My only property in the class is this: private GeoJsonObject shape; The dependcy for that is de.grundid.opendatalab:geojson-jackson:1.5.1. maybe this makes your life easier.
Yes, that's exactly the point. If you use Spring Data entities and expect them to create proper geo_shape field mappings, it won't work as is. Changes are required to be made in org.springframework.data.elasticsearch.core.MappingBuilder (among others). If you use ElasticSearchTemplate.putMapping() in order to bootstrap your geo_shape mapping, you run the risk of having Spring Data trying to create a conflicting field mapping (since it doesn't know anything about geo_shape)
The putMapping would be a dirty work around. Currently I create the index via a shell script and then everything works fine. I can put Polygons, Multipolygons and Points into the index without problems via repository.save() and with GeoShapeQueryBuilder I can use them to get data. The only thing I am missing is an annotation which tells spring at creation time to use that mapping.
Yes, I know, that's the missing piece. As it stands, Spring Data ES will not create such a mapping for you... until I push my changes, that is, or you do it on your side :)
Why is it different for polygons and circles and anything else? Isn't it just a FieldType that needs to be implemented?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.