2015-09-11 36 views
2

運行以下查詢後,我得到異常,因爲沒有查詢註冊[存在]。請幫幫我。Elasticsearch沒有任何查詢註冊爲[存在]]

{ 
    "query": { 
    "function_score": { 
     "query": { 
     "bool": { 
      "must": { 
      "match": { 
       "_all": { 
       "query": "cardio new york" 
       } 
      } 
      } 
     } 
     }, 
     "functions": [ 
     { 
      "gauss": { 
      "geo_location": { 
       "origin": { 
       "lat": 40.7127, 
       "lon": -74.0059 
       }, 
       "scale": "100km", 
       "offset": "0km", 
       "decay": 0.9 
      } 
      } 
     }, 
     { 
      "gauss": { 
      "startdate": { 
       "origin": "now", 
       "scale": "30d", 
       "offset": "30d" 
      } 
      }, 
      "weight": 0.5 
     } 
     ], 
     "filter": { 
     "query": { 
      "bool": { 
      "must": { 
       "match": { 
       "_all": { 
        "query": "cardio new york" 
       } 
       } 
      }, 
      "should": { 
       "exists": { 
       "fields": [ 
        "venue", 
        "geo_location" 
       ] 
       } 
      } 
      } 
     } 
     } 
    } 
    } 
} 

我想通過組合布爾匹配查詢來過濾function_score後的搜索結果。

回答

4

exists不是一個查詢,它的過濾器,你不能在bool查詢中使用它,相反,我會用bool過濾器和包裝只matchquery過濾器是這樣的:

"filter": { 
    "bool": { 
     "must": [{ 
     "query": { 
      "match": { 
      "_all": { 
       "query": "cardio new york" 
      } 
      } 
     } 
     }, { 
     "exists": { 
      "fields": [ 
      "venue", 
      "geo_location" 
      ] 
     } 
     }] 
    } 
    } 
+0

感謝回答這個。現在我正在尋找我想要的文件。但我有一個情景,用戶可以像「心臟2014」一樣搜索,基本上想要在2014年舉行心臟病學大會。當我搜索它再給出2015年會議與我高分。如何處理這個。請建議。 – sandeep

+0

@sandeep如果我回答了您的原始問題,請接受我的回答並單獨提出一個新問題。 stackoverflow網站的格式與典型的論壇不同。這是問答網站。所以我們應該回避評論。說,我認爲你要查找的是你的查詢中的'和'運算符。 – imotov

+0

再次感謝你。我的實際問題陳述在這裏共享,我正在使用上述查詢。並卡在那裏。 http://stackoverflow.com/q/32499245/5118016 – sandeep

1

這取決於你的版本,在版本2.0之前,您可以使用Exists過濾器,如imotov的答案中所示。

隨着2.0 and after存在過濾器已取代存在查詢documentation for current version

因此存在新的查詢將如下所示:

{ 
"index": "foobars", 
"type": "foo", 
"body": { 
    "query": { 
    "bool": { 
    "must": 
     {"exists" : { "field" : "bar" }} 
    } 
    }, 
    "from": 0, 
    "size": 20 
} 
} 
相關問題