2014-02-09 104 views
3

我使用Geo Distance FilterElasticSearch不管我什麼搜索距離爲我,elasticsearch 0.90.11返回零結果。地理距離與ElasticSearch過濾器總是返回0結果

這裏就是我所做的:首先,刪除/創建具有地理映射一個新的指標:

curl -XDELETE 'http://localhost:9200/photos' 

curl -XPOST 'http://localhost:9200/photos' -d ' 
{ 
    "mappings": { 
    "pin" : { 
     "properties" : { 
      "location" : { 
       "type" : "geo_point" 
      } 
     } 
    } 
    } 
} 
' 

然後,添加一個文件:

curl -XPOST 'http://localhost:9200/photos/photo?pretty=1' -d ' 
{ 
    "pin" : { 
     "location" : { 
     "lat" : 46.8, 
     "lon" : -71.2 
     } 
    }, 
    "file" : "IMG_2115.JPG" 
} 
' 

然後搜索:

curl -XGET 'http://localhost:9200/photos/_search?pretty=1&size=20' -d ' 
{ 
    "query" : { 
     "match_all" : {} 
    }, 
    "filter" : { 
     "geo_distance" : { 
     "distance" : "10km", 
     "pin.location" : { 
      "lat" : "46.8", 
      "lon" : "-71.2" 
     } 
     } 
    } 
} 
' 

但搜索收益的匹配率爲零:

{ 
    "took" : 2, 
    "timed_out" : false, 
    "_shards" : { 
    "total" : 5, 
    "successful" : 5, 
    "failed" : 0 
    }, 
    "hits" : { 
    "total" : 0, 
    "max_score" : null, 
    "hits" : [ ] 
    } 
} 

任何人都知道爲什麼,它沒有找到半徑範圍內的文件?作爲一個有趣的方面說明,在上面引用的文檔中描述的具有「查詢」和「過濾器」作爲子字段的「過濾」語法似乎不再起作用,似乎現在「查詢」和「過濾器」需要是在json查詢的頂層。

任何幫助表示讚賞...

回答

6

原來的官方手冊頁是不準確的,則映射必須

[Sun Feb 9 11:01:55 2014] # Request to: http://localhost:9200 
curl -XPUT 'http://localhost:9200/photos?pretty=1' -d ' 
{ 
    "mappings" : { 
     "photo" : { 
     "properties" : { 
      "Location" : { 
       "type" : "geo_point" 
      } 
     } 
     } 
    } 
} 
' 

,並與GPS數據記錄則需要像添加這樣的:

[Sun Feb 9 11:01:56 2014] # Request to: http://localhost:9200 
curl -XPOST 'http://localhost:9200/photos/photo?pretty=1' -d ' 
{ 
    "file" : "/home/mschilli/iphone/IMG_2115.JPG", 
    "Location" : [ 
     46.8, 
     -71.2 
    ] 
} 
' 

再後來查詢

[Sun Feb 9 11:05:00 2014] # Request to: http://localhost:9200 
curl -XGET 'http://localhost:9200/photos/_search?pretty=1&size=100' -d ' 
{ 
    "filter" : { 
     "geo_distance" : { 
     "distance" : "1km", 
     "Location" : [ 
      36.986, 
      -121.443333333333 
     ] 
     } 
    }, 
    "query" : { 
     "match_all" : {} 
    } 
} 
' 

將顯示所期望的結果,正確地過濾掉所選擇的GPS距離之外的效果。

+0

+1謝謝!我一直在想這個問題2天。 –

+0

我提交了[拉入請求(https://github.com/elastic/elasticsearch/pull/15745)來更新誤導文檔。 – Jonny

相關問題