带有 Spring Data ElasticSearch 的 GeoPoint 给出错误:QueryParsingException[field [location] is not a geo_point field]

Neh*_*iya 2 spring elasticsearch geopoints spring-data-elasticsearch

我在春季有弹性搜索实体,如下所示:

@Document(indexName = "cities_in", type = "cities")
public class CityDocument {

@Id
private String id;

@Field(type = FieldType.String)
private String city;

@Field(type = FieldType.Object)
@GeoPointField
private GeoPoint location;
}
Run Code Online (Sandbox Code Playgroud)

但是当我使用 curl 看到映射时,我curl -s -XGET 'http://localhost:9200/cities_in/cities/_mapping?pretty=1'得到的输出为:

  {
   "cities_in" : {
   "mappings" : {
    "cities" : {
      "properties" : {
        "city" : {
          "type" : "string"
        },
        "id" : {
         "type" : "string"
      },
      "location" : {
        "properties" : {
          "geohash" : {
            "type" : "string"
          },
          "lat" : {
            "type" : "double"
          },
          "lon" : {
            "type" : "double"
          }
        }
        }
        }
     }
   }
 }
}
Run Code Online (Sandbox Code Playgroud)

当点击我查询时,我收到以下错误:

{
 "error" : {
"root_cause" : [ {
  "type" : "query_parsing_exception",
  "reason" : "No query registered for [geo_point]",
  "index" : "cities_in",
  "line" : 1,
  "col" : 33
} ],
"type" : "search_phase_execution_exception",
"reason" : "all shards failed",
"phase" : "query",
"grouped" : true,
"failed_shards" : [ {
  "shard" : 0,
  "index" : "cities_in",
  "node" : "4jGBH3m4SkqNnBwC196hTw",
  "reason" : {
    "type" : "query_parsing_exception",
    "reason" : "No query registered for [geo_point]",
    "index" : "cities_in",
    "line" : 1,
    "col" : 33
  }
} ]
  },
  "status" : 400
 }
Run Code Online (Sandbox Code Playgroud)

为什么位置类型不是geo_point?如何用spring管理geopoint?

Thi*_*aut 6

如果您使用 Spring,请确保您使用的是 spring 中的 GeoPoint

org.springframework.data.elasticsearch.core.geo.GeoPoint


Val*_*Val 5

问题是FieldType.Object字段之前@GeoPointField由 Spring Data 的MapperBuilder.

因此,您只需删除注释并像这样@Field(type = FieldType.Object)声明您的字段:location

@GeoPointField
private GeoPoint location;
Run Code Online (Sandbox Code Playgroud)