Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ private static Script parseScript(Object config) {
Map<String,Object> configMap = (Map<String, Object>) config;
String script = null;
ScriptType type = null;
String lang = DEFAULT_SCRIPT_LANG;
String lang = null;
Map<String, Object> params = Collections.emptyMap();
for (Iterator<Map.Entry<String, Object>> itr = configMap.entrySet().iterator(); itr.hasNext();) {
Map.Entry<String, Object> entry = itr.next();
Expand Down Expand Up @@ -126,7 +126,15 @@ private static Script parseScript(Object config) {
}
assert type != null : "if script is not null, type should definitely not be null";

return new Script(type, lang, script, params);
if (type == ScriptType.STORED) {
if (lang != null) {
throw new IllegalArgumentException("lang cannot be specified for stored scripts");
}

return new Script(type, null, script, null, params);
} else {
return new Script(type, lang == null ? DEFAULT_SCRIPT_LANG : lang, script, params);
}
} else {
throw new IllegalArgumentException("Script value should be a String or a Map");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,3 +340,84 @@
source: if (ctx._source.user == "kimchy") {ctx.op = "index"} else {ctx.op = "junk"}

- match: { error.reason: 'Operation type [junk] not allowed, only [noop, index, delete] are allowed' }

---
"Update all docs with one deletion and one noop using a stored script":
- do:
index:
index: twitter
type: tweet
id: 1
body: { "level": 9, "last_updated": "2016-01-01T12:10:30Z" }
- do:
index:
index: twitter
type: tweet
id: 2
body: { "level": 10, "last_updated": "2016-01-01T12:10:30Z" }
- do:
index:
index: twitter
type: tweet
id: 3
body: { "level": 11, "last_updated": "2016-01-01T12:10:30Z" }
- do:
index:
index: twitter
type: tweet
id: 4
body: { "level": 12, "last_updated": "2016-01-01T12:10:30Z" }
- do:
indices.refresh: {}
- do:
put_script:
id: "my_update_script"
body: { "script": {"lang": "painless",
"source": "int choice = ctx._source.level % 3;
if (choice == 0) {
ctx._source.last_updated = '2016-01-02T00:00:00Z';
} else if (choice == 1) {
ctx.op = 'noop';
} else {
ctx.op = 'delete';
}" } }
- match: { acknowledged: true }

- do:
update_by_query:
refresh: true
index: twitter
body:
script:
id: "my_update_script"

- match: {updated: 2}
- match: {deleted: 1}
- match: {noops: 1}

- do:
search:
index: twitter
body:
query:
match:
last_updated: "2016-01-02T00:00:00Z"
- match: { hits.total: 2 }

- do:
search:
index: twitter
body:
query:
match:
last_updated: "2016-01-01T12:10:30Z"
- match: { hits.total: 1 }

- do:
search:
index: twitter
body:
query:
term:
level: 11
- match: { hits.total: 0 }