Open
Description
A runtime field in search cannot access a nested document inside a painless script, however the equivalent call in execute does access the nested document.
PUT /my-index-000001
{
"mappings": {
"properties": {
"cause": { "type": "nested" }
}
}
}
POST /my-index-000001/_doc/
{
"cause" : {
"bytes" : 1024
}
}
POST _scripts/painless/_execute
{
"script": {
"source": """
def actual_bytes = 0.0;
if (doc['cause.bytes'].size() != 0){
actual_bytes = doc['cause.bytes'].value;
}
emit(actual_bytes);
"""
},
"context": "double_field",
"context_setup": {
"index": "my-index-000001",
"document": {
"cause": {
"bytes": 1024
}
}
}
}
{
"result": [
1024
]
}
GET /my-index-000001/_search
{
"query": {
"match_all": {}
},
"fields": [
"causebytes"
],
"runtime_mappings": {
"causebytes": {
"type": "double",
"script": {
"source": """
def actual_bytes = 0.0;
if (doc['cause.bytes'].size() != 0){
actual_bytes = doc['cause.bytes'].value;
}
emit(actual_bytes);
"""
}
}
}
}
Result
{
"took": 6,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 1,
"relation": "eq"
},
"max_score": 1,
"hits": [
{
"_index": "my-index-000001",
"_id": "LPykooUBSMPtAbVHu_QN",
"_score": 1,
"_source": {
"cause": {
"bytes": 1024
}
},
"fields": {
"causebytes": [
0
],
"cause": [
{
"ytes": [
0
]
}
]
}
}
]
}
}
There also seems to be an issue with how hit.fields
for the original document is rendered in this case, but that's unrelated to this issue.