【发布时间】:2020-12-09 14:13:33
【问题描述】:
未能找到 geo_point 字段位置。 location 字段在映射中应该有 geo_point,但会得到 lat、lon。
模型类:
import org.springframework.data.elasticsearch.annotations.GeoPointField;
import org.springframework.data.elasticsearch.core.geo.GeoPoint;
class EsMapping extends TestIndex{
@GeoPointField
private GeoPoint location;
@Field(type = FieldType.Double)
private double latitude;
@Field(type = FieldType.Double)
private double longitude;
.
.
}
TestIndex.java
class TestIndex{
@Field(type = FieldType.Text)
private String name;
.
.
}
测试控制器
@Autowired
private ElasticsearchOperations elasticsearchOperations;
IndexOperations esMappingIndex =
elasticsearchOperations.indexOps(EsMapping.class);
esMappingIndex.delete();
esMappingIndex.create();
esMappingIndex.putMapping(esMappingIndex.createMapping());
esMappingIndex.refresh();
映射:(非预期) http://localhost:9200/testindex/_mapping
"location": {
"properties": {
"lat": {
"type": "float"
},
"lon": {
"type": "float"
}
}
},
"latitude": {
"type": "float"
},
"longitude": {
"type": "float"
},
错误:
{"error":{"root_cause":[{"type":"query_shard_exception","reason":"failed to find geo_point field [location] ","index_uuid":"QLCjshecRNqDMXtkrtbF9g","index":"testindex"}],"type":"search_phase_execution_exception","reason":"all shards failed","phase":"query","grouped":true,"failed_shards":[{"shard":0,"index":"testindex","node":"jCKzz88BQXeL3wzyX6c8lQ","reason":{"type":"query_shard_exception","reason":"failed to find geo_point field [location]","index_uuid":"QLCjshecRNqDMXtkrtbF9g","index":"testindex"}}]},"status":400}
预期映射
"location": {
"type": "geo_point"
},
"latitude": {
"type": "double"
},
"longitude": {
"type": "double"
},
【问题讨论】:
-
您能否提供完整的实体定义和发生此错误时的更多上下文?
-
@P.J.Meisch 感谢您的回复,我已经添加了预期的映射和控制器类代码。
标签: elasticsearch spring-data-elasticsearch