Skip to content

Commit 81017be

Browse files
authored
Rename string_field script context to keyword_field (#71854)
Up until now, the name of the script contexts that runtime fields use was internal only. They recently got exposed through the painless execute API. This commit fixes the discrepancy between the field type used to define a runtime field of type keyword and the script context needed to simulate its corresponding script: string_field should be keyword_field.
1 parent f1e9493 commit 81017be

File tree

5 files changed

+12
-24
lines changed

5 files changed

+12
-24
lines changed
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# Side Public License, v 1.
77
#
88

9-
# The whitelist for string-valued runtime fields
9+
# The whitelist for keyword runtime fields
1010

1111
# These two whitelists are required for painless to find the classes
1212
class org.elasticsearch.script.StringFieldScript @no_import {

modules/lang-painless/src/test/java/org/elasticsearch/painless/action/PainlessExecuteApiTests.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ public void testLongFieldExecutionContext() throws IOException {
242242
assertArrayEquals((long[])response.getResult(), new long[] {-1000L, 0L, 1L, 3L, 10L, 20000000000L});
243243
}
244244

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

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

259259
contextSetup = new Request.ContextSetup("index", new BytesArray("{}"), new MatchAllQueryBuilder());
260260
contextSetup.setXContentType(XContentType.JSON);
261261
request = new Request(new Script(ScriptType.INLINE, "painless",
262262
"emit(\"test\"); emit(\"baz was not here\"); emit(\"Data\"); emit(\"-10\"); emit(\"20\"); emit(\"9\");",
263-
emptyMap()), "string_field", contextSetup);
263+
emptyMap()), "keyword_field", contextSetup);
264264
response = innerShardOperation(request, scriptService, indexService);
265265
assertArrayEquals((String[])response.getResult(), new String[] {"-10", "20", "9", "Data", "baz was not here", "test"});
266266
}

modules/lang-painless/src/yamlRestTest/resources/rest-api-spec/test/painless/120_stored_scripts.yml

+3-7
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,6 @@
1616
---
1717

1818
"Test runtime field contexts not allowed as stored script":
19-
- skip:
20-
version: " - 8.99.99"
21-
reason: Script while the string_field script context gets renamed
22-
2319
- do:
2420
catch: bad_request
2521
put_script:
@@ -107,13 +103,13 @@
107103
- do:
108104
catch: bad_request
109105
put_script:
110-
id: string_field_script
111-
context: string_field
106+
id: keyword_field_script
107+
context: keyword_field
112108
body:
113109
script:
114110
source: "'should not reach compilation or this will error''"
115111
lang: painless
116112

117113
- match: { error.root_cause.0.type: "illegal_argument_exception" }
118114
- match: { error.type: "illegal_argument_exception" }
119-
- match: { error.caused_by.reason: "cannot store a script for context [string_field]" }
115+
- match: { error.caused_by.reason: "cannot store a script for context [keyword_field]" }

modules/lang-painless/src/yamlRestTest/resources/rest-api-spec/test/painless/70_execute_painless_scripts.yml

+4-12
Original file line numberDiff line numberDiff line change
@@ -265,36 +265,28 @@ setup:
265265
- match: { result: [ -90, 0, 20, 20, 35 ] }
266266

267267
---
268-
"Execute with string field context (single-value)":
269-
- skip:
270-
version: " - 8.99.99"
271-
reason: Script while the script context gets renamed
272-
268+
"Execute with keyword field context (single-value)":
273269
- do:
274270
scripts_painless_execute:
275271
body:
276272
script:
277273
source: "emit(doc['point'].value.lat.toString().substring(0, 5));"
278-
context: "string_field"
274+
context: "keyword_field"
279275
context_setup:
280276
document:
281277
point: "30.2,40.2"
282278
index: "my-index"
283279
- match: { result.0: "30.19" }
284280

285281
---
286-
"Execute with string field context (multi-value)":
287-
- skip:
288-
version: " - 8.99.99"
289-
reason: Script while the script context gets renamed
290-
282+
"Execute with keyword field context (multi-value)":
291283
- do:
292284
scripts_painless_execute:
293285
body:
294286
script:
295287
source: "emit(doc['point'].value.lat.toString().substring(0, 5));
296288
emit(doc['point'].value.lon.toString().substring(0, 5) + 'test');"
297-
context: "string_field"
289+
context: "keyword_field"
298290
context_setup:
299291
document:
300292
point: "30.2,40.2"

server/src/main/java/org/elasticsearch/script/StringFieldScript.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public abstract class StringFieldScript extends AbstractFieldScript {
2424
*/
2525
public static final long MAX_CHARS = 1024 * 1024;
2626

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

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

0 commit comments

Comments
 (0)