我正在尝试关注documentation for geo_points。 为此,我创建了一个名为“cities”的索引
curl -X POST -H "Cache-Control: no-cache" -H -d '{
"mappings": {
"cities": {
"properties": {
"name": {
"type": "string",
"fields": {
"raw": {
"type": "string",
"index": "not_analyzed"
}
}
},
"location":{
"type": "geo_point"
}
}
}
}
}' "http://192.168.0.76:9200/cities"
我现在正尝试使用以下请求插入文档:
curl -X POST -H "Cache-Control: no-cache" -d '{
"name": "Amsterdam",
"location": "52.3702,4.8952"
}' "http://192.168.0.76:9200/cities/properties?pretty"
然而,这会返回以下错误:
{
"error": {
"root_cause": [
{
"type": "mapper_parsing_exception",
"reason": "failed to parse"
}
],
"type": "mapper_parsing_exception",
"reason": "failed to parse",
"caused_by": {
"type": "illegal_state_exception",
"reason": "Mixing up field types: class org.elasticsearch.index.mapper.core.StringFieldMapper$StringFieldType != class org.elasticsearch.index.mapper.geo.BaseGeoPointFieldMapper$GeoPointFieldType on field location"
}
},
"status": 400
}
对我来说,这看起来很奇怪,因为文档声明我应该能够使用字符串表示法插入文档:
将location字段定义为geo_point,我们可以继续 包含纬度/经度对的索引文档,可以是 格式化为字符串,数组或对象:
字符串表示,带“lat,lon”。
我做错了什么?
答案 0 :(得分:1)
插入时出错。您无意中插入了不同的映射类型 properties
而不是cities
。来自不同映射类型中具有相同名称的documentation字段必须具有相同的映射
这将有效
curl -X POST -H "Cache-Control: no-cache" -d '{
"name": "Amsterdam",
"location": "52.3702,4.8952"
}' "http://192.168.0.76:9200/cities/cities?pretty"