-
Notifications
You must be signed in to change notification settings - Fork 26.1k
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
Changes from 6 commits
685aefa
fcd5fed
9245d34
c81a73a
d838315
d42657e
37c6e1f
57aa1ad
cfb6905
33e46ab
9e08be5
38c6728
d3d2ec4
f0b7d89
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,144 @@ | ||
| /* | ||
| * 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.
|
||
| @Before | ||
| public void checkClusterFeature() { | ||
| assumeTrue("[patterned_text] must be available", clusterHasFeature("mapper.patterned_text")); | ||
| } | ||
|
|
||
| @SuppressWarnings("unchecked") | ||
| 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 = (Map<String, Object>) ((Map<String, Object>) mapping.get("properties")).get( | ||
| "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 = (Map<String, Object>) ((Map<String, Object>) mapping.get("properties")).get( | ||
| "pattern_field" | ||
| ); | ||
| assertThat(patternFieldMapping, hasEntry("disable_templating", true)); | ||
| } | ||
| } | ||
|
|
||
| @SuppressWarnings("unchecked") | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: add the supress warning to the places where it is needed? For example: @SuppressWarnings("unchecked")
Map<String, Object> mapping = getMapping(client(), backingIndex0);
@SuppressWarnings("unchecked")
Map<String, Object> patternFieldMapping = (Map<String, Object>) ((Map<String, Object>) mapping.get("properties")).get(
"message"
);
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oops, yep I just added the whole-function SuppressWarnings just while I was developing the test and I meant to move it to the specific line, but it slipped my mind |
||
| 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" | ||
| }, | ||
| "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 = (Map<String, Object>) ((Map<String, Object>) mapping.get("properties")).get( | ||
| "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 = (Map<String, Object>) ((Map<String, Object>) mapping.get("properties")).get( | ||
| "message" | ||
| ); | ||
| assertThat(patternFieldMapping, hasEntry("disable_templating", true)); | ||
| } | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.