Skip to content

Commit fb7ffea

Browse files
authored
Merge branch '9.1' into backport/9.1/pr-130826
2 parents 79265b9 + 992e62d commit fb7ffea

File tree

102 files changed

+1202
-365
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

102 files changed

+1202
-365
lines changed

benchmarks/src/main/java/org/elasticsearch/benchmark/_nightly/esql/QueryPlanningBenchmark.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,11 @@ public class QueryPlanningBenchmark {
7070
private EsqlParser defaultParser;
7171
private Analyzer manyFieldsAnalyzer;
7272
private LogicalPlanOptimizer defaultOptimizer;
73+
private Configuration config;
7374

7475
@Setup
7576
public void setup() {
76-
77-
var config = new Configuration(
77+
this.config = new Configuration(
7878
DateUtils.UTC,
7979
Locale.US,
8080
null,
@@ -116,7 +116,7 @@ public void setup() {
116116
}
117117

118118
private LogicalPlan plan(EsqlParser parser, Analyzer analyzer, LogicalPlanOptimizer optimizer, String query) {
119-
var parsed = parser.createStatement(query, new QueryParams(), telemetry);
119+
var parsed = parser.createStatement(query, new QueryParams(), telemetry, config);
120120
var analyzed = analyzer.analyze(parsed);
121121
var optimized = optimizer.optimize(analyzed);
122122
return optimized;

docs/changelog/130849.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
pr: 130849
2+
summary: Fix behavior for `_index` LIKE for ESQL
3+
area: ES|QL
4+
type: bug
5+
issues:
6+
- 129511

docs/changelog/131015.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 131015
2+
summary: Move streams status actions to cluster:monitor group
3+
area: Data streams
4+
type: bug
5+
issues: []

docs/changelog/131081.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
pr: 131081
2+
summary: Fix knn search error when dimensions are not set
3+
area: Vector Search
4+
type: bug
5+
issues:
6+
- 129550

modules/streams/src/main/java/org/elasticsearch/rest/streams/logs/StreamsStatusAction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
public class StreamsStatusAction {
2828

29-
public static ActionType<Response> INSTANCE = new ActionType<>("cluster:admin/streams/status");
29+
public static ActionType<Response> INSTANCE = new ActionType<>("cluster:monitor/streams/status");
3030

3131
public static class Request extends LocalClusterStateRequest {
3232
protected Request(TimeValue masterTimeout) {

muted-tests.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -491,9 +491,6 @@ tests:
491491
- class: org.elasticsearch.search.query.VectorIT
492492
method: testFilteredQueryStrategy
493493
issue: https://github.com/elastic/elasticsearch/issues/129517
494-
- class: org.elasticsearch.test.apmintegration.TracesApmIT
495-
method: testApmIntegration
496-
issue: https://github.com/elastic/elasticsearch/issues/129651
497494
- class: org.elasticsearch.xpack.security.SecurityRolesMultiProjectIT
498495
method: testUpdatingFileBasedRoleAffectsAllProjects
499496
issue: https://github.com/elastic/elasticsearch/issues/129775

rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/search.vectors/40_knn_search.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -670,3 +670,36 @@ setup:
670670
properties:
671671
embedding:
672672
type: dense_vector
673+
674+
675+
---
676+
"Searching with no data dimensions specified":
677+
- requires:
678+
cluster_features: "search.vectors.no_dimensions_bugfix"
679+
reason: "Search with no dimensions bugfix"
680+
681+
- do:
682+
indices.create:
683+
index: empty-test
684+
body:
685+
mappings:
686+
properties:
687+
vector:
688+
type: dense_vector
689+
index: true
690+
691+
- do:
692+
search:
693+
index: empty-test
694+
body:
695+
fields: [ "name" ]
696+
knn:
697+
field: vector
698+
query_vector: [ -0.5, 90.0, -10, 14.8, -156.0 ]
699+
k: 3
700+
num_candidates: 3
701+
rescore_vector:
702+
oversample: 1.5
703+
similarity: 0.1
704+
705+
- match: { hits.total.value: 0 }

server/src/main/java/org/elasticsearch/TransportVersions.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ static TransportVersion def(int id) {
211211
public static final TransportVersion ESQL_DOCUMENTS_FOUND_AND_VALUES_LOADED_8_19 = def(8_841_0_61);
212212
public static final TransportVersion ESQL_PROFILE_INCLUDE_PLAN_8_19 = def(8_841_0_62);
213213
public static final TransportVersion ESQL_SPLIT_ON_BIG_VALUES_8_19 = def(8_841_0_63);
214+
public static final TransportVersion ESQL_FIXED_INDEX_LIKE_8_19 = def(8_841_0_64);
214215
public static final TransportVersion V_9_0_0 = def(9_000_0_09);
215216
public static final TransportVersion INITIAL_ELASTICSEARCH_9_0_1 = def(9_000_0_10);
216217
public static final TransportVersion INITIAL_ELASTICSEARCH_9_0_2 = def(9_000_0_11);
@@ -328,6 +329,7 @@ static TransportVersion def(int id) {
328329
public static final TransportVersion ESQL_PROFILE_INCLUDE_PLAN = def(9_111_0_00);
329330
public static final TransportVersion MAPPINGS_IN_DATA_STREAMS = def(9_112_0_00);
330331
public static final TransportVersion ESQL_SPLIT_ON_BIG_VALUES_9_1 = def(9_112_0_01);
332+
public static final TransportVersion ESQL_FIXED_INDEX_LIKE_9_1 = def(9_112_0_02);
331333

332334
/*
333335
* STOP! READ THIS FIRST! No, really,

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

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
import org.apache.lucene.search.MultiTermQuery;
1616
import org.apache.lucene.search.Query;
1717
import org.apache.lucene.util.BytesRef;
18+
import org.apache.lucene.util.automaton.Automaton;
19+
import org.apache.lucene.util.automaton.CharacterRunAutomaton;
1820
import org.elasticsearch.common.lucene.search.Queries;
1921
import org.elasticsearch.common.regex.Regex;
2022
import org.elasticsearch.core.Nullable;
@@ -23,6 +25,7 @@
2325

2426
import java.util.Collection;
2527
import java.util.Map;
28+
import java.util.function.Supplier;
2629

2730
/**
2831
* A {@link MappedFieldType} that has the same value for all documents.
@@ -135,9 +138,47 @@ public final Query wildcardQuery(String value, boolean caseInsensitive, QueryRew
135138
}
136139
}
137140

141+
/**
142+
* Returns a query that matches all documents or no documents
143+
* It usually calls {@link #wildcardQuery(String, boolean, QueryRewriteContext)}
144+
* except for IndexFieldType which overrides this method to use its own matching logic.
145+
*/
146+
public Query wildcardLikeQuery(String value, boolean caseInsensitive, QueryRewriteContext context) {
147+
return wildcardQuery(value, caseInsensitive, context);
148+
}
149+
138150
@Override
139151
public final boolean fieldHasValue(FieldInfos fieldInfos) {
140152
// We consider constant field types to always have value.
141153
return true;
142154
}
155+
156+
/**
157+
* Returns the constant value of this field as a string.
158+
* Based on the field type, we need to get it in a different way.
159+
*/
160+
public abstract String getConstantFieldValue(SearchExecutionContext context);
161+
162+
/**
163+
* Returns a query that matches all documents or no documents
164+
* depending on whether the constant value of this field matches or not
165+
*/
166+
@Override
167+
public Query automatonQuery(
168+
Supplier<Automaton> automatonSupplier,
169+
Supplier<CharacterRunAutomaton> characterRunAutomatonSupplier,
170+
@Nullable MultiTermQuery.RewriteMethod method,
171+
SearchExecutionContext context,
172+
String description
173+
) {
174+
CharacterRunAutomaton compiled = characterRunAutomatonSupplier.get();
175+
boolean matches = compiled.run(getConstantFieldValue(context));
176+
if (matches) {
177+
return new MatchAllDocsQuery();
178+
} else {
179+
return new MatchNoDocsQuery(
180+
"The \"" + context.getFullyQualifiedIndex().getName() + "\" query was rewritten to a \"match_none\" query."
181+
);
182+
}
183+
}
143184
}

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

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,13 @@
1010
package org.elasticsearch.index.mapper;
1111

1212
import org.apache.lucene.search.MatchAllDocsQuery;
13+
import org.apache.lucene.search.MatchNoDocsQuery;
14+
import org.apache.lucene.search.MultiTermQuery;
1315
import org.apache.lucene.search.Query;
1416
import org.apache.lucene.util.BytesRef;
1517
import org.elasticsearch.common.Strings;
18+
import org.elasticsearch.common.regex.Regex;
19+
import org.elasticsearch.core.Nullable;
1620
import org.elasticsearch.index.fielddata.FieldData;
1721
import org.elasticsearch.index.fielddata.FieldDataContext;
1822
import org.elasticsearch.index.fielddata.IndexFieldData;
@@ -27,6 +31,7 @@
2731

2832
import java.util.Collections;
2933
import java.util.List;
34+
import java.util.Locale;
3035

3136
public class IndexFieldMapper extends MetadataFieldMapper {
3237

@@ -102,6 +107,38 @@ public StoredFieldsSpec storedFieldsSpec() {
102107
};
103108
}
104109

110+
@Override
111+
public Query wildcardLikeQuery(
112+
String value,
113+
@Nullable MultiTermQuery.RewriteMethod method,
114+
boolean caseInsensitve,
115+
SearchExecutionContext context
116+
) {
117+
String indexName = context.getFullyQualifiedIndex().getName();
118+
return getWildcardLikeQuery(value, caseInsensitve, indexName);
119+
}
120+
121+
@Override
122+
public Query wildcardLikeQuery(String value, boolean caseInsensitive, QueryRewriteContext context) {
123+
String indexName = context.getFullyQualifiedIndex().getName();
124+
return getWildcardLikeQuery(value, caseInsensitive, indexName);
125+
}
126+
127+
private static Query getWildcardLikeQuery(String value, boolean caseInsensitve, String indexName) {
128+
if (caseInsensitve) {
129+
value = value.toLowerCase(Locale.ROOT);
130+
indexName = indexName.toLowerCase(Locale.ROOT);
131+
}
132+
if (Regex.simpleMatch(value, indexName)) {
133+
return new MatchAllDocsQuery();
134+
}
135+
return new MatchNoDocsQuery("The \"" + indexName + "\" query was rewritten to a \"match_none\" query.");
136+
}
137+
138+
@Override
139+
public String getConstantFieldValue(SearchExecutionContext context) {
140+
return context.getFullyQualifiedIndex().getName();
141+
}
105142
}
106143

107144
public IndexFieldMapper() {

0 commit comments

Comments
 (0)