|
| 1 | +/* |
| 2 | + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one |
| 3 | + * or more contributor license agreements. Licensed under the Elastic License |
| 4 | + * 2.0; you may not use this file except in compliance with the Elastic License |
| 5 | + * 2.0. |
| 6 | + */ |
| 7 | + |
| 8 | +package org.elasticsearch.xpack.logsdb.patterntext; |
| 9 | + |
| 10 | +import org.elasticsearch.xpack.logsdb.DataStreamLicenseChangeTestCase; |
| 11 | +import org.junit.Before; |
| 12 | + |
| 13 | +import java.io.IOException; |
| 14 | +import java.util.Map; |
| 15 | + |
| 16 | +import static org.hamcrest.Matchers.hasEntry; |
| 17 | +import static org.hamcrest.Matchers.hasKey; |
| 18 | + |
| 19 | +public class PatternTextBasicLicenseTests extends DataStreamLicenseChangeTestCase { |
| 20 | + @Before |
| 21 | + public void checkClusterFeature() { |
| 22 | + assumeTrue("[patterned_text] must be available", clusterHasFeature("mapper.patterned_text")); |
| 23 | + } |
| 24 | + |
| 25 | + private static final String patternTextMapping = """ |
| 26 | + { |
| 27 | + "index_patterns": ["%name%"], |
| 28 | + "priority": 500, |
| 29 | + "data_stream": {}, |
| 30 | + "template": { |
| 31 | + "mappings": { |
| 32 | + "properties": { |
| 33 | + "pattern_field": { |
| 34 | + "type": "pattern_text" |
| 35 | + } |
| 36 | + } |
| 37 | + } |
| 38 | + } |
| 39 | + }"""; |
| 40 | + |
| 41 | + @SuppressWarnings("unchecked") |
| 42 | + public void testLicenseUpgrade() throws IOException { |
| 43 | + final String dataStreamName = "test-foo"; |
| 44 | + |
| 45 | + final String doc = """ |
| 46 | + {"index": {}} |
| 47 | + {"@timestamp": "2025-01-01T00:00:00.000Z", "pattern_field": "foo"} |
| 48 | + """; |
| 49 | + |
| 50 | + assertOK(putTemplate(client(), "logs@custom", patternTextMapping.replace("%name%", dataStreamName))); |
| 51 | + assertOK(bulkIndex(client(), dataStreamName, () -> doc)); |
| 52 | + |
| 53 | + String backingIndex0 = getDataStreamBackingIndex(client(), dataStreamName, 0); |
| 54 | + { |
| 55 | + assertEquals("true", getSetting(client(), backingIndex0, "index.mapping.pattern_text.disable_templating")); |
| 56 | + Map<String, Object> mapping = getMapping(client(), backingIndex0); |
| 57 | + Map<String, Object> patternFieldMapping = (Map<String, Object>) ((Map<String, Object>) mapping.get("properties")).get( |
| 58 | + "pattern_field" |
| 59 | + ); |
| 60 | + assertThat(patternFieldMapping, hasEntry("disable_templating", true)); |
| 61 | + } |
| 62 | + |
| 63 | + assertOK(rolloverDataStream(client(), dataStreamName)); |
| 64 | + |
| 65 | + String backingIndex1 = getDataStreamBackingIndex(client(), dataStreamName, 1); |
| 66 | + { |
| 67 | + assertEquals("true", getSetting(client(), backingIndex1, "index.mapping.pattern_text.disable_templating")); |
| 68 | + Map<String, Object> mapping = getMapping(client(), backingIndex1); |
| 69 | + Map<String, Object> patternFieldMapping = (Map<String, Object>) ((Map<String, Object>) mapping.get("properties")).get( |
| 70 | + "pattern_field" |
| 71 | + ); |
| 72 | + assertThat(patternFieldMapping, hasKey("disable_templating")); |
| 73 | + } |
| 74 | + } |
| 75 | +} |
0 commit comments