一尘不染

ElasticSearch,与过滤器多重匹配?

elasticsearch

我在ES中有一个多匹配查询,并希望添加一个过滤器。

{
  "multi_match" : {
    "query" : "this is a test",
    "fields" : [ "subject^2", "message" ]
  }
}

添加此过滤器的语法是什么?

我试过了:

{
  "multi_match" => {
    "query" => "list",
    "fields" => [ "username" ]

  },
"filter" => {
        "term" => { "username" => "slimkicker"}
    }
}

阅读 254

收藏
2020-06-22

共1个答案

一尘不染

根据您的需要,必须将过滤器放置在正确的位置。您有两种选择:

使用顶级过滤器,并将该过滤器仅应用于搜索结果,而不应用于各个方面

{
    "query" : {
        "multi_match" : {
            "query" : "this is a test",
            "fields" : [ "subject^2", "message" ]
        }
    },
    "filter" : {
        "term" : { "username": "slimkicker" }
    }
}

使用过滤的查询,并将过滤器应用于搜索结果和构面

{
    "query" : {
        "filtered" : {
            "query" : {
                "multi_match" : {
                    "query" : "this is a test",
                    "fields" : [ "subject^2", "message" ]
                }
            },
            "filter" : {
                "term" : { "username": "slimkicker" }
            }
        }
    }
}
2020-06-22