-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Support for adding an item to an array/collection field in a document #16917
Comments
Have you tried using painless script to append value to an array? It can be achieved by something like this:
|
Thanks for the input. Well I can try but it is mentioned in the documentation that painless script translates to a bit of additional overhead as it involves script compilation. Is my understanding correct? |
Would it scale if we use script in "_bulk" with large number of updates? |
Yes, painless script introduces some overhead because of the complication and has performance issue, but there're multiple methods to reduce the compilation times and improve the performance, such as:
There're some dynamic settings for the script, such as |
If I use below scripts, four scripts can be stored upfront and I can use them generically across all indices. If we go this route, I believe max_compilations_rate may not be of concern. Is my understanding correct?
|
Yes, the stored script is cached and won't be compiled every time when using. |
Thank you, it looks promising for our use-case. Do you have any other recommendations to keep in mind? |
Feature
Proposal for adding support for updating array fields by appending a new item without requiring a document read, update the field in memory and write back to OpenSearch. Provide a similar capability to append values to an array field in a document without retrieving and re-indexing the entire document.
Example (Inspired by MongoDB):
Insert Document:
Append to Array Field:
Background and Context
Our product uses OpenSearch primarily for the following purposes:
To ensure efficient filtering and search, we intentionally denormalize data (which is a recommended practice). Below are some examples to explain the design.
Example 1: Certification and Course Search
Below document contains course and skill names to support denormalized search across related entities.
Example 2: User Enrollment Search
To list courses or certifications where a user is enrolled, we search in the course index and filter based on the user’s enrolled_courses field by doing an index lookup.
Problem Statement
In our product, frequent updates to user and learning object documents are required. Currently, updates involve the following steps:
Challenges with Current Approach:
Proposed Solution
We propose introducing a feature to directly append values to array fields without fetching and reindexing the entire document.
Benefits
API Suggestion
Similar to MongoDB’s $push operator, OpenSearch can introduce an operation like:
Inserts
Deletions
This uses an inline script to append values to an array field (enrolled_courses).
Business Impact
Conclusion
We believe that adding native support for array field updates will significantly improve performance and simplify application logic, not just for our use case but also for other OpenSearch users dealing with denormalized data models.
We are happy to provide more details or collaborate with the OpenSearch team on refining this proposal further.
Thank you for considering this request.
Related component
Indexing
Describe alternatives you've considered
No response
Additional context
While inspecting the opensearch audit logs, we could see logs like below that sort of indicate that this support might be already existing internally
No response
The text was updated successfully, but these errors were encountered: