我有一个elasticsearch搜索查询,它以分页的方式获取文档,如下所示:
{
"from" : 5, "size" : 2,
"sort" : [
{ "title" : {"order" : "asc"}}
],
"query" : {
"match_all": {}
},
"_source": ["title"]
}我想让from和size返回到ES的响应中,这个响应目前还没有从上面的查询中返回。任何指针都会非常有用。
发布于 2016-09-08 03:50:35
ES当前不返回在请求中发送的分页参数。你得破解它..。或者提交一个特征请求
您可以使用命名查询在几乎所有查询中传递这些信息,但是,您需要等到ES 5才能使match_all支持命名查询:
{
"from" : 5, "size" : 2,
"sort" : [
{ "title" : {"order" : "asc"}}
],
"query" : {
"match_all": {"_name": "5:2"} <--- name the query with the from/size params
},
"_source": ["title"]
}在响应中,您将得到"5:2",您可以解析它来确定from和size是什么。
"hits": {
"total": 1,
"max_score": 1,
"hits": [
{
"_index": "test",
"_type": "test",
"_id": "1",
"_score": 1,
"_source": {
"test": "test"
},
"matched_queries": [ <--- you can find from/size here
"5:2"
]
}
]
}https://stackoverflow.com/questions/39381404
复制相似问题