-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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] Composable index template mapping can prevent creating an index if mappings conflict #16340
Comments
To be honest, I think the existing behavior makes sense. You apply a template as a rule to be followed with indices to be matched, and it follows as directed to. Now to get to the point how to obtain the desired behavior. I think there is a work-around which makes sense. (There may be better ways to do it which I'm not aware). So basically let's say you want to create a different rule for your system indices. So,
(this succeeds) |
It's an overridable rule. You can (and the documentation says as much) override any template field mapping; the templates are just defaults. But there are some mappings that you can't override, and that's not documented and not obvious to users, and the error message when it doesn't work is unhelpful. It took 2 weeks and 5 devs finding this error "in the wild" to dig deep enough to figure out this undocumented behavior.
Yes, I described the workaround with a higher-priority template. You don't even need the complexity of a new composable template, just one with empty mappings: PUT _index_template/temporary_high_priority
{
"index_patterns": [
".*"
],
"template": {
"mappings": {}
},
"priority": 1000000
} This works fine for "fixing" a plugin, but in order to use this workaround for a plugin that wants to, on initialization, consistently and reliably create a system index with known mappings, you would have to:
And that assumes the node is started up. Some plugins create indices on startup and could kill the node before it even gets that far: opensearch-project/observability#1872 Compare that to alternative solutions like:
If we're not going to allow full override behavior I'd prefer one of the above solutions, to give plugins (or ideally any index creator) the power to completely override a template. Requiring plugins to go through the "check all the templates to make sure you're not going to be stepped on" shenanigans is not scalable. |
System index shouldn't follow the index template created by user for their business purpose. I vote for filtering out the system index creation from index template. |
@zane-neo Thanks for this suggestion. I generally agree. Follow-up question: is there a specific definition of "system index" that we can use for this filtering? Is it as simple as a leading dot, or does it need to be "registered"? (CC: @cwperks for comment here) |
@dbwiddis Conventionally they all begin with dot, but formally they must be registered with SystemIndexPlugin.getSystemIndexDescriptors. The registry is formed here. |
Now to just figure out where to fetch that object when matching indices with a template... |
And one clarification for my comment above. The system index registration supports "patterns". When a concrete index is made that matches the pattern, it is considered a system index. For instance if the alerting plugin registers System indices may also be auto created. If you ingest a document and it doesn't exist, it gets automatically created. See test for details. |
Looks like OpenSearch/server/src/main/java/org/opensearch/cluster/metadata/MetadataCreateIndexService.java Line 276 in 456ca97
We also already give special treatment to hidden indices here: OpenSearch/server/src/main/java/org/opensearch/cluster/metadata/MetadataCreateIndexService.java Lines 437 to 451 in 456ca97
So we probably just need to alter the logic here and below to set null for v2 template and an empty list for v1 template. |
Describe the bug
In the index templates documentation for Composable index templates, it states:
This documentation is not accurate.
Specifically, overriding is not possible if the conflicting type can't be merged (e.g., between object and nested, field and object, etc.). Overriding only occurs on "leaf" components. (See ab65a57)
Worse, this mapping conflict prevents index creation, including system indices.
A user could accidentally add a wrong mapping and potentially prevent a node from even starting up: opensearch-project/observability#1872
Related component
Indexing
To Reproduce
Expected behavior
The mapping specified in the create index API call overrides the template mapping, and the index is actually created.
Additional Details
Plugins
N/A. Reproduced on a local cluster using HEAD of 2.x branch, using
./gradlew clean run
.However, this is a significant issue for any plugin that uses a system index. It's a critical issue for plugins that prevent a node from starting up if the system index is not created.
Host/Environment (please complete the following information):
Reproducable locally on macOS; occurred on a production cluster on AOS, OpenSearch version 2.15
Additional context
This is significant in that:
In this case, to work around the bug I had to create a (temporary) higher priority matching template with an empty object in the
mapping
field to prevent the incompatible mapping.Stack trace leading to the error:
The text was updated successfully, but these errors were encountered: