Skip to content

Fix detector creation with aliases and data streams - #1792

Open
NelTdS wants to merge 1 commit into
opensearch-project:mainfrom
NelTdS:fix/detector-creation-index-patterns
Open

Fix detector creation with aliases and data streams#1792
NelTdS wants to merge 1 commit into
opensearch-project:mainfrom
NelTdS:fix/detector-creation-index-patterns

Conversation

@NelTdS

@NelTdS NelTdS commented Aug 17, 2026

Copy link
Copy Markdown

Description

Fixes several bugs that prevented detector creation when the configured index is an index pattern, alias, or data stream.

Six root causes addressed:

  1. GetIndexMappingsRequest null index (TransportIndexDetectorAction): IndexUtils.getNewIndexByCreationDate() returns null when no concrete index matches the pattern. The null was passed directly to GetIndexMappingsRequest, triggering Validation Failed: 1: index_name is missing. Fix: resolve pattern to concrete index first; fall back to the original name when resolution returns null.
  2. Strict index existence check (TransportIndexDetectorAction): The pre-creation SearchRequest used default strict IndicesOptions, producing Indices not found for patterns with no current backing indices. Fix: use IndicesOptions.LENIENT_EXPAND_OPEN.
  3. GetMappingsRequest strict resolution (MapperService): Three GetMappingsRequest calls used default options, causing OpenSearch to search for a template named -template when the pattern had no backing index, producing a misleading 404. Fix: add LENIENT_EXPAND_OPEN to all three calls.
  4. GetIndexRequest strict resolution (MapperService): resolveConcreteIndex() used a strict GetIndexRequest, failing with no such index for patterns with no current backing index. Fix: use LENIENT_EXPAND_OPEN; return the original name on empty result.
  5. NoSuchElementException on empty mappings (MapperService): doGetMappingAction and doGetMappingsView called .iterator().next() on the mappings map without an emptiness check. A data stream with no mappings returned an empty map, causing an uncaught exception. Fix: guard both call sites; return an empty response instead.
  6. Race condition on concurrent detector creation (TransportIndexDetectorAction): When multiple detectors are created in parallel, all requests read cluster state simultaneously, see the detectors index absent, and all issue CreateIndexRequest. The first succeeds; the remaining requests received ResourceAlreadyExistsException and failed fatally. Fix: catch ResourceAlreadyExistsException in the onFailure handler of initDetectorIndex and treat it as success.

Related Issues

None

Check List

  • New functionality includes testing.
  • New functionality has been documented.
  • API changes companion pull request created.
  • Commits are signed per the DCO using --signoff.
  • Public documentation issue/PR created.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Signed-off-by: Nelson Tavares de Sousa <github@neltds.de>
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

Successfully merging this pull request may close these issues.

1 participant