弹性搜索过滤查询,查询部分被忽略?

Elastic search filtered query, query part being ignored?

我正在用代码构建以下搜索,其想法是它过滤匹配集然后查询它,这样我就可以根据某些字段添加分数。出于某种原因,过滤器部分有效,但无论我在查询中输入什么(即在下面我没有索引 sdfsdfsdf)它仍然 returns 匹配过滤器的任何东西。

语法错误吗?

 {  
       "query":{  
          "filtered":{  
             "query":{  
                "bool":{  
                   "must":{  
                      "match":{  
                         "sdfsdfsdf":{  
                            "query":"4",
                            "boost":2.0
                         }
                      }
                   }
                },
                "filter":{  
                   "bool":{  
                      "must":[  
                         {  
                            "terms":{  
                               "_id":[  
                                  "55f93ead5df34f1900abc20b",
                                  "55f8ab0226ec4bb216d7c938",
                                  "55dc4e949dcf833308c63d6b"
                               ]
                            }
                         },
                         {  
                            "range":{  
                               "published_date":{  
                                  "lte":"now"
                               }
                            }
                         }
                      ],
                      "must_not":{  
                         "terms":{  
                            "_id":[  
                               "55f0a799acccc28204a5058c"
                            ]
                         }
                      }
                   }
                }
             }
          }
       }
    }

您需要将 sdfsdfsdf 替换为您的类型中现有的字段名称,例如title,否则我认为它会回退到 match_all 查询。

"match":{  
        "title":{  
              "query": "some text here",
              "boost":2.0
        }
}

您的 filter 级别不正确。它不应在 query 内,而应与 query 处于同一级别,如下所示:

{
  "query": {
    "filtered": {
      "query": {          <--- query and filter at the same level
        "bool": {
          "must": {
            "match": {
              "sdfsdfsdf": {
                "query": "4",
                "boost": 2
              }
            }
          }
        }
      },
      "filter": {         <--- query and filter at the same level
        "bool": {
          "must": [
            {
              "terms": {
                "_id": [
                  "55f93ead5df34f1900abc20b",
                  "55f8ab0226ec4bb216d7c938",
                  "55dc4e949dcf833308c63d6b"
                ]
              }
            },
            {
              "range": {
                "published_date": {
                  "lte": "now"
                }
              }
            }
          ],
          "must_not": {
            "terms": {
              "_id": [
                "55f0a799acccc28204a5058c"
              ]
            }
          }
        }
      }
    }
  }
}