php - 我无法通过Elastic Search进行AND请求

标签 php elasticsearch doctrine

我想用ES发出AND请求,因此我在must中的术语之间(对于tags.id)放入了boolQuery,但是它不起作用...我收到的元素却像OR

{
  "query": {
    "bool": {
      "must": [
        {
          "terms": {
            "computerId": [
              1
            ]
          }
        },
        {
          "nested": {
            "path": "tags",
            "query": {
              "bool": {
                "must": [
                  {
                    "terms": {
                      "tags.id": [
                        1,
                        2,
                        3
                      ]
                    }
                  }
                ]
              }
            }
          }
        }
      ]
    }
  }
}

最佳答案

您应该在bool查询中使用nested

试试这个:

{
"query": {
    "bool": {
      "must": [
        {
          "terms": {
            "computerId": [
              1
            ]
          }
        },
        {
          "nested": {
            "path": "tags",
            "query": {
              "term": {
                "tags.id": {
                  "value": 1
                }
              }
            }
          }
        },
        {
          "nested": {
            "path": "tags",
            "query": {
              "term": {
                "tags.id": {
                  "value": 2
                }
              }
            }
          }
        },
        {
          "nested": {
            "path": "tags",
            "query": {
              "term": {
                "tags.id": {
                  "value": 3
                }
              }
            }
          }
        }
      ]
    }
  }
}

术语的行为类似于OR,因此您的查询执行的是AND(1 OR 2 OR 3)。

Terms query returns documents that contain one or more exact terms in a provided field.



From Here

希望这可以帮助

关于php - 我无法通过Elastic Search进行AND请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59696373/

相关文章:

php - Doctrine批量删除join表记录

php - 使用 Doctrine 插入时 mysql 上的重复条目

php - 如何在发布带有文件上传的表单后保留上传的文件?

php - mysql_connect() 导致网页崩溃

php - 获取url,给定的url重定向到

elasticsearch - 如何在Liferay中使用带有停用词的短语查询

search - 在 ElasticSearch 中找到文本的返回字段

php - Symfony2 : How to go back to a page where the request of a form was send from

php - preg_replace() 如何理解 $replacement 参数中的 '${1}1,$3'?

amazon-web-services - 如何通过 aws ES 服务设置自己的 Kibana 客户端