2016-07-20 34 views
0

我無法讓我的過濾器查詢與geo_distance正常工作。它似乎返回0命中。但是如果我不試圖找到地理位置,我所有的其他查詢都可以工作。使用geo_distance過濾器不會使用ElasticSearch返回任何匹配

我使用ElasticSearch的2.3.1版

{ 
    "name" : "Mar-Vell", 
    "cluster_name" : "elastic-logs", 
    "version" : { 
    "number" : "2.3.1", 
    "build_hash" : "bd980929010aef404e7cb0843e61d0665269fc39", 
    "build_timestamp" : "2016-04-04T12:25:05Z", 
    "build_snapshot" : false, 
    "lucene_version" : "5.5.0" 
    }, 
    "tagline" : "You Know, for Search" 
} 

我已經提出請求使用JSON像這樣映射與類型「geo_point」我的位置鍵:

curl -XPUT 'http://10.0.7.181:9200/connections/profile/_mapping' -d ' 
{ 

     "profile" : { 
     "properties" : { 
      "location" : { 
       "type" : "geo_point" 
      } 
     } 
     } 
} 

它返回這個。我假設我的更改是有影響的。

{"acknowledged":true} 

下面是我送過來我們ElasticSearch我的數據

{ 
    "_index": "connections", 
    "_type": "profile", 
    "_id": "92", 
    "_score": 1, 
    "_source": { 
     "profile": { 
     "location": { 
      "lon": -111.8909815, 
      "lat": 40.7607818 
     }, 
     "age": 44, 
     "school": { 
      "undergraduate": { 
      "universityId": 1814, 
      "active": true, 
      "programId": 9 
      }, 
      "graduate": { 
      "universityId": 1814, 
      "active": true, 
      "programId": 7 
      } 
     }, 
     "bio": "Everything is awesome! " 
     }, 
     "id": 0, 
     "active": false, 
     "optIn": true 
    } 
    } 

我查詢的例子。沒有瘋狂。

{ 
    "filter" : { 
     "geo_distance" : { 
     "distance" : "1000mi", 
     "distance_type": "plane", 
     "location" : { 
      "lon": -111.8391029, 
      "lat": 40.7607818 
     } 
     } 
    }, 
    "query" : { 
     "match_all" : {} 
    } 
} 

我試過將距離改爲1英里,100英里和1000英里。它應該返回100英里但沒有表演的東西。我也嘗試過使用不同的單位測量來確定它是否會做任何事情。同樣的交易。

座標在鹽湖城。經度和緯度的順序應該是正確的。我不知道還有什麼我應該嘗試。

回答

1

您的位置字段的名稱是location,但在您的查詢中,您使用的是geoPoint作爲字段名稱。試試這個:

{ 
    "filter" : { 
     "geo_distance" : { 
     "distance" : "1000mi", 
     "distance_type": "plane", 
     "location" : { 
      "lon": -111.8391029, 
      "lat": 40.7607818 
     } 
     } 
    }, 
    "query" : { 
     "match_all" : {} 
    } 
} 

更新:好吧,這是明顯的錯誤,我看到了,所以我沒有看任何進一步。以下是我的一個項目中的一個工作查詢(包含您的值):

{ 
    "query": { 
    "bool": { 
     "must": { 
     "match_all": [] 
     }, 
     "filter": { 
     "geo_distance": { 
      "distance": "1000mi", 
      "distance_type": "plane", 
      "location": { 
      "lat": "-111.8391029", 
      "lon": "40.7607818" 
      } 
     } 
     } 
    } 
    } 
} 

這應該有效。

+0

對不起,我複製並粘貼了錯誤的代碼。我對我的示例搜索查詢進行了更改。我正在試驗一個新的屬性,我想通過創建一個名爲「geoPoint」的類型爲「geo_point」的不同屬性,它具有相同的值,它會產生變化。我以前嘗試通過「位置」搜索沒有運氣。 – Downstairz

+0

好吧,我現在用我的一個項目中的工作查詢更新了我的答案。 – Pelmered

0

@感謝幫助我的過濾器查詢。我發現我的映射不正確。現在一切都按預期工作。所以確保你正確映射它。

curl -XPUT 'http://10.0.7.181:9200/connections' -d ' 

{ 
    "mappings":{ 
     "profile":{ 
     "properties":{ 
      "location":{ 
       "type":"geo_point" 
      } 
     } 
     } 
    } 
}' 
相關問題