opensearch-project / opensearch-js

Node.js Client for OpenSearch
https://opensearch.org/docs/latest/clients/javascript/
Apache License 2.0
188 stars 122 forks source link

[BUG] Documentation shows onDocument can accept an array as a return but that throws an error #551

Open dtaivpp opened 1 year ago

dtaivpp commented 1 year ago

What is the bug?

Hey all, when attempting to use this code it tells me that an array is an invalid return type. Is this an issue with the JS library or with the documentation?

https://github.com/opensearch-project/documentation-website/blob/02f40d7efd4265e85c128d0a85a65c668c016b97/_clients/javascript/helpers.md?plain=1#L96C8-L102

How can one reproduce the bug?

let result = await os_client.helpers.bulk({
    datasource: [{ body: "this is my text", id: 1234}],
    onDocument (doc) {
      return [
      {
          index: { _index: index_name , _id: doc.id }
       }, 
       {...doc, body: "instead have this body"}
     ]
    }

What is the expected behavior?

I would expect this to modify the body of the document and add it as a bulk action.

What is your host/environment?

MacOS

Do you have any screenshots?

Screenshot 2023-07-12 at 3 57 35 PM

Do you have any additional context?

Add any other context about the problem.

nhtruong commented 1 year ago

I can't recreate your error. What version of the client are you using? Does the trace log point out where the error occurs?