带有Spring Data ElasticSearch的GeoPoint给出错误:QueryParsingException [field [location]不是geo_point字段]

时间:2016-06-18 12:44:39

标签: spring elasticsearch spring-data-elasticsearch geopoints

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

<div class="column">
  <img src="http://cdn.welingelichtekringen.nl/wp-content/uploads/2014/10/hond-584x340.jpg">
  <div class="overlay">
    <p>I'm some test text!</p>
  </div>
</div>

但是当我看到使用curl @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; } 进行映射时,我输出为:

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"
          }
        }
        }
        }
     }
   }
 }
}

为什么地理位置类型不是{ "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 } ? 如何用spring管理geopoint?

2 个答案:

答案 0 :(得分:4)

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

<强> org.springframework.data.elasticsearch.core.geo.GeoPoint

答案 1 :(得分:3)

问题是,FieldType.Object @GeoPointField字段会在@Field(type = FieldType.Object)之前被Spring数据MapperBuilder处理。

因此,您只需删除location注释,然后只需声明@GeoPointField private GeoPoint location; 字段:

header.removeClass('clearHeader').addClass("darkHeader").fadeIn(slow);