m0_37782509 2019-04-21 11:49 采纳率: 0%
浏览 1993

使用elasticsearchTemplate检索报错Field [location] is not of type [geo_shape] but of type [geo_point]

实体:

@Document(indexName = "elastic_search_project",type = "person",shards = 1,replicas = 0, refreshInterval = "-1")
@Getter
@Setter
public class GeoEntity {
    @Id
    private String id;
    private String name;
    private String content;
    @GeoPointField
    private GeoPoint location;

    public GeoEntity() {
    }

}

使用Geo_PONIT多边形检索可以成功(因为实体中有GEO_POINT映射);但现在要使用圆形检索,需要使用GEO_SHAPE,实体中应该怎么映射?

@RequestMapping("/searchByShape")
    public Page<GeoEntity> searchByShape(
            double lat, double lon, double distance, Pageable pageable) {

        //构造查询条件
        NativeSearchQueryBuilder nativeSearchQueryBuilder =
                null;
        try {
            nativeSearchQueryBuilder = new NativeSearchQueryBuilder()
                    .withFilter(QueryBuilders.geoShapeQuery("location",
                            ShapeBuilders.newCircleBuilder().radius(distance, DistanceUnit.KILOMETERS).center(lon,lat)))
                    .withPageable(pageable);
        } catch (IOException e) {
            e.printStackTrace();
        }

        Page<GeoEntity> page =
                elasticsearchTemplate.queryForPage(
                        nativeSearchQueryBuilder.build(), GeoEntity.class);
        return page;
    }

错误信息


org.elasticsearch.index.query.QueryShardException: Field [location] is not of type [geo_shape] but of type [geo_point]
    at org.elasticsearch.index.query.GeoShapeQueryBuilder.doToQuery(GeoShapeQueryBuilder.java:381)
    at org.elasticsearch.index.query.AbstractQueryBuilder.toQuery(AbstractQueryBuilder.java:104)
    at org.elasticsearch.index.query.QueryShardContext.lambda$toQuery$2(QueryShardContext.java:305)
    at org.elasticsearch.index.query.QueryShardContext$$Lambda$3084/1953286000.apply(Unknown Source)
    at org.elasticsearch.index.query.QueryShardContext.toQuery(QueryShardContext.java:317)
    at org.elasticsearch.index.query.QueryShardContext.toQuery(QueryShardContext.java:304)
    at org.elasticsearch.search.SearchService.parseSource(SearchService.java:769)
    at org.elasticsearch.search.SearchService.createContext(SearchService.java:616)
    at org.elasticsearch.search.SearchService.createAndPutContext(SearchService.java:592)
    at org.elasticsearch.search.SearchService.executeDfsPhase(SearchService.java:304)
    at org.elasticsearch.search.SearchService.access$000(SearchService.java:121)
    at org.elasticsearch.search.SearchService$1.onResponse(SearchService.java:290)
    at org.elasticsearch.search.SearchService$1.onResponse(SearchService.java:286)
    at org.elasticsearch.search.SearchService$4.doRun(SearchService.java:1082)
    at org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingAbstractRunnable.doRun(ThreadContext.java:723)
    at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:37)
    at org.elasticsearch.common.util.concurrent.TimedRunnable.doRun(TimedRunnable.java:41)
    at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:37)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
  • 写回答

1条回答 默认 最新

  • s3578505 2019-04-21 17:22
    关注

    映设是有Geo_shape映设的,可以是polygon,circle应该也可以,具体看业务要求吧

    评论

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。