-
Notifications
You must be signed in to change notification settings - Fork 25.7k
Add default sort for message.template_id field in logsdb indices #136571
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
jordan-powers
merged 14 commits into
elastic:main
from
jordan-powers:logs-message-default-sort
Oct 29, 2025
Merged
Changes from 11 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
685aefa
Initial implementation
jordan-powers fcd5fed
Add tests
jordan-powers 9245d34
Merge remote-tracking branch 'upstream/main' into logs-message-defaul…
jordan-powers c81a73a
Rename PatternTextBasicLicenseIT
jordan-powers d838315
Fix tests
jordan-powers d42657e
Merge remote-tracking branch 'upstream/main' into logs-message-defaul…
jordan-powers 37c6e1f
Add user setting to enable default message sort
jordan-powers 57aa1ad
Move suppress warnings to helper method
jordan-powers cfb6905
Merge remote-tracking branch 'upstream/main' into logs-message-defaul…
jordan-powers 33e46ab
Fix LogsdbSortConfigIT
jordan-powers 9e08be5
Merge remote-tracking branch 'upstream/main' into logs-message-defaul…
jordan-powers 38c6728
Update pattern_text documentation with new index sort setting
jordan-powers d3d2ec4
Merge remote-tracking branch 'upstream/main' into logs-message-defaul…
jordan-powers f0b7d89
Tweak updated docs
jordan-powers File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
140 changes: 140 additions & 0 deletions
140
...vaRestTest/java/org/elasticsearch/xpack/logsdb/patterntext/PatternTextBasicLicenseIT.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,140 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License | ||
| * 2.0; you may not use this file except in compliance with the Elastic License | ||
| * 2.0. | ||
| */ | ||
|
|
||
| package org.elasticsearch.xpack.logsdb.patterntext; | ||
|
|
||
| import org.elasticsearch.xpack.logsdb.DataStreamLicenseChangeTestCase; | ||
| import org.junit.Before; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
|
|
||
| import static org.hamcrest.Matchers.hasEntry; | ||
|
|
||
| public class PatternTextBasicLicenseIT extends DataStreamLicenseChangeTestCase { | ||
martijnvg marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| @Before | ||
| public void checkClusterFeature() { | ||
| assumeTrue("[patterned_text] must be available", clusterHasFeature("mapper.patterned_text")); | ||
| } | ||
|
|
||
| @SuppressWarnings("unchecked") | ||
| private Map<String, Object> getFieldMapping(Map<String, Object> mapping, String fieldName) { | ||
| return (Map<String, Object>) ((Map<String, Object>) mapping.get("properties")).get(fieldName); | ||
| } | ||
|
|
||
| public void testStandardIndex() throws IOException { | ||
| final String dataStreamName = "test-foo"; | ||
|
|
||
| final String mappingStr = """ | ||
| { | ||
| "index_patterns": ["%name%"], | ||
| "priority": 500, | ||
| "data_stream": {}, | ||
| "template": { | ||
| "mappings": { | ||
| "properties": { | ||
| "pattern_field": { | ||
| "type": "pattern_text" | ||
| } | ||
| } | ||
| } | ||
| } | ||
| }"""; | ||
|
|
||
| final String doc = """ | ||
| {"index": {}} | ||
| {"@timestamp": "2025-01-01T00:00:00.000Z", "pattern_field": "foo"} | ||
| """; | ||
|
|
||
| assertOK(putTemplate(client(), "logs@custom", mappingStr.replace("%name%", dataStreamName))); | ||
| assertOK(bulkIndex(client(), dataStreamName, () -> doc)); | ||
|
|
||
| String backingIndex0 = getDataStreamBackingIndex(client(), dataStreamName, 0); | ||
| { | ||
| assertEquals("true", getSetting(client(), backingIndex0, "index.mapping.pattern_text.disable_templating")); | ||
| Map<String, Object> mapping = getMapping(client(), backingIndex0); | ||
| Map<String, Object> patternFieldMapping = getFieldMapping(mapping, "pattern_field"); | ||
| assertThat(patternFieldMapping, hasEntry("disable_templating", true)); | ||
| } | ||
|
|
||
| assertOK(rolloverDataStream(client(), dataStreamName)); | ||
|
|
||
| String backingIndex1 = getDataStreamBackingIndex(client(), dataStreamName, 1); | ||
| { | ||
| assertEquals("true", getSetting(client(), backingIndex1, "index.mapping.pattern_text.disable_templating")); | ||
| Map<String, Object> mapping = getMapping(client(), backingIndex1); | ||
| Map<String, Object> patternFieldMapping = getFieldMapping(mapping, "pattern_field"); | ||
| assertThat(patternFieldMapping, hasEntry("disable_templating", true)); | ||
| } | ||
| } | ||
|
|
||
| public void testLogsdbIndex() throws IOException { | ||
| final String dataStreamName = "test-bar"; | ||
|
|
||
| final String mappingStr = """ | ||
| { | ||
| "index_patterns": ["%name%"], | ||
| "priority": 500, | ||
| "data_stream": {}, | ||
| "template": { | ||
| "settings": { | ||
| "index.mode": "logsdb", | ||
| "index.logsdb.default_sort_on_message_template": true | ||
| }, | ||
| "mappings": { | ||
| "properties": { | ||
| "@timestamp": { | ||
| "type": "date" | ||
| }, | ||
| "message": { | ||
| "type": "pattern_text" | ||
| }, | ||
| "host.name": { | ||
| "type": "keyword" | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| """; | ||
|
|
||
| final String doc = """ | ||
| {"index": {}} | ||
| {"@timestamp": "2025-01-01T00:00:00.000Z", "message": "foo 123", "host.name": "bar"} | ||
| """; | ||
|
|
||
| assertOK(putTemplate(client(), "logs@custom", mappingStr.replace("%name%", dataStreamName))); | ||
| assertOK(bulkIndex(client(), dataStreamName, () -> doc)); | ||
|
|
||
| String backingIndex0 = getDataStreamBackingIndex(client(), dataStreamName, 0); | ||
| { | ||
| assertEquals("true", getSetting(client(), backingIndex0, "index.mapping.pattern_text.disable_templating")); | ||
| assertEquals( | ||
| List.of("host.name", "message.template_id", "@timestamp"), | ||
| getSetting(client(), backingIndex0, "index.sort.field") | ||
| ); | ||
| Map<String, Object> mapping = getMapping(client(), backingIndex0); | ||
| Map<String, Object> patternFieldMapping = getFieldMapping(mapping, "message"); | ||
| assertThat(patternFieldMapping, hasEntry("disable_templating", true)); | ||
| } | ||
|
|
||
| assertOK(rolloverDataStream(client(), dataStreamName)); | ||
|
|
||
| String backingIndex1 = getDataStreamBackingIndex(client(), dataStreamName, 1); | ||
| { | ||
| assertEquals("true", getSetting(client(), backingIndex1, "index.mapping.pattern_text.disable_templating")); | ||
| assertEquals( | ||
| List.of("host.name", "message.template_id", "@timestamp"), | ||
| getSetting(client(), backingIndex1, "index.sort.field") | ||
| ); | ||
| Map<String, Object> mapping = getMapping(client(), backingIndex1); | ||
| Map<String, Object> patternFieldMapping = getFieldMapping(mapping, "message"); | ||
| assertThat(patternFieldMapping, hasEntry("disable_templating", true)); | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.