3

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]

        ]       
    ]

]);

5
  • Which version of the elasticsearch-php library are you using? Commented Jun 19, 2017 at 6:09
  • @Val I am using elasticsearch-php version 2.0 Commented Jun 19, 2017 at 7:03
  • There you go, you need to use version 5 and you'll be good. Commented Jun 19, 2017 at 7:12
  • @Val ... thank you ... how can I use this in version 2.0? Commented Jun 19, 2017 at 7:26
  • See this answer: stackoverflow.com/questions/37382980/… you need version 2.4 at least Commented Jun 19, 2017 at 7:28

2 Answers 2

6

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]
            ]
        ]
    ]
]);
Sign up to request clarification or add additional context in comments.

1 Comment

Without type is possible too (php 7.2 - ES 7.3) ['index' => 'test_index','body' => ['query' => ['match' => ['keyword' => '123456']]],];
2

this an old question, previous comments don't work anymore in 2020 :

$client->deleteByQuery([
    'index' => 'test_index',
   (there were a type here)  'type' => 'test_info',
    'body' => [
        'query' => [
            'match' => [
                (there were an array here) ['category_id' => 21]
            ]
        ]
    ]
]);

So the final code is :

$client->deleteByQuery([
    'index' => 'test_index',
    'body' => [
        'query' => [
            'match' => [
               'category_id' => 21
            ]
        ]
    ]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.