如何使用From / Size控制弹性搜索的聚合结果? [英] How to control the elasticsearch aggregation results with From / Size?

查看:486
本文介绍了如何使用From / Size控制弹性搜索的聚合结果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试在弹性搜索术语聚合中添加分页。在查询中,我们可以添加分页,如

  {
from:0,//添加开始控制分页
size:10,
query:{}
}

这很清楚,但是当我想为聚合添加分页时,我读了很多,但是找不到任何东西,我的代码看起来像这样,

  {
from:0,
size:0,
aggs:{
group_by_name:{
terms:{
field:name,
size:20
},
aggs :{
top_tag_hits:{
top_hits:{
size:1
}
}
}
}
}
}

有没有办法使用函数或任何方式创建分页其他建议?

解决方案

似乎你可能想要分区。 从docs:


有时,在单个请求/响应对中有太多唯一的条款要处理,所以它可以是有用的将分析分解成多个请求。这可以通过在查询时将字段的值分组为多个分区并在每个请求中仅处理一个分区来实现。


基本上你添加include:{partition:n,num_partitions:x} ,其中 n 是页面, x 是页数。



不幸的是,这个功能最近才被添加。如果标签可以在 GitHub Issue 上相信,产生了此功能,那么您将至少需要弹性5.2或更好。


I have been trying to add pagination in elasticsearch term aggregation. In query we can add the pagination like,

 {
    "from": 0, // to add the start to control the pagination
    "size": 10,
    "query": { } 
 }

this is pretty clear, but when I want to add pagination to aggregation, I read a lot about it, but I couldn't find anything, My code looks like this,

{
  "from": 0,
  "size": 0,
  "aggs": {
    "group_by_name": {
      "terms": {
        "field": "name",
        "size": 20
      },
      "aggs": {
        "top_tag_hits": {
          "top_hits": {
            "size": 1
          }
        }
      }
    }
  }
}

Is there any way to create pagination with a function or any other suggestions?

解决方案

Seems like you probably want partitions. From the docs:

Sometimes there are too many unique terms to process in a single request/response pair so it can be useful to break the analysis up into multiple requests. This can be achieved by grouping the field’s values into a number of partitions at query-time and processing only one partition in each request.

Basically you add "include": { "partition": n, "num_partitions": x },, where n is the page and x is the number of pages.

Unfortunately this feature was added fairly recently. If the tags can be believed on the GitHub Issue which spawned this feature, you'll need to be on at least Elasticsearch 5.2 or better.

这篇关于如何使用From / Size控制弹性搜索的聚合结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆