使用带有 Or 运算符的术语查询

Da *_*lva 1 elasticsearch

我正在尝试通过以下方式使用术语查询!!

{
  "query": {
    "bool": {
      "must": [
        {
          "term": {
            "technology": "Space"
          }
        },
        {
          "term": {
            "Person": "Steve Simon"
          }
        }
      ]
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

它返回给我一个反馈的响应,其中两个字段都存在于单个反馈中,就像交叉操作一样。我可以使用术语查询来获取上述查询的 UNION 结果,例如,我希望所有具有space, 的Steve Simon提要单独存在,同时提供同时存在的提要。

mol*_*are 5

使用should代替must。此外,您必须设置minimum_should_match为 1,这意味着should匹配文档只需要一个子句。

{
  "query": {
    "bool": {
      "should": [
        {
          "term": {
            "technology": "Space"
          }
        },
        {
          "term": {
            "Person": "Steve Simon"
          }
        }
      ],
      "minimum_should_match": 1
    }
  }
}
Run Code Online (Sandbox Code Playgroud)