Skip to content

Conversation

idegtiarenko
Copy link
Contributor

Today we parse original index pattern into EsqlExecutionInfo#clusterInfo and then assemble it back createIndexExpressionFromAvailableClusters.

In CPS with flat expressions resolution logic is more complex and should be delegated to field caps call using original expression.

@idegtiarenko idegtiarenko added >non-issue Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) :Analytics/ES|QL AKA ESQL v9.2.0 labels Sep 5, 2025
String q = "FROM nomatch*,cluster-a:nomatch";
String expectedError = "Unknown index [cluster-a:nomatch,nomatch*]";
String expectedError = "Unknown index [nomatch*,cluster-a:nomatch]";
expectVerificationExceptionForQuery(q, expectedError, requestIncludeMeta);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here and in 3 below cases the error message index now matches the original input (notice that the order was different).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this ordering stable - i.e. is it going to always match original order, no matter how many patterns and clusters we have?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct, error uses indexPattern. We are supplying original user input into it now.

assertThat(e.getMessage(), containsString(LICENSE_ERROR_MESSAGE));
}

@AwaitsFix(bugUrl = "es-12487")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is an interesting issue.
This test verifies index resolution with something like FROM fake-remote:events.

Field caps relies on returnLocalAll = true at

final Map<String, OriginalIndices> remoteClusterIndices = transportService.getRemoteClusterService()
.groupIndices(request.indicesOptions(), request.indices());

that causes it to return all indices from local clusters when all remotes are not found.

There are existing issues about it: #115262 and #115872

Today this flag is not exposed via FieldCapabilitiesRequest so I am not sure how this could be fixed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Depends on #134284

VerificationException.class,
containsString("Unknown index [xremote*:events]"),
() -> runQuery("FROM xremote*:events | STATS count(*)", requestIncludeMeta).close()
);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prior behavior returned empty result for empty index resolution.
Now this is complaining about empty index resolution (consistent with FROM empty-pattern-* case)

assertEquals(400, e.getResponse().getStatusLine().getStatusCode());
assertThat(e.getMessage(), containsString("verification_exception"));
assertThat(e.getMessage(), anyOf(containsString("Unknown index [foo]"), containsString("Unknown index [remote_cluster:foo]")));
assertThat(e.getMessage(), anyOf(containsString("Unknown index [foo]"), containsString("Unknown index [*:foo]")));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We randomly query foo or *:foo. Prior message was actually resolving * to all known remotes. I do not think this is desired behavior.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, we need to keep old resolved remote_cluster:foo in case old cluster is coordinating the query.
I will check if we can make this check version dependent.

);
Set<String> expectedUnknownIndexes = org.elasticsearch.common.Strings.commaDelimitedListToSet(expectedIndexExpressionInError);
assertThat(actualUnknownIndexes, equalTo(expectedUnknownIndexes));
assertThat(error.getMessage(), containsString("Unknown index [" + index + "]"));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Match original query pattern, not semi resolved pattern

@idegtiarenko idegtiarenko marked this pull request as ready for review September 24, 2025 14:10
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-analytical-engine (Team:Analytics)

# Conflicts:
#	x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/analysis/PreAnalyzer.java
if (preAnalysis.indexPattern() != null) {
String indexExpressionToResolve = EsqlCCSUtils.createIndexExpressionFromAvailableClusters(executionInfo);
if (indexExpressionToResolve.isEmpty()) {
if (executionInfo.clusterAliases().isEmpty()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we're back to the same question of whether this is right or not when we call it the second time. Is this intentional to have it here, or it's just sneaked in from merging the previous patch?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Related to #135353 (comment)

OK, I see! But we are calling preAnalyzeMainIndices twice - once at the beginning (now) and once if the filtered analysis fails. Is that also true for the second invocation? In any case, I'd add a comment to it - with this change, the existing comment is no longer true, and would be just confusing.

There are several aspects to this question:

  • today this behaves different from local only resolution: local does not allow empty resolution. We would like to change it to alight with DSL behavior. Once that is done this check should actually go away.
  • with respect for retrying analysis without filter: this would retry the same expression (even if some clusters should be skipped resulting in duplicated connection errors). I feel like this falls into ES-12978 issue category. With flat expression it is very tricky to manipulate input to exclude those clusters. Since we are going to be restarting analysis from scratch I would rather clear errors and start analysis fresh with no filter.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All considered, IMHO this seems reasonable.

I feel like this falls into ES-12978

ES-12978 is for CPS, but I guess we have the same problem with CCS now.
My assumption is that we'll address this problem before 9.3 FF.

Since we are going to be restarting analysis from scratch I would rather clear errors and start analysis fresh

++

@idegtiarenko idegtiarenko requested a review from smalyshev October 1, 2025 13:31
Copy link
Contributor

@luigidellaquila luigidellaquila left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is good, as long as we agree on the point raised by Stas (ie. ES-12978)

if (preAnalysis.indexPattern() != null) {
String indexExpressionToResolve = EsqlCCSUtils.createIndexExpressionFromAvailableClusters(executionInfo);
if (indexExpressionToResolve.isEmpty()) {
if (executionInfo.clusterAliases().isEmpty()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All considered, IMHO this seems reasonable.

I feel like this falls into ES-12978

ES-12978 is for CPS, but I guess we have the same problem with CCS now.
My assumption is that we'll address this problem before 9.3 FF.

Since we are going to be restarting analysis from scratch I would rather clear errors and start analysis fresh

++

@idegtiarenko
Copy link
Contributor Author

Replaced with #136009

@idegtiarenko idegtiarenko deleted the es-12487 branch October 7, 2025 06:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Analytics/ES|QL AKA ESQL >non-issue Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) v9.3.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants