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

使用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 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突