'id不能为null'。尝试从ElasticSearch中删除时出错 [英] 'id cannot be null.' error when trying to delete from ElasticSearch

查看:395
本文介绍了'id不能为null'。尝试从ElasticSearch中删除时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 Windows 机器, ElasticSearch 5.0.0 和标准的 PHP 客户端为 ElasticSearch ,我使用作曲家安装。一切正常,除了删除操作。我无法通过查询删除,因此得到此错误消息:

I have Windows machine, ElasticSearch 5.0.0 and a standard PHP client for ElasticSearch, that I installed using composer. Everything works ok, except delete operation. I can not delete by query and as a result get this error message:


未捕获的异常
'Elasticsearch\Common\异常\InvalidArgumentException'与
消息'id不能为空。'

Uncaught exception 'Elasticsearch\Common\Exceptions\InvalidArgumentException' with message 'id cannot be null.'

这是我如何尝试删除: / p>

This is how I try to delete:

$client = ClientBuilder::create()->build();
$params = [
    'index' => 'layers'
    'type' => 'layers_type'
    'body' => [
        'bool' => [
            'should' => [
                [
                    'multi_match' => [
                        'query' => ["304"],
                        'fields' => ["id"] // not a surrogate _id, by my own id, that is a part of my index properties
                    ]
                ]
            ]
        ]
    ]
];
$client->delete($params);

那么我该怎么解决呢?我需要安装任何插件,如果是的话,我该如何在Windows机器上执行?

So, how can I fix it? Do I need to install any plugin and if yes, how can I do that on my Windows machine?

推荐答案

删除 function 需要一个id,因为它是为了删除单个文档,这就是为什么你得到这个错误。

The delete function requires an id since it is meant to delete a single document, that's the reason why you get that error.

为了做你想要的,你需要 deleteByQuery 函数,而它已经在2.x中被删除,而不是添加回来(还)。

In order to do what you want, you need the deleteByQuery function instead, but it has been removed in 2.x and not added back (yet).

您可以使用 Elastica PHP客户端同时。符合5.0,支持deleteByQuery功能

You can use the Elastica PHP client in the meantime. It is 5.0 compliant and supports the deleteByQuery feature.

这篇关于'id不能为null'。尝试从ElasticSearch中删除时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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