【发布时间】:2017-11-01 01:22:34
【问题描述】:
我正在使用 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"
}
}
}
不幸的是,它不起作用。我觉得有什么遗漏或错误。
【问题讨论】:
-
它给出了什么错误?
-
@HatimStovewala 没有错误,但是顺序错误
-
能否提供一些示例文件和回复?您期望在响应中包含什么以及实际上是什么?谢谢。
-
@NikolayVasiliev 有这样的请求:GET my_index/my_type/_search { "sort" : { "_script" : { "type" : "number", "script" : { "lang": "painless ", "inline": "doc['embeddings.array'][0]" }, "order" : "asc" } } } 回复是jsonblob.com/05e5893a-be1c-11e7-9ae8-cdd8d94a615d
-
这是访问数组
doc['my_array.array'][0]的第一个元素的有效方法吗?
标签: elasticsearch