简体   繁体   中英

Custom Mapping Spring Data ElasticSearch

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.

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...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM