Scripting: fill in get contexts REST API#48319
Conversation
Updates response for `GET /_script_context`, returning a `contexts`
object with a list of context description objects. The description
includes the context name and a list of methods available. The
methods list has the signature for the `execute` mathod and any
getters. eg.
```
{
"contexts": [
{
"name" : "moving-function",
"methods" : [
{
"name" : "execute",
"return_type" : "double",
"params" : [
{
"type" : "java.util.Map",
"name" : "params"
},
{
"type" : "double[]",
"name" : "values"
}
]
}
]
},
{
"name" : "number_sort",
"methods" : [
{
"name" : "execute",
"return_type" : "double",
"params" : [ ]
},
{
"name" : "getDoc",
"return_type" : "java.util.Map",
"params" : [ ]
},
{
"name" : "getParams",
"return_type" : "java.util.Map",
"params" : [ ]
},
{
"name" : "get_score",
"return_type" : "double",
"params" : [ ]
}
]
},
...
]
}
```
fixes: elastic#47411
|
Pinging @elastic/es-core-infra (:Core/Infra/Scripting) |
…e/47411-painless-script-context-rest_2_exec_getters_merge
…different contexts
jdconrad
left a comment
There was a problem hiding this comment.
@stu-elastic Thank you for the work here. This looks good to me, and I don't have any other comments as we've been chatting throughout. I'm very pleased with the changes to the structure of the response.
...a/org/elasticsearch/action/admin/cluster/storedscripts/ScriptMethodInfoSerializingTests.java
Show resolved
Hide resolved
rjernst
left a comment
There was a problem hiding this comment.
Thanks for getting this up so quickly, and especially for the extensive serialization tests. I have a few comments.
| - match: { contexts.number_sort: {} } | ||
| - match: { contexts.processor_conditional: {} } | ||
| - match: { contexts.score: {} } | ||
| - match: { contexts.script_heuristic: {} } |
There was a problem hiding this comment.
We seem to have lost a lot of builtin contexts here?
There was a problem hiding this comment.
Unfortunately the change to list made performing the comparison after this differ in different contexts. This will be addressed when I address your next comment.
There was a problem hiding this comment.
I've cut this test down to make it more reliable, now just checking that at least one context exists, it has a execute method with return value field.
| - match: { contexts.0.name: "aggregation_selector" } | ||
| - match: { contexts.0.methods: [{"name": "execute", "return_type": "boolean", "params": []}, {"name": "getParams", "return_type": "java.util.Map", "params": []}] } | ||
|
|
||
| - match: { contexts.1.name: "aggs" } |
There was a problem hiding this comment.
Why is this structure changed to a list of objects? The order of these do not matter, so I don't think it should be a list.
There was a problem hiding this comment.
Agreed, I was going with ease of using our existing parsing primitives, which have a difficulty addressing dynamic keys. Will take a pass at making it a map and we'll see how ugly it gets.
There was a problem hiding this comment.
It got pretty ugly. Per offline conversation, we're gonna keep this structure for now.
There was a problem hiding this comment.
It got pretty ugly doing the fragment parsing and made testing difficult. Per offline conversation, we're gonna keep this structure for now.
...main/java/org/elasticsearch/action/admin/cluster/storedscripts/GetScriptContextResponse.java
Outdated
Show resolved
Hide resolved
...main/java/org/elasticsearch/action/admin/cluster/storedscripts/GetScriptContextResponse.java
Outdated
Show resolved
Hide resolved
...main/java/org/elasticsearch/action/admin/cluster/storedscripts/GetScriptContextResponse.java
Outdated
Show resolved
Hide resolved
server/src/main/java/org/elasticsearch/script/ScriptContextInfo.java
Outdated
Show resolved
Hide resolved
server/src/main/java/org/elasticsearch/script/ScriptContextInfo.java
Outdated
Show resolved
Hide resolved
|
|
||
| import static org.elasticsearch.common.xcontent.ConstructingObjectParser.constructorArg; | ||
|
|
||
| public class ScriptContextInfo implements ToXContentObject, Writeable { |
There was a problem hiding this comment.
I still think the naming is quite confusing here, but I can live with it for now since this is an internal api and thus these can be changed without backcompat.
There was a problem hiding this comment.
Happy to change when we can think of a better name.
The reason I chose this name is ScriptContextInfo is this is a description of a ScriptContext and appending Info is the naming convention we have, see PainlessContextInfo.
...a/org/elasticsearch/action/admin/cluster/storedscripts/ScriptMethodInfoSerializingTests.java
Outdated
Show resolved
Hide resolved
* Scripting: fill in get contexts REST API
Updates response for `GET /_script_context`, returning a `contexts`
object with a list of context description objects. The description
includes the context name and a list of methods available. The
methods list has the signature for the `execute` mathod and any
getters. eg.
```
{
"contexts": [
{
"name" : "moving-function",
"methods" : [
{
"name" : "execute",
"return_type" : "double",
"params" : [
{
"type" : "java.util.Map",
"name" : "params"
},
{
"type" : "double[]",
"name" : "values"
}
]
}
]
},
{
"name" : "number_sort",
"methods" : [
{
"name" : "execute",
"return_type" : "double",
"params" : [ ]
},
{
"name" : "getDoc",
"return_type" : "java.util.Map",
"params" : [ ]
},
{
"name" : "getParams",
"return_type" : "java.util.Map",
"params" : [ ]
},
{
"name" : "get_score",
"return_type" : "double",
"params" : [ ]
}
]
},
...
]
}
```
fixes: elastic#47411
Updates response for `GET /_script_context`, returning a `contexts`
object with a list of context description objects. The description
includes the context name and a list of methods available. The
methods list has the signature for the `execute` mathod and any
getters. eg.
```
{
"contexts": [
{
"name" : "moving-function",
"methods" : [
{
"name" : "execute",
"return_type" : "double",
"params" : [
{
"type" : "java.util.Map",
"name" : "params"
},
{
"type" : "double[]",
"name" : "values"
}
]
}
]
},
{
"name" : "number_sort",
"methods" : [
{
"name" : "execute",
"return_type" : "double",
"params" : [ ]
},
{
"name" : "getDoc",
"return_type" : "java.util.Map",
"params" : [ ]
},
{
"name" : "getParams",
"return_type" : "java.util.Map",
"params" : [ ]
},
{
"name" : "get_score",
"return_type" : "double",
"params" : [ ]
}
]
},
...
]
}
```
fixes: #47411
Updates response for
GET /_script_context, returning acontextsobject with a list of context description objects. The description
includes the context name and a list of methods available. The
methods list has the signature for the
executemathod and anygetters. eg.
fixes: #47411