正确查询 elasticsearch php 库上的计数

Correct query for count on elasticsearch php library

我正在使用 php library for elasticsearch 我正在尝试使用 count 方法从搜索中获取计数,以避免获取所有结果。但似乎我在查询 elasticsearch 服务器时没有使用正确的格式或其他东西。

这是我正在做的事情

        $hosts = ['localhost:9200'];
        $client = ClientBuilder::create()
        ->setHosts($hosts)
        ->build();


        $params = [
        'index' => 'logstash-*',
        'type'  => 'INFO',
        'body'  => [
            'query' => [
                'bool' => [
                    "should" => [
                        ["term" => ["tags" => "producer"]],
                        ["term" => ["tags" => "statistics"]],
                        ["term" => ["message" => "view"]],
                        ["term" => ["context.id" => 1]]
                    ]
                ]
            ]
        ]
    ];


$response = $client->search($params); // was returning all the results too, I was wrong
$response = $client->count($params); // return a count of all my documents in elasticsearch instance, that's wrong

修复了 @Val 的问题,我将最小值设置为 4 并且有效!

    array (size=4)
  'took' => int 14
  'timed_out' => boolean false
  '_shards' => 
    array (size=3)
      'total' => int 10
      'successful' => int 10
      'failed' => int 0
  'hits' => 
    array (size=3)
      'total' => int 11
      'max_score' => float 7.852423
      'hits' => 
        array (size=10)
          0 => 
            array (size=5)
              ...
          1 => 
            array (size=5)
              ...
          2 => 
            array (size=5)
              ...
          3 => 
            array (size=5)
              ...
          4 => 
            array (size=5)
              ...
          5 => 
            array (size=5)
              ...
          6 => 
            array (size=5)
              ...
          7 => 
            array (size=5)
              ...
          8 => 
            array (size=5)
              ...
          9 => 
            array (size=5)
              ...
array (size=2)
  'count' => int 11
  '_shards' => 
    array (size=3)
      'total' => int 10
      'successful' => int 10
      'failed' => int 0

如何获得查询的正确计数?

我用正确答案编辑了问题。 最终查询为:

$params = [
    'index' => 'logstash-*',
    'type'  => 'INFO',
    'body'  => [
        'query' => [
            'bool' => [
                "should" => [
                    ["term" => ["tags" => "producer"]],
                    ["term" => ["tags" => "statistics"]],
                    ["term" => ["message" => "view"]],
                    ["term" => ["context.id" => 1]]
                ],
               "minimum_should_match" => 4
            ]
        ]
    ]
];