ElasticSearch通过查询删除不适用于PHP

Sij*_*iji 1 php elasticsearch

我正在使用Elastic search 5.x,以下代码可以正常工作:

curl -XPOST "http://localhost:9200/test_index/test_info/_delete_by_query" -d'
{
  "query": {
    "match": {
        "category_id": "21"
    }
  }
}'
Run Code Online (Sandbox Code Playgroud)

但是,当我在php代码中尝试相同操作时,它不起作用:

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

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

        ]       
    ]
Run Code Online (Sandbox Code Playgroud)

]);

小智 5

您需要在参数query数组内部提供数组body

$client->deleteByQuery([
    'index' => 'test_index',
    'type' => 'test_info',
    'body' => [
        'query' => [
            'match' => [
                ['category_id' => 21]
            ]
        ]
    ]
]);
Run Code Online (Sandbox Code Playgroud)