Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bulk actions for Index and Update: index or update with doc_as_upsert? #731

Closed
loretoparisi opened this issue Nov 19, 2018 · 3 comments
Closed

Comments

@loretoparisi
Copy link

loretoparisi commented Nov 19, 2018

I'm doing a index / update bulk call using the client.bulk api:

When I do the insert action

{
                index: 'myIndex',
                type: '_doc',
                body: [
                    // action description
                    { index: { _id: docIDOne } },
                    // the document to index
                    itemOne,
                    // action description
                    { index: { _id: docIDTwo } },
                    // the document to index
                    itemTwo,
                ]
            }

The index action works ok. At second attempt of the index action with the same items it works as well and I get a updated value for the result field in the response:

{
      "index": {
        "_index": "entities",
        "_type": "_doc",
        "_id": "TGVCcm9u",
        "_version": 4,
        "result": "updated",
        "_shards": {
          "total": 2,
          "successful": 2,
          "failed": 0
        },
        "_seq_no": 5,
        "_primary_term": 1,
        "status": 200
      }

Does this mean that that doc has been updated?
I have tried also to use the update action with the doc_as_upsert flag like:

elastic.bulk({
                index: indexName,
                type: '_doc',
                body: [
                    // action description
                    { update: { _id: docIDOne } },
                    // the document to index
                    { doc_as_upsert : true, doc: itemOne },
                    // action description
                    { update: { _id: docIDTwo } },
                    // the document to index
                    { doc_as_upsert : true, doc: 
 },
                ]
            });

and it gives me back a created result the first attempt, and a noop the second one. I suppose I will get a updated if it updates the content.

So the point is: which api call shall I use to perform something closer to a insert OR update: index or update with the doc_as_upsert flag?

@delvedor
Copy link
Member

You should use update with doc_as_upsert :)

This issue tracker should be used only for questions or issues related to the JavaScript client. If you have other general questions about Elastic I suggest you use our fantastic forum, where your question will probably help others as well :)

https://discuss.elastic.co/

@loretoparisi
Copy link
Author

@delvedor thank you, I was not sure that the JavaScript API was supporting it, since in the docs there is not reference to it, I mean here.

@delvedor
Copy link
Member

It's not documented because only querystring parameters are documented, all supported body keys are described in https://www.elastic.co/guide/en/elasticsearch/reference/6.5/docs-update.html (you can arrive at that URL from the js docs in the body section) ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants