Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

node.js - NodeJs-ElasticSearch Bulk API error handling

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"} }
  • I'm using nodejs elastic module.
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

No failures in one action does not affect the others .

From the documentation of elasticsearch bulk api :

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.

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

Example:

    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, ''));
        }
    });

Response:

    {
        "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
                        }
                }
        ]
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...