当前位置:   article > 正文

ElasticsearchRestTemplate创建索引映射Geo失败问题_elasticsearchresttemplate没有createindex方法

elasticsearchresttemplate没有createindex方法

原文地址:Spring boot Elasticsearch: Geo Point not creating correct mapping. Fails on searching - Stack Overflow

spring-data-elasticsearch 4.0以上版本

使用ElasticsearchRestTemplate的时候没有使用正确姿势映射到ES,导致geo字段类型为float。度娘个遍也没有解决问题。最后在stack overflow上解决了问题,故发出我的第一篇文章,希望能够帮到他人。
 

  1. //可以使用String,数组和GeoPoint类型。具体如何实现可以百度,这个可以找到很多
  2. @GeoPointField
  3. private GeoPoint location;
  1. //直接save()或者create()之后没有操作geo_point就会映射失败
  2. private void createIndex() {
  3. AnnotatedTypeScanner scanner = new AnnotatedTypeScanner(false, Document.class);
  4. for (Class clazz : scanner.findTypes("com.xxx.es.model")) {
  5. Document doc = AnnotationUtils.findAnnotation(clazz, Document.class);
  6. assert doc != null;
  7. IndexOperations ops = elasticsearchRestTemplate.indexOps(clazz);
  8. if (ops.exists()) ops.delete();
  9. ops.create();
  10. ops.refresh();
  11. ops.putMapping(ops.createMapping());
  12. }
  13. }

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/代码探险家/article/detail/853939
推荐阅读
相关标签
  

闽ICP备14008679号