Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ElasticSearch Delete by query not working in PHP

I am using Elastic search 5.x and the following code is working fine:

curl -XPOST "http://localhost:9200/test_index/test_info/_delete_by_query" -d'
{
  "query": {
    "match": {
        "category_id": "21"
    }
  }
}'

But when I am trying the same in my php code, its not working:

$client->deleteByQuery([
'index' => 'test_index',
'type'  => 'test_info',

    'query' => [
        'match' => [
                ['category_id' => 21]

        ]       
    ]

]);

like image 920
Siji Avatar asked Apr 06 '26 00:04

Siji


1 Answers

You need to provide your query array inside body array of your parameters:

$client->deleteByQuery([
    'index' => 'test_index',
    'type' => 'test_info',
    'body' => [
        'query' => [
            'match' => [
                ['category_id' => 21]
            ]
        ]
    ]
]);
like image 52
Mariusz Avatar answered Apr 08 '26 13:04

Mariusz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!