Browse Source

reindex: gracefully handle when _source is disabled

Closes #17666
Nik Everett 9 years ago
parent
commit
0f9804b0e2

+ 2 - 2
docs/reference/mapping/fields/source-field.asciidoc

@@ -34,7 +34,8 @@ Users often disable the `_source` field without thinking about the
 consequences, and then live to regret it.  If the `_source` field isn't
 available then a number of features are not supported:
 
-* The <<docs-update,`update` API>>.
+* The <<docs-update,`update`>>, <<docs-update-by-query,`update_by_query`>>,
+and <<docs-reindex,`reindex`>> APIs.
 
 * On the fly <<search-request-highlighting,highlighting>>.
 
@@ -133,4 +134,3 @@ GET logs/event/_search
 
 <1> These fields will be removed from the stored `_source` field.
 <2> We can still search on this field, even though it is not in the stored `_source`.
-

+ 3 - 0
modules/reindex/src/main/java/org/elasticsearch/index/reindex/AbstractAsyncBulkIndexByScrollAction.java

@@ -86,6 +86,9 @@ public abstract class AbstractAsyncBulkIndexByScrollAction<
         Map<String, Object> scriptCtx = null;
 
         for (SearchHit doc : docs) {
+            if (doc.isSourceEmpty()) {
+                throw new IllegalArgumentException("[" + doc.index() + "][" + doc.type() + "][" + doc.id() + "] didn't store _source");
+            }
             IndexRequest index = buildIndexRequest(doc);
             copyMetadata(index, doc);
             if (script != null) {

+ 29 - 1
modules/reindex/src/test/resources/rest-api-spec/test/reindex/20_validation.yaml

@@ -157,6 +157,34 @@
         requests_per_second: ""
         body:
           source:
-            from: 1
+            index: test
+          dest:
+            index: dest
+
+---
+"reindex without source gives useful error message":
+  - do:
+      indices.create:
+        index: test
+        body:
+          mappings:
+            test:
+              _source:
+                enabled: false
+  - do:
+      index:
+        index:  test
+        type:   test
+        id:     1
+        body:   { age: 23 }
+  - do:
+      indices.refresh: {}
+
+  - do:
+      catch: /\[test\]\[test\]\[1\] didn't store _source/
+      reindex:
+        body:
+          source:
+            index: test
           dest:
             index: dest

+ 24 - 0
modules/reindex/src/test/resources/rest-api-spec/test/update_by_query/20_validation.yaml

@@ -53,3 +53,27 @@
       update_by_query:
         index: test
         requests_per_second: ''
+
+---
+"update_by_query without source gives useful error message":
+  - do:
+      indices.create:
+        index: test
+        body:
+          mappings:
+            test:
+              _source:
+                enabled: false
+  - do:
+      index:
+        index:  test
+        type:   test
+        id:     1
+        body:   { age: 23 }
+  - do:
+      indices.refresh: {}
+
+  - do:
+      catch: /\[test\]\[test\]\[1\] didn't store _source/
+      update_by_query:
+        index: test