Skip to content

Commit 1c9eb06

Browse files
[9.2] 🌊 Streams: Speed up field simulation (#241313) (#241417)
# Backport This will backport the following commits from `main` to `9.2`: - [🌊 Streams: Speed up field simulation (#241313)](#241313) <!--- Backport version: 9.6.6 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sorenlouv/backport) <!--BACKPORT [{"author":{"name":"Joe Reuter","email":"[email protected]"},"sourceCommit":{"committedDate":"2025-10-31T09:33:05Z","message":"🌊 Streams: Speed up field simulation (#241313)\n\nThis PR should speed up field simulation, which is blocking the submit\nbutton when defining mappings. It does the following things:\n* Set a timeout\n* Reduce sample size\n* Set terminate_after and disable track_total_hits to get Elasticsearch\nto stop work as soon as possible\n* Don't sort the results, otherwise Elasticsearch is forced to evaluate\nall the docs because otherwise it can't tell which ones would end up on\ntop in the order","sha":"50186a48b362ca77d429d4d43dd25cebcfe1cfbe","branchLabelMapping":{"^v9.3.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix","Team:obs-ux-logs","backport:version","Feature:Streams","Team:streams-program","v9.3.0","v9.2.1"],"title":"🌊 Streams: Speed up field simulation","number":241313,"url":"https://github.com/elastic/kibana/pull/241313","mergeCommit":{"message":"🌊 Streams: Speed up field simulation (#241313)\n\nThis PR should speed up field simulation, which is blocking the submit\nbutton when defining mappings. It does the following things:\n* Set a timeout\n* Reduce sample size\n* Set terminate_after and disable track_total_hits to get Elasticsearch\nto stop work as soon as possible\n* Don't sort the results, otherwise Elasticsearch is forced to evaluate\nall the docs because otherwise it can't tell which ones would end up on\ntop in the order","sha":"50186a48b362ca77d429d4d43dd25cebcfe1cfbe"}},"sourceBranch":"main","suggestedTargetBranches":["9.2"],"targetPullRequestStates":[{"branch":"main","label":"v9.3.0","branchLabelMappingKey":"^v9.3.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/241313","number":241313,"mergeCommit":{"message":"🌊 Streams: Speed up field simulation (#241313)\n\nThis PR should speed up field simulation, which is blocking the submit\nbutton when defining mappings. It does the following things:\n* Set a timeout\n* Reduce sample size\n* Set terminate_after and disable track_total_hits to get Elasticsearch\nto stop work as soon as possible\n* Don't sort the results, otherwise Elasticsearch is forced to evaluate\nall the docs because otherwise it can't tell which ones would end up on\ntop in the order","sha":"50186a48b362ca77d429d4d43dd25cebcfe1cfbe"}},{"branch":"9.2","label":"v9.2.1","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}] BACKPORT--> Co-authored-by: Joe Reuter <[email protected]>
1 parent 9de3416 commit 1c9eb06

File tree

1 file changed

+9
-20
lines changed
  • x-pack/platform/plugins/shared/streams/server/routes/internal/streams/schema

1 file changed

+9
-20
lines changed

β€Žx-pack/platform/plugins/shared/streams/server/routes/internal/streams/schema/route.tsβ€Ž

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { checkAccess } from '../../../../lib/streams/stream_crud';
2020
import { createServerRoute } from '../../../create_server_route';
2121

2222
const UNMAPPED_SAMPLE_SIZE = 500;
23+
const FIELD_SIMULATION_TIMEOUT = '1s';
2324

2425
export const unmappedFieldsRoute = createServerRoute({
2526
endpoint: 'GET /internal/streams/{name}/schema/unmapped_fields',
@@ -90,7 +91,7 @@ export const unmappedFieldsRoute = createServerRoute({
9091
},
9192
});
9293

93-
const FIELD_SIMILATION_SAMPLE_SIZE = 200;
94+
const FIELD_SIMILATION_SAMPLE_SIZE = 20;
9495

9596
export const schemaFieldsSimulationRoute = createServerRoute({
9697
endpoint: 'POST /internal/streams/{name}/schema/fields_simulation',
@@ -149,26 +150,18 @@ export const schemaFieldsSimulationRoute = createServerRoute({
149150
})),
150151
},
151152
},
152-
sort: [
153-
{
154-
'@timestamp': {
155-
order: 'desc' as const,
156-
},
157-
},
158-
],
159153
size: FIELD_SIMILATION_SAMPLE_SIZE,
154+
track_total_hits: false,
155+
terminate_after: FIELD_SIMILATION_SAMPLE_SIZE,
156+
timeout: FIELD_SIMULATION_TIMEOUT,
160157
};
161158

162159
const sampleResults = await scopedClusterClient.asCurrentUser.search({
163160
index: params.path.name,
164161
...documentSamplesSearchBody,
165162
});
166163

167-
if (
168-
(typeof sampleResults.hits.total === 'object' && sampleResults.hits.total?.value === 0) ||
169-
sampleResults.hits.total === 0 ||
170-
!sampleResults.hits.total
171-
) {
164+
if (sampleResults.hits.hits.length === 0) {
172165
return {
173166
status: 'unknown',
174167
simulationError: null,
@@ -232,16 +225,12 @@ export const schemaFieldsSimulationRoute = createServerRoute({
232225

233226
const runtimeFieldsSearchBody = {
234227
runtime_mappings: propertiesCompatibleWithRuntimeMappings,
235-
sort: [
236-
{
237-
'@timestamp': {
238-
order: 'desc' as const,
239-
},
240-
},
241-
],
242228
size: FIELD_SIMILATION_SAMPLE_SIZE,
243229
fields: params.body.field_definitions.map((field) => field.name),
244230
_source: false,
231+
track_total_hits: false,
232+
terminate_after: FIELD_SIMILATION_SAMPLE_SIZE,
233+
timeout: FIELD_SIMULATION_TIMEOUT,
245234
};
246235

247236
// This gives us a "fields" representation rather than _source from the simulation

0 commit comments

Comments
Β (0)