【问题标题】:Can I do a query that has both distinct and field and pagination it in ElasticSearch?我可以在 ElasticSearch 中进行同时具有不同字段和分页的查询吗?
【发布时间】:2021-10-29 22:19:06
【问题描述】:

区分字段并在 ElasticSearch 中实现分页的查询。我知道这些问题是分开实现的,但我们搜索了一个同时实现两个功能的解决方案。我附上了我们尝试使用它们的代码。 1. 仅实现分页:

POST myIndex/_search
{
  "from": 2,
  "size": 5,
  .
  .
  .
}

2.在我的查询中实现不同的一个字段

POST myIndex/_search
{
  "size": 0,
  "aggs": {
    "myField": {
      "terms": {
        "field": "name’s of my field",
        "size": 10000
      }
    }
  }
.
.
.
}

3.同时实现不同的字段和分页

POST myIndex/_search
{
  "from":2 
  "size": 5,
  "aggs": {
    "myField": {
      "terms": {
        "field": "name’s of my field",
        "size": 10000
      }
    }
  }
.
.
.
}
  1. 如您所见,当我们尝试同时使用 distinct 和 pagination 时,我们无法更改第一个大小的值(在 distinct 字段中,第一个值必须为零)并且第二个值不起作用。我也尝试使用分区,但我没有任何结果。
POST myIndex/_search
{
  "from":2 
  "size": 5,
  "aggs": {
    "myField": {
      "terms": {
        "field": "name’s of my field",
        "include": {
              "partition": 0,
              "num_partitions": 20
            },
        "size": 10000
      }
    }
  }
.
.
.
}

【问题讨论】:

    标签: elasticsearch pagination distinct-values


    【解决方案1】:

    你可以试试弹性搜索collapsing

    GET index-name/_search
    {
      "collapse": {
        "field": "field-name"
      },
      "from":0,
      "size": 5
    }
    

    用于聚合中的分页

    检查这个Need pagination on Aggreration Groupping Elastic search

    【讨论】:

    • 我运行这段代码但返回错误:{ "error" : { "root_cause" : [ { "type" : "parsing_exception", "reason" : "request does not support [collapse]", "line" : 2, "col" : 3 } ], "type" : "parsing_exception", "reason" : "request does not support [collapse]", "line" : 2, "col" : 3 }, "status" : 400 }
    • @s.h.moghaddasi 你的弹性搜索版本是什么
    猜你喜欢
    • 1970-01-01
    • 2022-12-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多