使用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)
查看全部
m0_37782509
m0_37782509
2019/04/21 11:49
  • java
  • elasticsearch
  • 点赞
  • 收藏
  • 回答
    私信

1个回复