dao
(olivier hodac)
December 18, 2023, 1:40pm
1
hello, I try to create a field that is an array of strings. Each string is the name of a field
example: I have docs like this:
{
a: 1, b:2, toto: 'processed', tata:'processed'
}
I want to create a field that will be servers:['toto', 'tata']
To do so, Il try this piece of code:
def servers = doc.entrySet().stream()
.filter(f->f.getValue().equals("processed"))
.map(f->f.getKey())
.collect(Collectors.toList());
emit(servers);
unfortunately, it does not work. even if I replace emit(servers);
with
emit("hardcoded");
Any clue or doc on that?
beste
dao
(olivier hodac)
December 18, 2023, 2:44pm
2
OK, I did try the dev console mode:
POST /_scripts/painless/_execute
{
"script": {
"source": """
doc.entrySet();
def servers = doc.get("xid").value;
emit(servers);
"""
},
"context": "keyword_field",
"context_setup": {
"index": "acars-history-000003",
"document": {
"hms": "processed",
"xid": "95fae05a-96dd-4be5-b642-8c1ac876353f"
}
}
}
and the response is clear:
{
"error": {
"root_cause": [
{
"type": "script_exception",
"reason": "runtime error",
"script_stack": [
"org.elasticsearch.server@8.10.0/org.elasticsearch.search.lookup.LeafDocLookup.entrySet(LeafDocLookup.java:251)",
"""doc.entrySet();
def """,
" ^---- HERE"
],
"script": " ...",
"lang": "painless",
"position": {
"offset": 8,
"start": 5,
"end": 25
}
}
],
"type": "script_exception",
"reason": "runtime error",
"script_stack": [
"org.elasticsearch.server@8.10.0/org.elasticsearch.search.lookup.LeafDocLookup.entrySet(LeafDocLookup.java:251)",
"""doc.entrySet();
def """,
" ^---- HERE"
],
"script": " ...",
"lang": "painless",
"position": {
"offset": 8,
"start": 5,
"end": 25
},
"caused_by": {
"type": "unsupported_operation_exception",
"reason": null
}
},
"status": 400
}
My question then:
1. what are the authorized methods in the context of a doc in a runtime script?
2. how to list the different doc entries?
system
(system)
Closed
January 15, 2024, 2:45pm
3
This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.