2013-02-24 114 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