【问题标题】:Elasticsearch: multi_match no effect with filtersElasticsearch:multi_match对过滤器没有影响
【发布时间】:2016-03-30 20:06:11
【问题描述】:

我尽量简短。此搜索不应用 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
                        }
                     }
                  }
               ]
            }
         }
      }
   }
}

【问题讨论】:

    标签: elasticsearch


    【解决方案1】:

    在查询时将过滤器放在同一级别,如下所示:

    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
                        }
                     }
                  }
               ]
            }
          }
        }
    } 
    

    【讨论】:

    • 太棒了!没有你的帮助,我会看不到问题的所在!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-28
    • 2022-10-25
    • 2020-11-10
    • 2015-11-04
    • 2010-12-01
    • 2013-10-07
    相关资源
    最近更新 更多