添加应该查询必须使用bool查询不正确匹配

时间:2018-01-30 14:03:09

标签: laravel elasticsearch

我有一个必须查询包含多个bool包含应该查询.. 我的意思是我想从内部进行多个查询使OR查询和外部make AND查询..这样的事情:

(condition_1 || condition_2) && (condition_3 || condition_4) && ...

所以我按照以下方式处理:

"must" => [
  [
    "terms" => [
      "status_id" => [164,163]
    ]
  ],
  [
    "term" => [
      "is_visible" => true
    ]
  ],
  [
    "bool" => [
      "should" => [
        [
          "bool" => [
            "must_not" => [
              "exists" => [
                "field" => "candidate_location_id"
              ]
            ]
          ]
        ],
        [
          "bool" => [
            "filter" => [
              "terms" => [
                "candidate_location_id" => [1]
              ]
            ]
          ]
        ]
      ]
      "minimum_should_match" => 1
    ]
  ],
  [
    "bool" => [
      "should" => [
        [
          "bool" => [
            "must_not" => [
              "exists" => [
                "field" => "location_id"
              ]
            ]
          ]
        ],
        [
          "terms" => [
            "location_id" => [1,2,3,70]
          ]
        ]
      ]
    ]
  ]
]

这是这样的:

(status_id == values) AND (is_visible == true) AND ((candidate_location_id == null) OR (candidate_location_id == values)) AND ((location_id == null) OR (location_id == values))

我的问题是我认为查询是否会忽略其中的两个条件...我的意思是查询返回文档... candidate_location_id不属于nullvalues在查询中定义..

我也看到了minimum_should_match但是它没有用

如果有人有任何解决方案来解决我的问题,请与我分享..谢谢大家。

0 个答案:

没有答案