【问题标题】:Elastic search query Pagination help on Aggregations弹性搜索查询 聚合上的分页帮助
【发布时间】:2021-01-20 13:09:41
【问题描述】:

我已经尝试了以下关于聚合分页的查询,但无法正常工作。

我收到错误 "reason": "[40:7] [terms] unknown field [from], parser not found"

{
  "size": 0,
  "query": {
    "bool": {
      "must": [
        {
          "term": {
            "answer.keyword": "UNHANDLED"
          }
        },
        {
          "term": {
            "source.keyword": "QUAL2"
          }
        }
      ]
    }
  },
  "aggs": {
    "MyBuckets": {
      "terms": {
        "field": "question.keyword",
        "order": {
          "_count": "asc"
        },
        "size": "10"
      },
      "aggs": {
        "MyBuckets": {
          "terms": {
            "field": "timestamp",
            "order": {
              "_count": "asc"
            },
            "size": "3",
            "from": 8
          }
        }
      }
    }
  }
}

【问题讨论】:

  • 也许你应该显示你正在尝试的查询?

标签: elasticsearch elasticsearch-5 elasticsearch-aggregation


【解决方案1】:

仅支持size,您必须从聚合查询中删除参数from。 你可以试试partitions in the aggreagtion

试试下面的查询:

{
  "size": 0,
  "query": {
    "bool": {
      "must": [
        {
          "term": {
            "answer.keyword": "UNHANDLED"
          }
        },
        {
          "term": {
            "source.keyword": "QUAL2"
          }
        }
      ]
    }
  },
  "aggs": {
    "MyBuckets": {
      "terms": {
        "field": "question.keyword",
        "order": {
          "_count": "asc"
        },
        "size": "10"
      },
      "aggs": {
        "MyBuckets": {
          "terms": {
            "field": "timestamp",
            "order": {
              "_count": "asc"
            },
            "size": "3",
            "include": {
              "partition": 1,
              "num_partitions": 10
            }
          }
        }
      }
    }
  }
}

【讨论】:

  • 好的,谢谢。是否可以在分区中获得从 1 到 10、10 -11、11-20 等的分页。如果您不介意可以修改我的查询,请在 myquery 中添加分区聚合。我是弹性搜索的新手,请做必要的事情
  • @Prabhudas8703 请仔细阅读我的更新答案,如果这能解决您的问题,请告诉我?
  • 非常感谢。我有个疑问。 (Size:"3" &Partition :1, & num_partitions": 10)。如果我用这个逻辑运行,我会得到 3 输出。只是想知道那个 3 是在 1 到 10 范围之间?还是 1-3 范围? .....另外,如果我执行上面的查询,我只会得到问题关键字的记录,而不是因为时间戳没有使用上述逻辑执行。
  • @Prabhudas8703 能否分享一个包含timestamp 和question 字段的示例数据?
  • 我已经与您分享了示例数据。请检查以上一项
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-12-24
  • 1970-01-01
  • 1970-01-01
  • 2015-03-02
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多