elastic / elasticsearch-php

Official PHP client for Elasticsearch.
https://www.elastic.co/guide/en/elasticsearch/client/php-api/current/index.html
MIT License
35 stars 970 forks source link

Docs not up2date? Trying to append an object to a nested array. #1183

Open Atomzwieback opened 2 years ago

Atomzwieback commented 2 years ago

Summary of problem or feature request

Current PHP Docs seems not be up2date?

Code snippet of problem

This example as you show it in the docs dont work?

$params = [
    'index' => 'my_index',
    'id'    => 'my_id',
    'body'  => [
        'script' => 'ctx._source.counter += count',
        'params' => [
            'count' => 4
        ]
    ]
];

$response = $client->update($params);

The error i got is: "[UpdateRequest] unknown field [params]"

System details

ziko1153 commented 2 years ago

@Atomzwieback Ya i m facing same issue. i think it should be something like that

 $params = [
                'index' => 'products',
                'body' => [
                    'script' => [
                        'lang' => 'painless',
                        'source' => 'ctx._source.name = params.name;ctx._source.brand = params.brand;ctx._source.category = params.category',
                        'params' => [
                            'name' => 'foo bar',
                            'brand' => 'brand',
                            'category' => 'category'
                        ]
                    ],
                    'query' => [
                        'ids' => [
                            'values' => [1,5]
                        ]
                    ]

                ]
            ];

return $this->client->updateByQuery($params);