{ title: 'abcccc',
price: 3300,
price_per: 'task',
location: { lat: -33.8756, lon: 151.204 },
description: 'asdfasdf'
}
上面是我想要索引的JSON。然而,当我索引它时,错误是:
{"error":"MapperParsingException[Failed to parse [location]]; nested: ElasticSearchIllegalArgumentException[unknown property [lat]]; ","status":400}
如果我去掉"位置"字段,一切正常。
如何索引地理?我读了教程,仍然对它的工作原理感到困惑。它应该这样工作,对吧。。。?
您收到此错误消息是因为字段位置未正确映射。可能在某个时间点,您试图对此字段中的字符串进行索引,现在它被映射为字符串。Elasticsearch无法自动检测字段是否包含地理点。它必须在映射中明确指定。否则,Elasticsearch会根据您在第一个索引记录中使用的地理点表示类型,将此类字段映射为字符串、数字或对象。一旦将字段添加到映射中,就不能再更改其类型。因此,为了修复这种情况,您需要删除此类型的映射并重新创建它。以下是为地理点字段指定映射的示例:
curl -XDELETE "localhost:9200/geo-test/"
echo
# Set proper mapping. Elasticsearch cannot automatically detect that something is a geo_point:
curl -XPUT "localhost:9200/geo-test" -d '{
"settings": {
"index": {
"number_of_replicas" : 0,
"number_of_shards": 1
}
},
"mappings": {
"doc": {
"properties": {
"location" : {
"type" : "geo_point"
}
}
}
}
}'
echo
# Put some test data in Sydney
curl -XPUT "localhost:9200/geo-test/doc/1" -d '{
"title": "abcccc",
"price": 3300,
"price_per": "task",
"location": { "lat": -33.8756, "lon": 151.204 },
"description": "asdfasdf"
}'
curl -XPOST "localhost:9200/geo-test/_refresh"
echo
# Search, and calculate distance to Brisbane
curl -XPOST "localhost:9200/geo-test/doc/_search?pretty=true" -d '{
"query": {
"match_all": {}
},
"script_fields": {
"distance": {
"script": "doc['''location'''].arcDistanceInKm(-27.470,153.021)"
}
},
"fields": ["title", "location"]
}
'
echo
由于您没有指定如何解析它,因此:
使用未知属性名在JSON.NET中解析JSON
可能会带来一些光线。