Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 我能';t使用弹性搜索进行创建和请求_Php_<img Src="//i.stack.imgur.com/RUiNP.png" Height="16" Width="18" Alt="" Class="sponsor Tag Img">elasticsearch_Doctrine - Fatal编程技术网 elasticsearch,doctrine,Php,elasticsearch,Doctrine" /> elasticsearch,doctrine,Php,elasticsearch,Doctrine" />

Php 我能';t使用弹性搜索进行创建和请求

Php 我能';t使用弹性搜索进行创建和请求,php,elasticsearch,doctrine,Php,elasticsearch,Doctrine,我想用ES发出一个和请求,所以我在boolQuery中的术语之间(对于标记.id)放置了一个必须,但它不起作用。。。我接收元素,但像或 { "query": { "bool": { "must": [ { "terms": { "computerId": [ 1 ] } }, { "nest

我想用ES发出一个
请求,所以我在
boolQuery
中的术语之间(对于
标记.id
)放置了一个
必须
,但它不起作用。。。我接收元素,但像

{
  "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
                }
              }
            }
          }
        }
      ]
    }
  }
}
术语的行为类似于或,因此您的查询是AND(1、2或3)

术语查询返回在提供的字段中包含一个或多个确切术语的文档


希望这对你有所帮助

你想实现什么?1、2和3?没错,我只想要具有三个
标记.id
的对象,但通过此查询,我会收到几乎与其中一个
标记.id
匹配的所有对象,请参见我的答案。如果你有任何问题,请告诉我。3个嵌套?这是个好习惯?我测试了一下,然后告诉你。谢谢你,如果你的对象看起来像:tags:[{id:1},{id:2},{id:3}],那么这就是在内部对象之间进行操作的方式。啊,好的,这正是我得到的对象,我正在寻找用3嵌套在内部来构建查询的方法。因为在我得到一个嵌套之前,它是我的方法的输出,很高兴它能工作。请看