Elasticsearch 2.3 使用PHP LIbrary 通过查询删除类型中的所有文档
Elasticsearch 2.3 Delete all documents in a type by query using PHP LIbrary
我希望能够使用 elasticsearch php 库通过查询删除文档。实际上,理想情况下,我想删除我的类型中的所有文档。
从某种意义上说,我可以使用普通的 curl XDELETE 请求来实现这一点,但是我无法使用弹性搜索的 PHP 库来实现它。
是的,我已经安装了 delete-by-query
插件,因此原始请求有效。
我当前的代码:
$params = [
'index' => 'sanctions_lists',
'type' => $listName,
'body' => [
'query' => [
'match_all' => []
]
]
];
return $this->delete($params);
结果
InvalidArgumentException in Client.php line 1440:
id cannot be null.
从我的错误消息(ID 不能为空)看来,按查询删除可能是 php 库的限制,只允许按 ID 删除。
当 php 库非常适合我在应用程序中的其他查询时,如果我必须在我的应用程序中为此功能执行原始 HTTP 请求,那会有点烦人。
问题总结
是否有使用 elasticsearch php 库通过查询删除而不触及库代码的解决方法?
不言而喻,但感谢任何花时间查看和帮助解决我的问题的人。干杯。
编辑
Incase it helps im using:
elasticsearch php 库版本 v2.1.5
您需要使用 deleteByQuery()
function,像这样:
$params = [
'index' => 'sanctions_lists',
'type' => $listName,
'body' => [
'query' => [
'match_all' => []
]
]
];
return $this->deleteByQuery($params);
如果你想看一下源代码here
$params = [
"index" => "my_index",
"type" => "my_type",
"body" => [
"query" => [
"match_all" => (object)[]
]
]
];
$client->deleteByQuery($params);
根据 answer, U may experience error, so note "match_all" => (object)[] retyping. I found that here
我希望能够使用 elasticsearch php 库通过查询删除文档。实际上,理想情况下,我想删除我的类型中的所有文档。 从某种意义上说,我可以使用普通的 curl XDELETE 请求来实现这一点,但是我无法使用弹性搜索的 PHP 库来实现它。
是的,我已经安装了 delete-by-query
插件,因此原始请求有效。
我当前的代码:
$params = [
'index' => 'sanctions_lists',
'type' => $listName,
'body' => [
'query' => [
'match_all' => []
]
]
];
return $this->delete($params);
结果
InvalidArgumentException in Client.php line 1440: id cannot be null.
从我的错误消息(ID 不能为空)看来,按查询删除可能是 php 库的限制,只允许按 ID 删除。
当 php 库非常适合我在应用程序中的其他查询时,如果我必须在我的应用程序中为此功能执行原始 HTTP 请求,那会有点烦人。
问题总结
是否有使用 elasticsearch php 库通过查询删除而不触及库代码的解决方法?
不言而喻,但感谢任何花时间查看和帮助解决我的问题的人。干杯。
编辑
Incase it helps im using:
elasticsearch php 库版本 v2.1.5
您需要使用 deleteByQuery()
function,像这样:
$params = [
'index' => 'sanctions_lists',
'type' => $listName,
'body' => [
'query' => [
'match_all' => []
]
]
];
return $this->deleteByQuery($params);
如果你想看一下源代码here
$params = [
"index" => "my_index",
"type" => "my_type",
"body" => [
"query" => [
"match_all" => (object)[]
]
]
];
$client->deleteByQuery($params);
根据