Msearch with PHP

Hello , I am using msearch

like this doc -

well it is working in kibana .
but when I try to do it , in php . does not work .

this is my test code -

  $this->elasticSeacrh->msearch([
                                                [ 'index' => 'index-test-one'],
                                                [ 'body'   => [
                                                    'query' => [
                                                        'match_all' => new \stdClass()
                                                    ]
                                                ]],
                                                [ 'index' => 'index-test-two'],
                                                [  'body'   => [
                                                    'query' => [
                                                        'match_all' => new \stdClass()
                                                    ]
                                                ]]
                                            ]);

it gives his error -

{"message":"The parameter body is required","errors":{"message":["The parameter body is required"]}}

I Tried like this as well -

$response =  $this->elasticSeacrh->msearch([
            'body' => [
                [ 'index' =>  'index-test-one'],
                ["query" => [
                    'match_all' => new \stdClass()
                ]],

                [ 'index' =>  'index-test-two'],
                ["query" => [
                    'match_all' => new \stdClass()
                ]],
            ]
        ]);


it returns this

Elastic\Elasticsearch\Response\Elasticsearch Object
(
    [response:protected] => GuzzleHttp\Psr7\Response Object
        (
            [reasonPhrase:GuzzleHttp\Psr7\Response:private] => OK
            [statusCode:GuzzleHttp\Psr7\Response:private] => 200
            [headers:GuzzleHttp\Psr7\Response:private] => Array
                (
                    [X-elastic-product] => Array
                        (
                            [0] => Elasticsearch
                        )

                    [content-type] => Array
                        (
                            [0] => application/vnd.elasticsearch+json;compatible-with=8
                        )

                    [content-length] => Array
                        (
                            [0] => 5810
                        )

                )

            [headerNames:GuzzleHttp\Psr7\Response:private] => Array
                (
                    [x-elastic-product] => X-elastic-product
                    [content-type] => content-type
                    [content-length] => content-length
                )

            [protocol:GuzzleHttp\Psr7\Response:private] => 1.1
            [stream:GuzzleHttp\Psr7\Response:private] => GuzzleHttp\Psr7\Stream Object
                (
                    [stream:GuzzleHttp\Psr7\Stream:private] => Resource id #19
                    [size:GuzzleHttp\Psr7\Stream:private] => 
                    [seekable:GuzzleHttp\Psr7\Stream:private] => 1
                    [readable:GuzzleHttp\Psr7\Stream:private] => 1
                    [writable:GuzzleHttp\Psr7\Stream:private] => 1
                    [uri:GuzzleHttp\Psr7\Stream:private] => php://temp
                    [customMetadata:GuzzleHttp\Psr7\Stream:private] => Array
                        (
                        )

                )

        )

)

It seams to bring always empty result M Search in PHP .

USING SEARCH -

   $response =   $elasticSeacrh->search(['index' => 'index-test-one',
            'size'   => 4,             // how many results *per shard* you want back
            'body'   => [
                'query' => [
                    'match_all' => new \stdClass()
                ]
            ]
        ]);
        dd($response['hits']);

RESULT

^ array:3 [▼
  "total" => array:2 [▶]
  "max_score" => 1.0
  "hits" => array:4 [▼
    0 => array:4 [▶]
    1 => array:4 [▶]
    2 => array:4 [▶]
    3 => array:4 [▶]
  ]
]

BUT using MSEARCH , does not work , always bringing empty result -

USING MSEARCH -

 $response = $elasticSeacrh->msearch(['body'  => [
            ['index' => 'metric-property-broker-daily-2023-06'],
            ['size'   => 4,  'query' => ['match_all' => new \stdClass() ]]
        ]]);

        dd($response['hits']);

RESULT

Undefined array key "hits"

@polyfractal

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.