Trying out the following query to get the values of 2 array fields and their corresponding lengths, the array values and the lengths don't match
Query:
GET my_index/_search
{
"_source": ["file_types", "link_to_file"],
"query": {
"bool": {
"filter": [
{
"term": {
"_id": "45t8724b811b590d54cc1925166a9cb5"
}
}
]
}
},
"script_fields": {
"file_types_len": {
"script": "doc['file_types'].length"
},
"link_to_file_len": {
"script": "doc['link_to_file'].length"
}
}
}
Result:
{
"_index": "my_index-150522",
"_type": "_doc",
"_id": "45t8724b811b590d54cc1925166a9cb5",
"_score": 0.0,
"_source": {
"link_to_file": [
"https://bucket.s3.amazonaws.com/abc123",
"https://bucket.s3.amazonaws.com/wer134"
],
"file_types": ["jpeg", "jpeg"]
},
"fields": {
"file_types_len": [1],
"link_to_file_len": [2]
}
}
Both the arrays are of length 2 according the values returned, but the length for one of the arrays is says 1. Why is this happening ?