Elasticsearch 2.3使用PHP LIbrary通过查询删除类型中的所有文档 [英] Elasticsearch 2.3 Delete all documents in a type by query using PHP LIbrary

查看:263
本文介绍了Elasticsearch 2.3使用PHP LIbrary通过查询删除类型中的所有文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过使用elasticsearch php库查询来删除文档。我实际上最好要删除我的类型中的所有文档。
我可以使用正常的卷曲XDELETE请求来实现这一点,但是我无法使用弹性搜索的PHP库来使用它。



是的,我已经安装 delete-by-query plugin,因此原始请求的工作原理。



我当前的代码:

  $ params = [
'index'=> 'pharmaceutical_lists',
'type'=> $ listName,
'body'=> [
'query'=> [
'match_all'=> []
]
]
];
return $ this-> delete($ params);

结果


Client.php行1440中的InvalidArgumentException:
id不能为空。


从我的错误消息(ID不能为null)它看起来通过查询删除可能是php库的限制只允许通过id删除。



如果我在应用程序中执行此功能的原始HTTP请求,那么当php库对应用程序中的其他查询非常有用时,会有点烦人。



问题摘要



是否有解决方法可以使用弹性搜索php库没有触摸图书馆代码?



不用说,但感谢任何人随时查看和帮助我的问题。干杯。



修改



elasticsearch php库版本 v2.1.5

解决方案

您需要使用 deleteByQuery() function ,如下所示:

  $ params = [
'index'=> 'pharmaceutical_lists',
'type'=> $ listName,
'body'=> [
'query'=> [
'match_all'=> []
]
]
];
return $ this-> deleteByQuery($ params);

如果你想看看源代码可用 here


I want to be able to delete documents by query using the elasticsearch php library. I actually ideally want to delete all documents in my type. I can achieve this using a normal curl XDELETE request in sense, however I cant get it to work using elastic search's PHP library.

Yes I have installed the delete-by-query plugin hence why raw request works.

my current code:

$params = [
    'index' => 'sanctions_lists',
    'type' => $listName,
    'body' => [
        'query' => [
            'match_all' => []
        ]
    ]
];
return $this->delete($params);

results in

InvalidArgumentException in Client.php line 1440: id cannot be null.

From my error message (ID cannot be null) it appears delete by query could be a limitation of the php library Only allowing deletes by id.

Would be a bit annoying if I have to execute raw HTTP request for this function inside my app when the php library has been really good for my other queries in the app.

Question Summary

Is there a workaround to delete by query using the elasticsearch php library without touching library code?

Goes without saying but thanks to anyone who takes any time to view and help with my question. Cheers.

Edit

Incase it helps im using:

elasticsearch php library version v2.1.5

解决方案

You need to use the deleteByQuery() function, like this:

$params = [
    'index' => 'sanctions_lists',
    'type' => $listName,
    'body' => [
        'query' => [
            'match_all' => []
        ]
    ]
];
return $this->deleteByQuery($params);

If you want to have a look the source code is available here

这篇关于Elasticsearch 2.3使用PHP LIbrary通过查询删除类型中的所有文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆