-
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
[BUG in multiple plugins] Using CreateIndexRequest.mapping() without _doc wrapper fails with v1 index templates #14984
Comments
Additional information for other plugins on seeing if you are impacted:
Based on my review of the above search link:
My review may be incomplete, other plugin owners should confirm. |
@dbwiddis How about we make this a meta issue and open child issues (you can use https://github.com/opensearch-project/project-meta) that use this one as a parent to track all the instances? We can also move this one to https://github.com/opensearch-project/opensearch-plugins. |
[Triage] For the job-scheduler
The other mapping opensearch_job_scheduler_job_details.json is used with the extension project which is not being used at the moment. Adding @cwperks @joshpalis @dbwiddis @getsaurabh02 |
@prudhvigodithi for JS I see in CreateIndexRequest mapping beings passed as String here and here. All we have to do is to change to final CreateIndexRequest request = new CreateIndexRequest(LOCK_INDEX_NAME).mapping(lockMapping(), XContentType.JSON); CreateIndexRequest request = new CreateIndexRequest(JOB_DETAILS_INDEX_NAME).mapping(jobDetailsMapping(), XContentType.JSON); |
Thanks @owaiskazi19 we can add |
Mappings won't be created dynamic from the json. It would be if a user initialized the index with v1 index templates. |
I am little confused due to my lack of knowledge on templates. Apologies if my question is naive but I ddint understand this I am trying to understand why would system indices created by plugin and not discoverable by user be affected by user's v1 templates? |
Try deleting that index and adding the template in step 1 of the original issue and then recreating a job. |
Because the specific In many of the links above to specific plugins you can use git blame to go back and find the PR that removed the second The presence of a v1 template which matches the system index will cause the code to follow a path which loses the user-specified mapping. In particular, v2 mappings process in a list and there is code to add the missing It's a rare edge case:
|
@dbwiddis In your description you mentioned that mappings from v1 template won't get applied only if following two conditions are met:
My question to you is if both conditions are required for the occurrence of this issue then how come plugins you mentioned are impacted currently? For e.g., in ISM I don't think there is any template created first to create the ISM system indices. I will let @bowenlan-amzn further confirm this. Are you suggesting that this can happen in future if we start using templates for the creation of system indices? |
One scenario I can think of where this issue can occur today is where there's a template present which unintentionally resolves to system indices used by plugins and then a new system index is created. |
In the specific examples, we discovered this when people were activating an agent using ML Commons Agent Framework, using a Flow Framework template. In both cases they had used neither plugin before, so the indices did not previously exist.
I am not an expert in any other plugin which is why I did my best to describe the specific conditions required. As an older plugin, users who have upgraded from ES7.7 to the present likely already have the ISM indices created before the bug was introduced (a lot of refactoring was done prior to 2.x to remove typed mappings which introduced this bug).
That is exactly the scenario we are facing. It seems that ES 7.7 and previous used these templates for defaults such as numbers of shards, etc. |
Describe the bug
** NOTE: This is not a bug in OpenSearch. **
This is existing behavior with legacy/deprecated code, with a Javadoc instructing what to do that many plugins have ignored by copying each other's code. I'm posting here for visibility to as many plugin maintainers as can see it and add the appropriate fix.
The bug (in at least 7 plugins that I've seen with a brief search):
Using
new CreateIndexRequest(indexName).mapping(mapping)
with a JSON string that does not wrap the mapping in a_doc
field as specified in the Javadocs, fails to apply if a v1 Index Template (/_template
API, deprecated) is present which matches that index. This causes the index to use dynamic mapping which can cause follow-on failures such asIllegalArgumentException[mapper [master_key] cannot be changed from type [text] to [keyword]]
.Related component
Plugins
To Reproduce
(Note: this is roughly what a "default" template in pre-7.8 ES actually contained and may still exist in clusters built then and later upgraded.)
CreateIndexRequest
with this mapping:Expected behavior
The index should be created with the user-specified mapping.
Additional Details
Plugins
I found thus bug in
flow-framework
andml-commons
plugins while debugging. It looks like it also exists in, as a minimum,index-management
,alerting
,k-nn
,security-analytics
,job-scheduler
, and potentially more that I have not verifiedAdditional context
The Javadoc for
CreateIndexRequest
clearly states that a_doc
field wrapper is required:OpenSearch/server/src/main/java/org/opensearch/action/admin/indices/create/CreateIndexRequest.java
Lines 246 to 257 in 157d277
When a v1 template matching the index is present, the code path followed requires this
_doc
field.V1 templates were deprecated in ElasticSearch 7.8.0, so may not be familiar to OpenSearch users, or in common use. However, for users who have regularly upgraded, they may still have some of these existing templates and as the repro case shows, they can still create them even if they're not documented except in legacy documentation/tutorials/examples.
The text was updated successfully, but these errors were encountered: