Преглед изворни кода

TSDB: routingPath object type check improvement (#83310)

Only reject mappings who's object fields exactly match routing_path. If
the fields match some pattern in routing_path that's ok - so long as the
fields inside follow all of the routing_path rules.
weizijun пре 3 година
родитељ
комит
ab6de24f7b

+ 5 - 0
docs/changelog/83310.yaml

@@ -0,0 +1,5 @@
+pr: 83310
+summary: "TSDB: routingPath object type check improvement"
+area: TSDB
+type: enhancement
+issues: []

+ 37 - 4
rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/tsdb/20_mapping.yml

@@ -54,10 +54,10 @@ ecs style:
                               time_series_metric: gauge
 
 ---
-top level dim object:
+top level wildcard dim object:
   - skip:
-      version: " - 8.0.99"
-      reason: introduced in 8.1.0
+      version: " - 8.1.99"
+      reason: routing_path object type check improve in 8.2.0
 
   - do:
       indices.create:
@@ -66,7 +66,7 @@ top level dim object:
             settings:
               index:
                 mode: time_series
-                routing_path: [dim.*]
+                routing_path: [dim*]
                 time_series:
                   start_time: 2021-04-28T00:00:00Z
                   end_time: 2021-04-29T00:00:00Z
@@ -111,6 +111,39 @@ top level dim object:
                               type: double
                               time_series_metric: gauge
 
+---
+exact match object type:
+  - skip:
+      version: " - 8.1.99"
+      reason: routing_path object type check improve in 8.2.0
+
+  - do:
+      catch: '/All fields that match routing_path must be keywords with \[time_series_dimension: true\] and without the \[script\] parameter. \[dim\] was \[object\]./'
+      indices.create:
+        index: tsdb_index
+        body:
+          settings:
+            index:
+              mode: time_series
+              routing_path: [dim]
+              time_series:
+                start_time: 2021-04-28T00:00:00Z
+                end_time: 2021-04-29T00:00:00Z
+              number_of_replicas: 0
+              number_of_shards: 2
+          mappings:
+            properties:
+              "@timestamp":
+                type: date
+              dim:
+                properties:
+                  metricset:
+                    type: keyword
+                    time_series_dimension: true
+                  uid:
+                    type: keyword
+                    time_series_dimension: true
+
 ---
 non keyword matches routing_path:
   - skip:

+ 2 - 2
server/src/main/java/org/elasticsearch/index/mapper/DocumentMapper.java

@@ -9,7 +9,6 @@
 package org.elasticsearch.index.mapper;
 
 import org.elasticsearch.common.compress.CompressedXContent;
-import org.elasticsearch.common.regex.Regex;
 import org.elasticsearch.index.IndexSettings;
 
 import java.util.List;
@@ -104,7 +103,8 @@ public class DocumentMapper {
                 mappingLookup.getFieldType(match).validateMatchedRoutingPath();
             }
             for (String objectName : mappingLookup.objectMappers().keySet()) {
-                if (Regex.simpleMatch(path, objectName)) {
+                // object type is not allowed in the routing paths
+                if (path.equals(objectName)) {
                     throw new IllegalArgumentException(
                         "All fields that match routing_path must be keywords with [time_series_dimension: true] "
                             + "and without the [script] parameter. ["

+ 16 - 2
server/src/test/java/org/elasticsearch/index/TimeSeriesModeTests.java

@@ -144,8 +144,22 @@ public class TimeSeriesModeTests extends MapperServiceTestCase {
         assertThat(e.getMessage(), equalTo("routing is forbidden on CRUD operations that target indices in [index.mode=time_series]"));
     }
 
-    public void testRoutingPathMatchesObject() {
-        Settings s = getSettings(randomBoolean() ? "dim.o" : "dim.*");
+    public void testRoutingPathMatchesObject() throws IOException {
+        Settings s = getSettings("dim.o*");
+        createMapperService(s, mapping(b -> {
+            b.startObject("dim").startObject("properties");
+            {
+                b.startObject("o").startObject("properties");
+                b.startObject("inner_dim").field("type", "keyword").field("time_series_dimension", true).endObject();
+                b.endObject().endObject();
+            }
+            b.startObject("dim").field("type", "keyword").field("time_series_dimension", true).endObject();
+            b.endObject().endObject();
+        }));
+    }
+
+    public void testRoutingPathEqualsObjectNameError() {
+        Settings s = getSettings("dim.o");
         Exception e = expectThrows(IllegalArgumentException.class, () -> createMapperService(s, mapping(b -> {
             b.startObject("dim").startObject("properties");
             {