这是我使用以下查询在索引文档中对名为“age”的字段进行排序的查询:
{
"query": {
"match_all": {}
},
"sort": {
"_script": {
"script": "doc[\"age\"].value",
"lang": "groovy",
"type": "number",
"order": "asc"
}
}
}
以下是回复:
{
"hits": {
"total": 3,
"max_score": null,
"hits": [
{
"_index": "monthdata",
"_type": "monthdata",
"_id": "121224354",
"_score": null,
"_source": {
"profile": {
"name": "Merlin",
"age": 25,
"sex": "female"
}
},
"sort": [
25
]
}
]
}
}
我需要完成的是,我不希望文档数据与它一起显示,而只是排序数组。
我尝试在查询中添加"size" : 0
,但它会使整个匹配消失。
如何才能只显示排序数组?
答案 0 :(得分:0)
我认为你不能那样做。排序的目的是对文档进行排序,如果您取出文档,则会留下值列表?没有意义。
您可以采取哪些措施来减轻结果,指定您想要查看的fields
。如果您未指定任何fields
,则不会返回任何内容,但排序值将为:
{
"query": {
"match_all": {}
},
"sort": {
"_script": {
"script": "doc[\"age\"].value",
"lang": "groovy",
"type": "number",
"order": "asc"
}
},
"fields": []
}
会给你
{
"hits": {
"total": 3,
"max_score": null,
"hits": [
{
"_index": "monthdata",
"_type": "monthdata",
"_id": "121224354",
"_score": null,
"sort": [
25
]
},
{
"_index": "monthdata",
"_type": "monthdata",
"_id": "121224352",
"_score": null,
"sort": [
32
]
},
{
"_index": "monthdata",
"_type": "monthdata",
"_id": "121224355",
"_score": null,
"sort": [
35
]
}
]
}
}
答案 1 :(得分:0)
设置"尺寸"为零不会在此上下文中工作,因为size指定要获取并显示在结果中的文档数。另一种方法是在脚本中设置fields属性,如下所示:
contribute_to_class
这将为您提供所需的结果。