2016-07-25 193 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

坏贴! ,谢谢,第二个对我来说工作正常,第一个没有返回任何数据 –