reindex: gracefully handle when _source is disabled

Closes #17666
This commit is contained in:
Nik Everett 2016-04-11 19:05:09 -04:00
parent 39b914bd77
commit 0f9804b0e2
4 changed files with 58 additions and 3 deletions

View File

@ -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 consequences, and then live to regret it. If the `_source` field isn't
available then a number of features are not supported: 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>>. * 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. <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`. <2> We can still search on this field, even though it is not in the stored `_source`.

View File

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

View File

@ -157,6 +157,34 @@
requests_per_second: "" requests_per_second: ""
body: body:
source: 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: dest:
index: dest index: dest

View File

@ -53,3 +53,27 @@
update_by_query: update_by_query:
index: test index: test
requests_per_second: '' 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