# Msearch with PHP

**URL:** <https://discuss.elastic.co/t/msearch-with-php/340585>\
**Category:** Elasticsearch\
**Created:** [August 10, 2023, 6:28pm UTC](https://discuss.elastic.co/t/msearch-with-php/340585 "2023-08-10T18:28:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Murilo\_Livorato](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/murilo_livorato/32/123848_2.png) [@Murilo\_Livorato](https://discuss.elastic.co/u/Murilo_Livorato)\
**Post date:** [August 10, 2023, 6:28pm UTC](https://discuss.elastic.co/t/msearch-with-php/340585/1 "2023-08-10T18:28:16Z")

</div>

Hello , I am using msearch

like this doc -

> **[Multi search API | Elasticsearch Guide \[8.9\] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-multi-search.html)**

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

this is my test code -

```auto
  $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 -

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

```

I Tried like this as well -

```auto
$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

```auto
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
                        (
                        )

                )

        )

)

```

---

<div class="post-metadata">

**Author:** ![Murilo\_Livorato](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/murilo_livorato/32/123848_2.png) [@Murilo\_Livorato](https://discuss.elastic.co/u/Murilo_Livorato)\
**Post date:** [August 11, 2023, 1:56pm UTC](https://discuss.elastic.co/t/msearch-with-php/340585/2 "2023-08-11T13:56:44Z")

</div>

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

USING SEARCH -

```auto
   $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

```auto
^ 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 -

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

        dd($response['hits']);

```

RESULT

```auto
Undefined array key "hits"

```

@polyfractal

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [September 8, 2023, 1:57pm UTC](https://discuss.elastic.co/t/msearch-with-php/340585/3 "2023-09-08T13:57:16Z")

</div>

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