2013-02-24 115 views
3
{ 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} 

如果我删除“位置”字段,一切正常。

如何建立地理位置?我阅读教程,我仍然困惑它如何工作。它应该像这样工作,对吧......?

+0

请添加导致该错误的步骤的完整描述。 – DrTech 2013-02-25 19:03:49

+0

您是否试过[其他格式](http://www.elasticsearch.org/guide/reference/mapping/geo-point-type.html),例如'位置:'-33.8756,151.204''? – mindas 2013-02-26 22:02:33

回答

2

因为现场位置不是正确映射您收到此错误信息。有可能在某个时间点,你试图在这个字段中索引一个字符串,现在它被映射为一个字符串。 Elasticsearch无法自动检测到某个字段包含geo_point。它必须在映射中明确指定。否则,Elasticsearch会根据您在第一个索引记录中使用的geo_point表示的类型将此字段映射为字符串,数字或对象。一旦将字段添加到映射中,其类型就不能再进行更改。因此,为了解决这种情况,您需要删除此类型的映射并重新创建。以下是指定geo_point字段映射的示例:

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