2016-03-30 37 views
0

我儘量簡短。此搜索不適用multi_match中的搜索關鍵字。我插入的任何搜索文字,我總是得到相同的結果Elasticsearch:multi_match對過濾器沒有影響

如果我刪除filtered/filter,它會給我一個合適的搜索。爲什麼?

GET /catalog/products/_search 
{ 
    "from":0, 
    "size":150, 
    "query":{ 
     "filtered":{ 
     "query":{ 
      "multi_match":{ 
       "query":"text to search", 
       "fields":[ 
        "title^5", 
        "description" 
       ] 
      }, 
      "filter":{ 
       "and":[ 
        { 
        "term":{ 
         "category": 2 
        } 
        }, 
        { 
        "not":{ 
         "term":{ 
          "subCategory": 3 
         } 
        } 
        } 
       ] 
      } 
     } 
     } 
    } 
} 

回答

2

將過濾器在同一水平上的查詢,例如:

GET /catalog/products/_search 
{ 
    "from":0, 
    "size":150, 
    "query":{ 
     "filtered":{ 
     "query":{ 
      "multi_match":{ 
      "query":"text to search", 
      "fields":[ 
       "title^5", 
       "description" 
      ] 
      } 
     }, 
     "filter":{ 
      "and":[ 
       { 
       "term":{ 
        "category": 2 
       } 
       }, 
       { 
       "not":{ 
        "term":{ 
         "subCategory": 3 
        } 
       } 
       } 
      ] 
     } 
     } 
    } 
} 
+0

太好了!沒有你的幫助,我會失去視力來找到問題! – Ivan