I am using Elasticsearch 5.5 and have an index with such mapping:
{
"my_index": {
"mappings": {
"my_type": {
"properties": {
"title": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"my_array": {
"properties": {
"array": {
"type": "float"
},
"length": {
"type": "long"
}
}
}
}
}
}
}
}
I would like to search by title and sort by first value from array. Also it would be great to set this first value to the _score field.
So, I've prepared such request:
GET my_index/my_type/_search
{
"query": {
"term": {
"title.keyword": "Shorts"
}
},
"sort" : {
"_script" : {
"type" : "number",
"script" : {
"lang": "painless",
"inline": "doc['my_array.array'][0]"
},
"order" : "asc"
}
}
}
Unfortunately it doesn't work. I feel something is missing or wrong.
doc['my_array.array'][0]?