Skip to content

Rename string_field script context to keyword_field #71854

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
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 @@ -6,7 +6,7 @@
# Side Public License, v 1.
#

# The whitelist for string-valued runtime fields
# The whitelist for keyword runtime fields

# These two whitelists are required for painless to find the classes
class org.elasticsearch.script.StringFieldScript @no_import {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ public void testLongFieldExecutionContext() throws IOException {
assertArrayEquals((long[])response.getResult(), new long[] {-1000L, 0L, 1L, 3L, 10L, 20000000000L});
}

public void testStringFieldExecutionContext() throws IOException {
public void testKeywordFieldExecutionContext() throws IOException {
ScriptService scriptService = getInstanceFromNode(ScriptService.class);
IndexService indexService = createIndex("index", Settings.EMPTY, "doc", "test_point", "type=geo_point");

Expand All @@ -252,15 +252,15 @@ public void testStringFieldExecutionContext() throws IOException {
Request request = new Request(new Script(ScriptType.INLINE, "painless",
"emit(doc['test_point'].value.lat.toString().substring(0, 5)); " +
"emit(doc['test_point'].value.lon.toString().substring(0, 5));", emptyMap()),
"string_field", contextSetup);
"keyword_field", contextSetup);
Response response = innerShardOperation(request, scriptService, indexService);
assertArrayEquals((String[])response.getResult(), new String[] {"30.19", "40.19"});

contextSetup = new Request.ContextSetup("index", new BytesArray("{}"), new MatchAllQueryBuilder());
contextSetup.setXContentType(XContentType.JSON);
request = new Request(new Script(ScriptType.INLINE, "painless",
"emit(\"test\"); emit(\"baz was not here\"); emit(\"Data\"); emit(\"-10\"); emit(\"20\"); emit(\"9\");",
emptyMap()), "string_field", contextSetup);
emptyMap()), "keyword_field", contextSetup);
response = innerShardOperation(request, scriptService, indexService);
assertArrayEquals((String[])response.getResult(), new String[] {"-10", "20", "9", "Data", "baz was not here", "test"});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,13 @@
- do:
catch: bad_request
put_script:
id: string_field_script
context: string_field
id: keyword_field_script
context: keyword_field
body:
script:
source: "'should not reach compilation or this will error''"
lang: painless

- match: { error.root_cause.0.type: "illegal_argument_exception" }
- match: { error.type: "illegal_argument_exception" }
- match: { error.caused_by.reason: "cannot store a script for context [string_field]" }
- match: { error.caused_by.reason: "cannot store a script for context [keyword_field]" }
Original file line number Diff line number Diff line change
Expand Up @@ -265,28 +265,28 @@ setup:
- match: { result: [ -90, 0, 20, 20, 35 ] }

---
"Execute with string field context (single-value)":
"Execute with keyword field context (single-value)":
- do:
scripts_painless_execute:
body:
script:
source: "emit(doc['point'].value.lat.toString().substring(0, 5));"
context: "string_field"
context: "keyword_field"
context_setup:
document:
point: "30.2,40.2"
index: "my-index"
- match: { result.0: "30.19" }

---
"Execute with string field context (multi-value)":
"Execute with keyword field context (multi-value)":
- do:
scripts_painless_execute:
body:
script:
source: "emit(doc['point'].value.lat.toString().substring(0, 5));
emit(doc['point'].value.lon.toString().substring(0, 5) + 'test');"
context: "string_field"
context: "keyword_field"
context_setup:
document:
point: "30.2,40.2"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public abstract class StringFieldScript extends AbstractFieldScript {
*/
public static final long MAX_CHARS = 1024 * 1024;

public static final ScriptContext<Factory> CONTEXT = newContext("string_field", Factory.class);
public static final ScriptContext<Factory> CONTEXT = newContext("keyword_field", Factory.class);

@SuppressWarnings("unused")
public static final String[] PARAMETERS = {};
Expand Down