0

我正在尝试编写一个查询,要求“区域”为 530,“开始”为 06192013,或“区域”为“530”,“开始”为“空白”。此外,在这两种情况下,“space”都是“top”或“space2”是“bottom”。此查询似乎正在抓取与这些场景中的任何一个匹配的任何内容,我该如何更改它以使其像我想要的那样工作?

{
  "size":25, 
  "from":0,
  "query": {
    "custom_filters_score": {
      "query": {
        "filtered": {
          "query": {
            "bool": {
              "must": [
                {"term":{"type":"ghost"}}, 
                {"term":{"area":"530"}}
              ]
            }
          }, 
          "filter" : {
            "or": [
              {"terms":{"space": ["top"]}}, 
              {"terms":{"space2":["bottom"]}}, 
              {
                "and": [
                  {"term":{"area":"530"}}, 
                  {"term":{"start":"06192013"}}
                ]
              }, 
              {
                "and": [
                  {"term":{"area":"530"}}, 
                  {"term":{"starts":"blank"}}
                ]
              }
            ]
          }
        }
      }, 
      "filters": [
        {"filter":{"term":{"filter1":5743}}, "boost":"1000"}, 
        {"filter":{"term":{"filter2":4451}}, "boost":"64"}, 
        {"filter":{"term":{"filter3":["tech"]}}, "boost":"16"}, 
        {"filter":{"terms":{"filter4":[]}}, "boost":"8"}, 
        {"filter":{"terms":{"filter5":[]}}, "boost":"5"}, 
        {"filter":{"term":{"access":"1"}}, "boost":"2"}
      ], 
      "score_mode":"total"
    }
  }
}
4

1 回答 1

1

你快到了!试试这个:

...
"query" : { "match_all":{} },
"filter" : {
    "and": [
        {
            "or": [
                {"term":{"space": "top"}}, 
                {"term":{"space2":"bottom"}}
            ]
        },
        {
            "and": [
                 {"term":{"area":"530"}}, 
                 {
                     "or": [
                         {"term":{"start":"06192013"}},
                         {"term":{"starts":"blank"}}
                     ]
                 }
            ]
        }
    ]
}
...

除非您需要评分(看起来不像),否则您应该使用过滤器完成所有这些操作,它们不会计算分数并且因此更快。

最终"query" : { "match_all":{} }会为所有匹配过滤器的文档提供相同的分数

注意:我还将您的terms查询与一个元素的数组转换为term查询...

于 2013-06-12T11:04:18.203 回答