NodeJs-ElasticSearch Bulk API 错误处理 [英] NodeJs-ElasticSearch Bulk API error handling

查看:49
本文介绍了NodeJs-ElasticSearch Bulk API 错误处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我找不到关于 Elastic Bulk API 在一项或多项操作中失败时会发生什么情况的任何文档.例如,对于以下请求,假设已经有一个 ID 为3"的文档,因此创建"应该失败-这是否会使所有其他操作失败?

I can't find any documentation on what happens if Elastic Bulk API fails on one or more of the actions. For example, for the following request, let's say there is already a document with id "3", so "create" should fail- does this fail all of the other actions?

{ "index" : { "_index" : "test", "_type" : "type1", "_id" : "1" } }
{ "field1" : "value1" }
{ "delete" : { "_index" : "test", "_type" : "type1", "_id" : "2" } }
{ "create" : { "_index" : "test", "_type" : "type1", "_id" : "3" } }
{ "field1" : "value3" }
{ "update" : {"_id" : "1", "_type" : "type1", "_index" : "index1"} }
{ "doc" : {"field2" : "value2"} }

  • 我正在使用 nodejs 弹性模块.
  • 推荐答案

    一个动作的失败不会影响其他动作.

    No failures in one action does not affect the others .

    来自 elasticsearch 批量的文档接口:

    From the documentation of elasticsearch bulk api :

    对批量操作的响应是一个大型 JSON 结构,带有执行的每个操作的单独结果.一个失败单个动作不影响其余动作.

    The response to a bulk action is a large JSON structure with the individual results of each action that was performed. The failure of a single action does not affect the remaining actions.

    在elasticsearch客户端的响应中,有status对应每个动作的响应来判断是否失败

    In the response from elasticsearch client there is status in response corresponding to each action to determine if it was a failure or not

    示例:

        client.bulk({
          body: [
            // action description
            { index:  { _index: 'test', _type: 'test', _id: 1 } },
             // the document to index
            { title: 'foo' },
            // action description
            { update: { _index: 'test', _type: 'test', _id: 332 } },
            // the document to update
            { doc: { title: 'foo' } },
            // action description
            { delete: { _index: 'test', _type: 'test', _id: 33 } },
            // no document needed for this delete
          ]
        }, function (err, resp) {
            if(resp.errors) {
               console.log(JSON.stringify(resp, null, '	'));
            }
        });
    

    回复:

        {
            "took": 13,
            "errors": true,
            "items": [
                    {
                            "index": {
                                    "_index": "test",
                                    "_type": "test",
                                    "_id": "1",
                                    "_version": 20,
                                    "_shards": {
                                            "total": 2,
                                            "successful": 1,
                                            "failed": 0
                                    },
                                    "status": 200
                            }
                    },
                    {
                            "update": {
                                    "_index": "test",
                                    "_type": "test",
                                    "_id": "332",
                                    "status": 404,
                                    "error": {
                                            "type": "document_missing_exception",
                                            "reason": "[test][332]: document missing",
                                            "shard": "-1",
                                            "index": "test"
                                    }
                            }
                    },
                    {
                            "delete": {
                                    "_index": "test",
                                    "_type": "test",
                                    "_id": "33",
                                    "_version": 2,
                                    "_shards": {
                                            "total": 2,
                                            "successful": 1,
                                            "failed": 0
                                    },
                                    "status": 404,
                                    "found": false
                            }
                    }
            ]
    }
    

    这篇关于NodeJs-ElasticSearch Bulk API 错误处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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