我正在使用 Elasticsearch 5.5,并且有一个具有如下映射的索引:
{
"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"
}
}
}
}
}
}
}
}
我希望能够按照标题搜索,并按照数组中的第一个值进行排序。同时,将这个第一个值设置为_score
字段是非常好的。
因此,我已经准备了这样的请求:
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"
}
}
}
很不幸,它不能正常工作。我感觉缺少了些什么或有问题。
doc['my_array.array'][0]
是否有效? - Uladzislau Kaminski