2016-07-25 190 views
0

發佈此彈性搜索拋出異常 org.elasticsearch.index.query.QueryParsingException:MYAPP]沒有爲[匹配]彈性搜索查詢 - 彈性搜索1.7

http://localhost:9200/ 
     GET myapp/_search/ 
    { 
     "query": { 
     "filtered": { 
      "filter": { 
      "bool": { 
       "must": [ 
       { 
        "match": { 
        "userName": "Micky" 
        } 
       }, 
       { 
        "match": { 
        "Age": 21 
        } 
       } 
       ], 
       "should": [], 
       "must_not": [] 
      } 
      } 
     } 
     }, 
     "from": 0, 
     "size": 20 
    } 

爲什麼這個查詢註冊過濾器錯誤(技術細節)?

+0

的可能的複製[ElasticSearch:無過濾爲\註冊[匹配\] \]](http://stackoverflow.com/questions/21116803/elasticsearch-no-filter-registered-for-match) – Mico

回答

0

沒有過濾器命名爲match,您可以使用term代替

POST myapp/_search/ 
{ 
    "query": { 
    "filtered": { 
     "filter": { 
     "bool": { 
      "must": [ 
      { 
       "term": { 
       "userName": "Micky" 
       } 
      }, 
      { 
       "term": { 
       "Age": 21 
       } 
      } 
      ], 
      "should": [], 
      "must_not": [] 
     } 
     } 
    } 
    }, 
    "from": 0, 
    "size": 20 
} 

或使用constant_score查詢,而不是filtered,因爲你沒有過濾器。

POST myapp/_search/ 
{ 
    "query": { 
    "constant_score": { 
     "query": { 
     "bool": { 
      "must": [ 
      { 
       "match": { 
       "userName": "Micky" 
       } 
      }, 
      { 
       "match": { 
       "Age": 21 
       } 
      } 
      ], 
      "should": [], 
      "must_not": [] 
     } 
     } 
    } 
    }, 
    "from": 0, 
    "size": 20 
} 
+0

異常「錯誤」:「org.elasticsearch.index.query.QueryParsingException:[myapp]請求不支持[from]」 –

+0

錯誤的複製/粘貼?對我來說工作得很好。 – Val

+0

壞貼! ,謝謝,第二個對我來說工作正常,第一個沒有返回任何數據 –