Skip to content

Commit 97af248

Browse files
authored
Merge branch 'main' into feature/shard_ref_count
2 parents 6270833 + 7249ac4 commit 97af248

File tree

18 files changed

+235
-63
lines changed

18 files changed

+235
-63
lines changed

docs/changelog/128854.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
pr: 128854
2+
summary: Mark token pruning for sparse vector as GA
3+
area: Machine Learning
4+
type: feature
5+
issues: []
6+
highlight:
7+
title: Mark Token Pruning for Sparse Vector as GA
8+
body: |-
9+
Token pruning for sparse_vector queries has been live since 8.13 as tech preview.
10+
As of 8.19.0 and 9.1.0, this is now generally available.
11+
notable: true

docs/reference/query-languages/esql/limitations.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,6 @@ In addition, when [querying multiple indexes](docs-content://explore-analyze/que
100100

101101
{{esql}} does not support configurations where the [_source field](/reference/elasticsearch/mapping-reference/mapping-source-field.md) is [disabled](/reference/elasticsearch/mapping-reference/mapping-source-field.md#disable-source-field).
102102

103-
[preview] {{esql}}'s support for [synthetic `_source`](/reference/elasticsearch/mapping-reference/mapping-source-field.md#synthetic-source) is currently experimental.
104-
105-
106103
## Full-text search [esql-limitations-full-text-search]
107104

108105
One limitation of [full-text search](/reference/query-languages/esql/functions-operators/search-functions.md) is that it is necessary to use the search function,

docs/reference/query-languages/query-dsl/query-dsl-sparse-vector-query.md

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,28 +62,36 @@ GET _search
6262
`query_vector`
6363
: (Optional, dictionary) A dictionary of token-weight pairs representing the precomputed query vector to search. Searching using this query vector will bypass additional inference. Only one of `inference_id` and `query_vector` is allowed.
6464

65-
`prune`
66-
: (Optional, boolean) [preview] Whether to perform pruning, omitting the non-significant tokens from the query to improve query performance. If `prune` is true but the `pruning_config` is not specified, pruning will occur but default values will be used. Default: false.
65+
`prune` {applies_to}`stack: preview 9.0, ga 9.1`
66+
: (Optional, boolean) Whether to perform pruning, omitting the non-significant tokens from the query to improve query performance. If `prune` is true but the `pruning_config` is not specified, pruning will occur but default values will be used. Default: false.
6767

68-
`pruning_config`
69-
: (Optional, object) [preview] Optional pruning configuration. If enabled, this will omit non-significant tokens from the query in order to improve query performance. This is only used if `prune` is set to `true`. If `prune` is set to `true` but `pruning_config` is not specified, default values will be used.
68+
`pruning_config` {applies_to}`stack: preview 9.0, ga 9.1`
69+
: (Optional, object) Optional pruning configuration. If enabled, this will omit non-significant tokens from the query in order to improve query performance. This is only used if `prune` is set to `true`. If `prune` is set to `true` but `pruning_config` is not specified, default values will be used.
7070

7171
Parameters for `pruning_config` are:
7272

7373
`tokens_freq_ratio_threshold`
74-
: (Optional, integer) [preview] Tokens whose frequency is more than `tokens_freq_ratio_threshold` times the average frequency of all tokens in the specified field are considered outliers and pruned. This value must between 1 and 100. Default: `5`.
74+
: (Optional, integer) Tokens whose frequency is more than `tokens_freq_ratio_threshold` times the average frequency of all tokens in the specified field are considered outliers and pruned. This value must between 1 and 100. Default: `5`.
7575

7676
`tokens_weight_threshold`
77-
: (Optional, float) [preview] Tokens whose weight is less than `tokens_weight_threshold` are considered insignificant and pruned. This value must be between 0 and 1. Default: `0.4`.
77+
: (Optional, float) Tokens whose weight is less than `tokens_weight_threshold` are considered insignificant and pruned. This value must be between 0 and 1. Default: `0.4`.
7878

7979
`only_score_pruned_tokens`
80-
: (Optional, boolean) [preview] If `true` we only input pruned tokens into scoring, and discard non-pruned tokens. It is strongly recommended to set this to `false` for the main query, but this can be set to `true` for a rescore query to get more relevant results. Default: `false`.
80+
: (Optional, boolean) If `true` we only input pruned tokens into scoring, and discard non-pruned tokens. It is strongly recommended to set this to `false` for the main query, but this can be set to `true` for a rescore query to get more relevant results. Default: `false`.
8181

8282
::::{note}
8383
The default values for `tokens_freq_ratio_threshold` and `tokens_weight_threshold` were chosen based on tests using ELSERv2 that provided the most optimal results.
8484
::::
8585

86+
When token pruning is applied, non-significant tokens will be pruned from the query.
87+
Non-significant tokens can be defined as tokens that meet both of the following criteria:
88+
* The token appears much more frequently than most tokens, indicating that it is a very common word and may not benefit the overall search results much.
89+
* The weight/score is so low that the token is likely not very relevant to the original term
8690

91+
Both the token frequency threshold and weight threshold must show the token is non-significant in order for the token to be pruned.
92+
This ensures that:
93+
* The tokens that are kept are frequent enough and have significant scoring.
94+
* Very infrequent tokens that may not have as high of a score are removed.
8795

8896
## Example ELSER query [sparse-vector-query-example]
8997

@@ -198,7 +206,7 @@ GET my-index/_search
198206

199207
## Example ELSER query with pruning configuration and rescore [sparse-vector-query-with-pruning-config-and-rescore-example]
200208

201-
The following is an extension to the above example that adds a [preview] pruning configuration to the `sparse_vector` query. The pruning configuration identifies non-significant tokens to prune from the query in order to improve query performance.
209+
The following is an extension to the above example that adds a pruning configuration to the `sparse_vector` query. The pruning configuration identifies non-significant tokens to prune from the query in order to improve query performance.
202210

203211
Token pruning happens at the shard level. While this should result in the same tokens being labeled as insignificant across shards, this is not guaranteed based on the composition of each shard. Therefore, if you are running `sparse_vector` with a `pruning_config` on a multi-shard index, we strongly recommend adding a [Rescore filtered search results](/reference/elasticsearch/rest-apis/filter-search-results.md#rescore) function with the tokens that were originally pruned from the query. This will help mitigate any shard-level inconsistency with pruned tokens and provide better relevance overall.
204212

libs/entitlement/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ NotEntitledException: component [(server)], module [org.apache.lucene.misc], cla
3535

3636
### How to add an Elasticsearch module/plugin policy
3737

38-
A policy is defined in an `entitlements-policy.yaml` file within an Elasticsearch module/plugin under `src/main/plugin-metadata`. Policy files contain lists of entitlements that should be allowed, grouped by Java module name, which acts as the policy scope. For example, the `transport-netty4` Elasticsearch module's policy file contains an entitlement to accept `inbound_network` connections, limited to the `io.netty.transport` and `io.netty.common` Java modules.
38+
A policy is defined in an `entitlement-policy.yaml` file within an Elasticsearch module/plugin under `src/main/plugin-metadata`. Policy files contain lists of entitlements that should be allowed, grouped by Java module name, which acts as the policy scope. For example, the `transport-netty4` Elasticsearch module's policy file contains an entitlement to accept `inbound_network` connections, limited to the `io.netty.transport` and `io.netty.common` Java modules.
3939

4040
Elasticsearch modules/plugins that are not yet modularized (i.e. do not have `module-info.java`) will need to use single `ALL-UNNAMED` scope. For example, the `reindex` Elasticsearch module's policy file contains a single `ALL-UNNAMED` scope, with an entitlement to perform `outbound_network`; all code in `reindex` will be able to connect to the network. It is not possible to use the `ALL-UNNAMED` scope for modularized modules/plugins.
4141

modules/data-streams/src/main/java/org/elasticsearch/datastreams/action/TransportUpdateDataStreamSettingsAction.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ protected void masterOperation(
131131
new UpdateDataStreamSettingsAction.DataStreamSettingsResponse(
132132
dataStreamName,
133133
false,
134-
e.getMessage(),
134+
Strings.hasText(e.getMessage()) ? e.getMessage() : e.toString(),
135135
EMPTY,
136136
EMPTY,
137137
UpdateDataStreamSettingsAction.DataStreamSettingsResponse.IndicesSettingsResult.EMPTY
@@ -222,9 +222,12 @@ private void updateSettingsOnIndices(
222222
Map<String, Object> settingsToApply = new HashMap<>();
223223
List<String> appliedToDataStreamOnly = new ArrayList<>();
224224
List<String> appliedToDataStreamAndBackingIndices = new ArrayList<>();
225+
Settings effectiveSettings = dataStream.getEffectiveSettings(
226+
clusterService.state().projectState(projectResolver.getProjectId()).metadata()
227+
);
225228
for (String settingName : requestSettings.keySet()) {
226229
if (APPLY_TO_BACKING_INDICES.contains(settingName)) {
227-
settingsToApply.put(settingName, requestSettings.get(settingName));
230+
settingsToApply.put(settingName, effectiveSettings.get(settingName));
228231
appliedToDataStreamAndBackingIndices.add(settingName);
229232
} else if (APPLY_TO_DATA_STREAM_ONLY.contains(settingName)) {
230233
appliedToDataStreamOnly.add(settingName);
@@ -242,9 +245,7 @@ private void updateSettingsOnIndices(
242245
true,
243246
null,
244247
settingsFilter.filter(dataStream.getSettings()),
245-
settingsFilter.filter(
246-
dataStream.getEffectiveSettings(clusterService.state().projectState(projectResolver.getProjectId()).metadata())
247-
),
248+
settingsFilter.filter(effectiveSettings),
248249
new UpdateDataStreamSettingsAction.DataStreamSettingsResponse.IndicesSettingsResult(
249250
appliedToDataStreamOnly,
250251
appliedToDataStreamAndBackingIndices,

modules/data-streams/src/yamlRestTest/resources/rest-api-spec/test/data_stream/240_data_stream_settings.yml

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,3 +299,102 @@ setup:
299299
- match: { .$idx0name.settings.index.lifecycle.name: "my-policy" }
300300
- match: { .$idx1name.settings.index.number_of_shards: "1" }
301301
- match: { .$idx1name.settings.index.lifecycle.name: "my-policy" }
302+
303+
---
304+
"Test null out settings":
305+
- requires:
306+
cluster_features: [ "logs_stream" ]
307+
reason: requires setting 'logs_stream' to get or set data stream settings
308+
- do:
309+
allowed_warnings:
310+
- "index template [my-template] has index patterns [my-data-stream-*] matching patterns from existing older templates [global] with patterns (global => [*]); this template [my-template] will take precedence during new index creation"
311+
indices.put_index_template:
312+
name: my-template
313+
body:
314+
index_patterns: [ my-data-stream-* ]
315+
data_stream: { }
316+
template:
317+
settings:
318+
number_of_replicas: 0
319+
lifecycle.name: my-policy
320+
321+
- do:
322+
indices.create_data_stream:
323+
name: my-data-stream-1
324+
325+
- do:
326+
cluster.health:
327+
index: "my-data-stream-1"
328+
wait_for_status: green
329+
330+
331+
332+
- do:
333+
indices.get_data_stream:
334+
name: my-data-stream-1
335+
- match: { data_streams.0.name: my-data-stream-1 }
336+
- match: { data_streams.0.settings: {} }
337+
- match: { data_streams.0.effective_settings: null }
338+
339+
- do:
340+
indices.put_data_stream_settings:
341+
name: my-data-stream-1
342+
body:
343+
index:
344+
number_of_shards: 2
345+
lifecycle:
346+
name: my-new-policy
347+
prefer_ilm: true
348+
- match: { data_streams.0.name: my-data-stream-1 }
349+
- match: { data_streams.0.applied_to_data_stream: true }
350+
- match: { data_streams.0.index_settings_results.applied_to_data_stream_only: [index.number_of_shards]}
351+
- length: { data_streams.0.index_settings_results.applied_to_data_stream_and_backing_indices: 2 }
352+
- match: { data_streams.0.settings.index.number_of_shards: "2" }
353+
- match: { data_streams.0.settings.index.lifecycle.name: "my-new-policy" }
354+
- match: { data_streams.0.settings.index.lifecycle.prefer_ilm: "true" }
355+
- match: { data_streams.0.effective_settings.index.number_of_shards: "2" }
356+
- match: { data_streams.0.effective_settings.index.number_of_replicas: "0" }
357+
- match: { data_streams.0.effective_settings.index.lifecycle.name: "my-new-policy" }
358+
- match: { data_streams.0.effective_settings.index.lifecycle.prefer_ilm: "true" }
359+
360+
- do:
361+
indices.put_data_stream_settings:
362+
name: my-data-stream-1
363+
body:
364+
index:
365+
number_of_shards: null
366+
lifecycle:
367+
name: null
368+
- match: { data_streams.0.name: my-data-stream-1 }
369+
- match: { data_streams.0.applied_to_data_stream: true }
370+
- match: { data_streams.0.index_settings_results.applied_to_data_stream_only: [index.number_of_shards]}
371+
- length: { data_streams.0.index_settings_results.applied_to_data_stream_and_backing_indices: 1 }
372+
- match: { data_streams.0.settings.index.number_of_shards: null }
373+
- match: { data_streams.0.settings.index.lifecycle.name: null }
374+
- match: { data_streams.0.settings.index.lifecycle.prefer_ilm: "true" }
375+
- match: { data_streams.0.effective_settings.index.number_of_shards: null }
376+
- match: { data_streams.0.effective_settings.index.number_of_replicas: "0" }
377+
- match: { data_streams.0.effective_settings.index.lifecycle.name: "my-policy" }
378+
- match: { data_streams.0.effective_settings.index.lifecycle.prefer_ilm: "true" }
379+
380+
- do:
381+
indices.get_data_stream_settings:
382+
name: my-data-stream-1
383+
- match: { data_streams.0.name: my-data-stream-1 }
384+
- match: { data_streams.0.settings.index.lifecycle.name: null }
385+
- match: { data_streams.0.settings.index.lifecycle.prefer_ilm: "true" }
386+
- match: { data_streams.0.effective_settings.index.number_of_shards: null }
387+
- match: { data_streams.0.effective_settings.index.number_of_replicas: "0" }
388+
- match: { data_streams.0.effective_settings.index.lifecycle.name: "my-policy" }
389+
390+
- do:
391+
indices.get_data_stream:
392+
name: my-data-stream-1
393+
- set: { data_streams.0.indices.0.index_name: idx0name }
394+
395+
- do:
396+
indices.get_settings:
397+
index: my-data-stream-1
398+
- match: { .$idx0name.settings.index.number_of_shards: "1" }
399+
- match: { .$idx0name.settings.index.lifecycle.name: "my-policy" }
400+
- match: { .$idx0name.settings.index.lifecycle.prefer_ilm: "true" }

muted-tests.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -562,9 +562,6 @@ tests:
562562
- class: org.elasticsearch.xpack.rank.rrf.RRFRankClientYamlTestSuiteIT
563563
method: test {yaml=rrf/950_pinned_interaction/rrf with pinned retriever as a sub-retriever}
564564
issue: https://github.com/elastic/elasticsearch/issues/129845
565-
- class: org.elasticsearch.xpack.test.rest.XPackRestIT
566-
method: test {p0=esql/60_usage/Basic ESQL usage output (telemetry) non-snapshot version}
567-
issue: https://github.com/elastic/elasticsearch/issues/129888
568565
- class: org.elasticsearch.index.mapper.vectors.DenseVectorFieldMapperTests
569566
method: testExistsQueryMinimalMapping
570567
issue: https://github.com/elastic/elasticsearch/issues/129911

server/src/main/java/org/elasticsearch/cluster/metadata/MetadataDataStreamsService.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,15 @@ private DataStream createDataStreamForUpdatedDataStreamSettings(
456456

457457
Template.Builder templateBuilder = Template.builder();
458458
Settings.Builder mergedSettingsBuilder = Settings.builder().put(existingSettings).put(settingsOverrides);
459+
/*
460+
* A null value for a setting override means that we remove it from the data stream, and let the value from the template (if any)
461+
* be used.
462+
*/
463+
settingsOverrides.keySet().forEach(key -> {
464+
if (mergedSettingsBuilder.get(key) == null) {
465+
mergedSettingsBuilder.remove(key);
466+
}
467+
});
459468
Settings mergedSettings = mergedSettingsBuilder.build();
460469

461470
final ComposableIndexTemplate template = lookupTemplateForDataStream(dataStreamName, projectMetadata);

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/parser/LogicalPlanBuilder.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,13 @@ public LogicalPlanBuilder(ParsingContext context) {
120120

121121
protected LogicalPlan plan(ParseTree ctx) {
122122
LogicalPlan p = ParserUtils.typedParsing(this, ctx, LogicalPlan.class);
123+
if (p instanceof Explain == false && p.anyMatch(logicalPlan -> logicalPlan instanceof Explain)) {
124+
throw new ParsingException(source(ctx), "EXPLAIN does not support downstream commands");
125+
}
126+
if (p instanceof Explain explain && explain.query().anyMatch(logicalPlan -> logicalPlan instanceof Explain)) {
127+
// TODO this one is never reached because the Parser fails to understand multiple round brackets
128+
throw new ParsingException(source(ctx), "EXPLAIN cannot be used inside another EXPLAIN command");
129+
}
123130
var errors = this.context.params().parsingErrors();
124131
if (errors.hasNext() == false) {
125132
return p;

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/session/EsqlSession.java

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -190,15 +190,10 @@ public void execute(EsqlQueryRequest request, EsqlExecutionInfo executionInfo, P
190190
assert executionInfo != null : "Null EsqlExecutionInfo";
191191
LOGGER.debug("ESQL query:\n{}", request.query());
192192
LogicalPlan parsed = parse(request.query(), request.params());
193-
Explain explain = findExplain(parsed);
194-
if (explain != null) {
193+
if (parsed instanceof Explain explain) {
195194
explainMode = true;
196-
if (explain == parsed) {
197-
parsed = explain.query();
198-
parsedPlanString = parsed.toString();
199-
} else {
200-
throw new VerificationException("EXPLAIN does not support downstream commands");
201-
}
195+
parsed = explain.query();
196+
parsedPlanString = parsed.toString();
202197
}
203198
analyzedPlan(parsed, executionInfo, request.filter(), new EsqlCCSUtils.CssPartialErrorsActionListener(executionInfo, listener) {
204199
@Override
@@ -211,19 +206,6 @@ public void onResponse(LogicalPlan analyzedPlan) {
211206
});
212207
}
213208

214-
private Explain findExplain(LogicalPlan parsed) {
215-
if (parsed instanceof Explain e) {
216-
return e;
217-
}
218-
for (LogicalPlan child : parsed.children()) {
219-
Explain result = findExplain(child);
220-
if (result != null) {
221-
return result;
222-
}
223-
}
224-
return null;
225-
}
226-
227209
/**
228210
* Execute an analyzed plan. Most code should prefer calling {@link #execute} but
229211
* this is public for testing.

0 commit comments

Comments
 (0)