Răsfoiți Sursa

Fix _bulk api dynamic_templates and explicit op_type (#92687)

Joe Gallo 2 ani în urmă
părinte
comite
6850057676

+ 5 - 0
docs/changelog/92687.yaml

@@ -0,0 +1,5 @@
+pr: 92687
+summary: 'Fix `_bulk` api `dynamic_templates` and explicit `op_type`'
+area: Mapping
+type: bug
+issues: []

+ 66 - 5
rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/bulk/11_dynamic_templates.yml

@@ -24,20 +24,20 @@
       bulk:
         refresh: true
         body:
-          - index:
+          - create:
               _index: test_index
               _id: id_1
               dynamic_templates:
                 location: location
-          - { "location": [ -71.34, 41.12 ]}
+          - { "location": "41.12,-71.34"}
           - index:
               _index: test_index
               _id: id_2
               dynamic_templates:
                 location: location
-          - { "location": "41.12,-71.34"}
+          - { "location": [ -71.34, 41.12 ]}
   - match: { errors: false }
-  - match: { items.0.index.result: created }
+  - match: { items.0.create.result: created }
   - match: { items.1.index.result: created }
 
   - do:
@@ -65,7 +65,7 @@
               _index: test_index
               _id: id_3
           - { "my_location": "41.12,-71.34" } # matches the field name defined in the `my_location` template
-          - index:
+          - create:
               _index: test_index
               _id: id_4
               dynamic_templates:
@@ -169,3 +169,64 @@
   - match: { items.0.index.error.reason: "failed to parse field [foo] of type [keyword] in document with id 'id_11'. Preview of field's value: '{bar=hello world}'"}
   - match: { items.1.index.status: 201 }
   - match: { items.1.index.result: created }
+
+---
+"Dynamic templates with op_type":
+  - skip:
+      version: " - 8.6.99"
+      reason: "bug fixed in 8.7.0"
+
+  - do:
+      indices.create:
+        index: test_index
+        body:
+          mappings:
+            dynamic_templates:
+              - location:
+                  mapping:
+                    type: geo_point
+              - my_location:
+                  match: my*
+                  mapping:
+                    type: geo_point
+              - string:
+                  mapping:
+                    type: keyword
+  - do:
+      bulk:
+        refresh: true
+        body:
+          - index:
+              _index: test_index
+              _id: id_1
+              op_type: create
+              dynamic_templates:
+                location: location
+          - { "location": "41.12,-71.34"}
+          - index:
+              _index: test_index
+              _id: id_2
+              op_type: index
+              dynamic_templates:
+                location: location
+          - { "location": [ -71.34, 41.12 ]}
+  - match: { errors: false }
+  - match: { items.0.create.result: created }
+  - match: { items.1.index.result: created }
+
+  - do:
+      search:
+        index: test_index
+        body:
+          query:
+            geo_bounding_box:
+              location:
+                top_left:
+                  lat: 42
+                  lon: -72
+                bottom_right:
+                  lat: 40
+                  lon: -74
+  - match: { hits.total.value: 2 }
+  - match: { hits.hits.0._id: id_1 }
+  - match: { hits.hits.1._id: id_2 }

+ 1 - 0
server/src/main/java/org/elasticsearch/action/bulk/BulkRequestParser.java

@@ -357,6 +357,7 @@ public final class BulkRequestParser {
                                     .setIfSeqNo(ifSeqNo)
                                     .setIfPrimaryTerm(ifPrimaryTerm)
                                     .source(sliceTrimmingCarriageReturn(data, from, nextMarker, xContentType), xContentType)
+                                    .setDynamicTemplates(dynamicTemplates)
                                     .setRequireAlias(requireAlias),
                                 type
                             );

+ 1 - 1
server/src/main/java/org/elasticsearch/ingest/IngestCtxMap.java

@@ -22,7 +22,7 @@ import java.util.Map;
  * _index, _id and _routing must be a String or null
  * _version_type must be a lower case VersionType or null
  * _version must be representable as a long without loss of precision or null
- * _dyanmic_templates must be a map
+ * _dynamic_templates must be a map
  * _if_seq_no must be a long or null
  * _if_primary_term must be a long or null
  *