当字段中的多个值时,如何更改项汇总的默认值大小参数?

发布于 2025-01-27 10:05:35 字数 1790 浏览 1 评论 0原文

根据Elasticsearch 文档,“术语”聚合以最多的文档返回前十个条款。在我的特殊情况下,我要发送14个必需的值。

{
  "size": 0,
  "aggs": {
    "counts": {
      "filters": {
        "filters": {
          "respondents": {
            "bool": {
              "should": [
                {
                  "terms": {
                    "my_field": [
                      "1",
                      "2",
                      "3",
                      "4",
                      "5",
                      "6",
                      "7",
                      "8",
                      "9",
                      "10",
                      "11",
                      "12",
                      "13",
                      "14"
                    ],
                    "size": 20 // this is not working
                  }
                }
              ]
            }
          }
        }
      }
    }
  }
}

但是其中4个没有退还。 如果我与“ my_field”属性并排添加“大小”属性,那么返回错误:

{
  "error": {
    "root_cause": [
      {
        "type": "parsing_exception",
        "reason": "[terms] query does not support [size]",
        "line": 40,
        "col": 49
      }
    ],
    "type": "parsing_exception",
    "reason": "[terms] query does not support [size]",
    "line": 40,
    "col": 49
  },
  "status": 400
}

我该怎么办才能获得所有14个必需的值?

According to the Elasticsearch documentation, the "terms" aggregation returns the top ten terms with the most documents. In my particular case, I am sending 14 required values to count on.

{
  "size": 0,
  "aggs": {
    "counts": {
      "filters": {
        "filters": {
          "respondents": {
            "bool": {
              "should": [
                {
                  "terms": {
                    "my_field": [
                      "1",
                      "2",
                      "3",
                      "4",
                      "5",
                      "6",
                      "7",
                      "8",
                      "9",
                      "10",
                      "11",
                      "12",
                      "13",
                      "14"
                    ],
                    "size": 20 // this is not working
                  }
                }
              ]
            }
          }
        }
      }
    }
  }
}

But then 4 of them are not returned.
If I add the "size" property side by side with "my_field" property, then an error is returned:

{
  "error": {
    "root_cause": [
      {
        "type": "parsing_exception",
        "reason": "[terms] query does not support [size]",
        "line": 40,
        "col": 49
      }
    ],
    "type": "parsing_exception",
    "reason": "[terms] query does not support [size]",
    "line": 40,
    "col": 49
  },
  "status": 400
}

What should I do to be able to get all 14 required values?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

静水深流 2025-02-03 10:05:35

您缺少术语聚合和filter聚合不支持size> size param,因为它将在聚合查询上应用过滤器。

{
  "size": 0,
  "aggs": {
    "counts": {
      "filters": {
        "filters": {
          "respondents": {
            "bool": {
              "should": [
                {
                  "terms": {
                    "my_field": [
                      "1",
                      "2",
                      "3",
                      "4",
                      "5",
                      "6",
                      "7",
                      "8",
                      "9",
                      "10",
                      "11",
                      "12",
                      "13",
                      "14"
                    ]
                  }
                }
              ]
            }
          }
        }
      },
      "aggs": {
        "count": {
          "terms": {
            "field": "my_field",
            "size": 20
          }
        }
      }
    }
  }
}

You are missing term aggregation and filter aggregation doesn't support size param as it will apply filter on aggregation query.

{
  "size": 0,
  "aggs": {
    "counts": {
      "filters": {
        "filters": {
          "respondents": {
            "bool": {
              "should": [
                {
                  "terms": {
                    "my_field": [
                      "1",
                      "2",
                      "3",
                      "4",
                      "5",
                      "6",
                      "7",
                      "8",
                      "9",
                      "10",
                      "11",
                      "12",
                      "13",
                      "14"
                    ]
                  }
                }
              ]
            }
          }
        }
      },
      "aggs": {
        "count": {
          "terms": {
            "field": "my_field",
            "size": 20
          }
        }
      }
    }
  }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文