2016-03-30 105 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