Skip to content

Commit 5529733

Browse files
authored
Merge branch 'main' into 2025/10/24/new-id-format
2 parents 546e23b + 6f90938 commit 5529733

File tree

6 files changed

+75
-37
lines changed

6 files changed

+75
-37
lines changed

docs/changelog/137536.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 137536
2+
summary: Use DV rewrites where possible in Keyword queries
3+
area: Search
4+
type: enhancement
5+
issues: []

muted-tests.yml

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -426,27 +426,12 @@ tests:
426426
- class: org.elasticsearch.xpack.ml.integration.BasicDistributedJobsIT
427427
method: testFailOverBasics
428428
issue: https://github.com/elastic/elasticsearch/issues/136778
429-
- class: org.elasticsearch.xpack.inference.qa.mixed.CohereServiceMixedIT
430-
method: testRerank
431-
issue: https://github.com/elastic/elasticsearch/issues/136872
432-
- class: org.elasticsearch.xpack.inference.qa.mixed.CohereServiceMixedIT
433-
method: testCohereEmbeddings
434-
issue: https://github.com/elastic/elasticsearch/issues/136779
435429
- class: org.elasticsearch.xpack.search.CrossClusterAsyncSearchIT
436430
method: testRemoteClusterOnlyCCSWithFailuresOnAllShards
437431
issue: https://github.com/elastic/elasticsearch/issues/136894
438-
- class: org.elasticsearch.xpack.esql.qa.mixed.FieldExtractorIT
439-
method: testTextFieldWithIpSubfieldMalformed {STORED}
440-
issue: https://github.com/elastic/elasticsearch/issues/136917
441-
- class: org.elasticsearch.xpack.esql.qa.mixed.FieldExtractorIT
442-
method: testTextFieldWithKeywordSubfield {STORED}
443-
issue: https://github.com/elastic/elasticsearch/issues/136918
444432
- class: org.elasticsearch.xpack.esql.optimizer.rules.logical.HoistRemoteEnrichTopNTests
445433
method: testTopNSortExpressionWithinRemoteEnrichAliasing
446434
issue: https://github.com/elastic/elasticsearch/issues/136957
447-
- class: org.elasticsearch.xpack.esql.qa.mixed.FieldExtractorIT
448-
method: testByteFieldWithIntSubfieldTooBig {NONE}
449-
issue: https://github.com/elastic/elasticsearch/issues/137034
450435
- class: org.elasticsearch.xpack.esql.qa.single_node.GenerativeMetricsIT
451436
method: test
452437
issue: https://github.com/elastic/elasticsearch/issues/137071
@@ -481,6 +466,9 @@ tests:
481466
method: testSimilarityWithOneDimVector {functionName=v_cosine
482467
similarityFunction=org.elasticsearch.xpack.esql.expression.function.vector.CosineSimilarity$1@6f152006 elementType=byte}
483468
issue: https://github.com/elastic/elasticsearch/issues/137552
469+
- class: org.elasticsearch.xpack.ilm.CCRIndexLifecycleIT
470+
method: testTsdbLeaderIndexRolloverAndSyncAfterWaitUntilEndTime {targetCluster=FOLLOWER}
471+
issue: https://github.com/elastic/elasticsearch/issues/137565
484472

485473
# Examples:
486474
#

server/src/main/java/org/elasticsearch/index/mapper/KeywordFieldMapper.java

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,12 @@
2727
import org.apache.lucene.index.Term;
2828
import org.apache.lucene.index.Terms;
2929
import org.apache.lucene.index.TermsEnum;
30+
import org.apache.lucene.search.FuzzyQuery;
3031
import org.apache.lucene.search.MultiTermQuery;
32+
import org.apache.lucene.search.PrefixQuery;
3133
import org.apache.lucene.search.Query;
34+
import org.apache.lucene.search.RegexpQuery;
35+
import org.apache.lucene.search.WildcardQuery;
3236
import org.apache.lucene.util.BytesRef;
3337
import org.apache.lucene.util.automaton.Automata;
3438
import org.apache.lucene.util.automaton.Automaton;
@@ -67,9 +71,7 @@
6771
import org.elasticsearch.search.aggregations.support.CoreValuesSourceType;
6872
import org.elasticsearch.search.lookup.FieldValues;
6973
import org.elasticsearch.search.lookup.SearchLookup;
70-
import org.elasticsearch.search.runtime.StringScriptFieldFuzzyQuery;
7174
import org.elasticsearch.search.runtime.StringScriptFieldPrefixQuery;
72-
import org.elasticsearch.search.runtime.StringScriptFieldRegexpQuery;
7375
import org.elasticsearch.search.runtime.StringScriptFieldTermQuery;
7476
import org.elasticsearch.search.runtime.StringScriptFieldWildcardQuery;
7577
import org.elasticsearch.xcontent.Text;
@@ -720,14 +722,13 @@ public Query fuzzyQuery(
720722
if (indexType.hasTerms()) {
721723
return super.fuzzyQuery(value, fuzziness, prefixLength, maxExpansions, transpositions, context, rewriteMethod);
722724
} else {
723-
return StringScriptFieldFuzzyQuery.build(
724-
new Script(""),
725-
ctx -> new SortedSetDocValuesStringFieldScript(name(), context.lookup(), ctx),
726-
name(),
727-
indexedValueForSearch(value).utf8ToString(),
725+
return new FuzzyQuery(
726+
new Term(name(), indexedValueForSearch(value)),
728727
fuzziness.asDistance(BytesRefs.toString(value)),
729728
prefixLength,
730-
transpositions
729+
maxExpansions,
730+
transpositions,
731+
MultiTermQuery.DOC_VALUES_REWRITE
731732
);
732733
}
733734
}
@@ -743,6 +744,10 @@ public Query prefixQuery(
743744
if (indexType.hasTerms()) {
744745
return super.prefixQuery(value, method, caseInsensitive, context);
745746
} else {
747+
if (caseInsensitive == false) {
748+
Term prefix = new Term(name(), indexedValueForSearch(value));
749+
return new PrefixQuery(prefix, MultiTermQuery.DOC_VALUES_REWRITE);
750+
}
746751
return new StringScriptFieldPrefixQuery(
747752
new Script(""),
748753
ctx -> new SortedSetDocValuesStringFieldScript(name(), context.lookup(), ctx),
@@ -1017,6 +1022,10 @@ public Query wildcardQuery(
10171022
} else {
10181023
value = indexedValueForSearch(value).utf8ToString();
10191024
}
1025+
if (caseInsensitive == false) {
1026+
Term term = new Term(name(), value);
1027+
return new WildcardQuery(term, Operations.DEFAULT_DETERMINIZE_WORK_LIMIT, MultiTermQuery.DOC_VALUES_REWRITE);
1028+
}
10201029
return new StringScriptFieldWildcardQuery(
10211030
new Script(""),
10221031
ctx -> new SortedSetDocValuesStringFieldScript(name(), context.lookup(), ctx),
@@ -1038,13 +1047,8 @@ public Query normalizedWildcardQuery(String value, MultiTermQuery.RewriteMethod
10381047
} else {
10391048
value = indexedValueForSearch(value).utf8ToString();
10401049
}
1041-
return new StringScriptFieldWildcardQuery(
1042-
new Script(""),
1043-
ctx -> new SortedSetDocValuesStringFieldScript(name(), context.lookup(), ctx),
1044-
name(),
1045-
value,
1046-
false
1047-
);
1050+
Term term = new Term(name(), value);
1051+
return new WildcardQuery(term, Operations.DEFAULT_DETERMINIZE_WORK_LIMIT, MultiTermQuery.DOC_VALUES_REWRITE);
10481052
}
10491053
}
10501054

@@ -1064,14 +1068,13 @@ public Query regexpQuery(
10641068
if (matchFlags != 0) {
10651069
throw new IllegalArgumentException("Match flags not yet implemented [" + matchFlags + "]");
10661070
}
1067-
return new StringScriptFieldRegexpQuery(
1068-
new Script(""),
1069-
ctx -> new SortedSetDocValuesStringFieldScript(name(), context.lookup(), ctx),
1070-
name(),
1071-
indexedValueForSearch(value).utf8ToString(),
1071+
return new RegexpQuery(
1072+
new Term(name(), indexedValueForSearch(value)),
10721073
syntaxFlags,
10731074
matchFlags,
1074-
maxDeterminizedStates
1075+
RegexpQuery.DEFAULT_PROVIDER,
1076+
maxDeterminizedStates,
1077+
MultiTermQuery.DOC_VALUES_REWRITE
10751078
);
10761079
}
10771080
}

x-pack/plugin/ml/src/main/java/module-info.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
opens org.elasticsearch.xpack.ml to org.elasticsearch.painless.spi; // whitelist resource access
3333
opens org.elasticsearch.xpack.ml.utils; // for exact.properties access
3434

35+
provides org.elasticsearch.features.FeatureSpecification with org.elasticsearch.xpack.ml.MachineLearningFeatures;
3536
provides org.elasticsearch.painless.spi.PainlessExtension with org.elasticsearch.xpack.ml.MachineLearningPainlessExtension;
3637
provides org.elasticsearch.xpack.autoscaling.AutoscalingExtension with org.elasticsearch.xpack.ml.autoscaling.MlAutoscalingExtension;
3738

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
8+
package org.elasticsearch.xpack.ml;
9+
10+
import org.elasticsearch.features.FeatureSpecification;
11+
import org.elasticsearch.features.NodeFeature;
12+
13+
import java.util.Set;
14+
15+
public class MachineLearningFeatures implements FeatureSpecification {
16+
17+
public static final NodeFeature COMPONENTS_RESET_ACTION = new NodeFeature("ml.components.reset");
18+
19+
public Set<NodeFeature> getFeatures() {
20+
return Set.of(COMPONENTS_RESET_ACTION);
21+
}
22+
}

x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportResetMlComponentsAction.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,20 @@
77

88
package org.elasticsearch.xpack.ml.action;
99

10+
import org.elasticsearch.action.ActionListener;
1011
import org.elasticsearch.action.FailedNodeException;
1112
import org.elasticsearch.action.support.ActionFilters;
1213
import org.elasticsearch.action.support.nodes.TransportNodesAction;
1314
import org.elasticsearch.cluster.node.DiscoveryNode;
1415
import org.elasticsearch.cluster.service.ClusterService;
1516
import org.elasticsearch.common.io.stream.StreamInput;
17+
import org.elasticsearch.features.FeatureService;
1618
import org.elasticsearch.injection.guice.Inject;
1719
import org.elasticsearch.tasks.Task;
1820
import org.elasticsearch.threadpool.ThreadPool;
1921
import org.elasticsearch.transport.TransportService;
2022
import org.elasticsearch.xpack.core.ml.action.ResetMlComponentsAction;
23+
import org.elasticsearch.xpack.ml.MachineLearningFeatures;
2124
import org.elasticsearch.xpack.ml.inference.TrainedModelStatsService;
2225
import org.elasticsearch.xpack.ml.notifications.AnomalyDetectionAuditor;
2326
import org.elasticsearch.xpack.ml.notifications.DataFrameAnalyticsAuditor;
@@ -37,6 +40,7 @@ public class TransportResetMlComponentsAction extends TransportNodesAction<
3740
private final DataFrameAnalyticsAuditor dfaAuditor;
3841
private final InferenceAuditor inferenceAuditor;
3942
private final TrainedModelStatsService trainedModelStatsService;
43+
private final FeatureService featureService;
4044

4145
@Inject
4246
public TransportResetMlComponentsAction(
@@ -47,7 +51,8 @@ public TransportResetMlComponentsAction(
4751
AnomalyDetectionAuditor anomalyDetectionAuditor,
4852
DataFrameAnalyticsAuditor dfaAuditor,
4953
InferenceAuditor inferenceAuditor,
50-
TrainedModelStatsService trainedModelStatsService
54+
TrainedModelStatsService trainedModelStatsService,
55+
FeatureService featureService
5156
) {
5257
super(
5358
ResetMlComponentsAction.NAME,
@@ -61,6 +66,20 @@ public TransportResetMlComponentsAction(
6166
this.dfaAuditor = dfaAuditor;
6267
this.inferenceAuditor = inferenceAuditor;
6368
this.trainedModelStatsService = trainedModelStatsService;
69+
this.featureService = featureService;
70+
}
71+
72+
@Override
73+
protected void doExecute(
74+
Task task,
75+
ResetMlComponentsAction.Request request,
76+
ActionListener<ResetMlComponentsAction.Response> listener
77+
) {
78+
if (featureService.clusterHasFeature(clusterService.state(), MachineLearningFeatures.COMPONENTS_RESET_ACTION) == false) {
79+
listener.onResponse(new ResetMlComponentsAction.Response(clusterService.getClusterName(), List.of(), List.of()));
80+
} else {
81+
super.doExecute(task, request, listener);
82+
}
6483
}
6584

6685
@Override

0 commit comments

Comments
 (0)