elastic / elasticsearch-js

Official Elasticsearch client library for Node.js
https://ela.st/js-client
Apache License 2.0
5.24k stars 727 forks source link

Property 'buckets' does not exist on type 'AggregationsCardinalityAggregate'. #2312

Open premtemp1 opened 1 month ago

premtemp1 commented 1 month ago

Hello, I have nodejs/typescipt function that I would like to get the aggregations. buckets result. However, I get the error Property 'buckets' does not exist on type 'AggregationsCardinalityAggregate'.

The basic code is console.log(res?.aggregations?.unique_val.buckets) which throws the error. I am able get the object using console.log(res?.aggregations?.unique_val)

can you please let me know why I cannot get any of key/val day within the aggregations?.unique_val object. Here is result json from the search

{
  "took": 7,
  "timed_out": false,
  "_shards": {
    "total": 1,
    "successful": 1,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": {
      "value": 10000,
      "relation": "gte"
    },
    "max_score": null,
    "hits": []
  },
  "aggregations": {
    "unique_industries": {
      "doc_count_error_upper_bound": 0,
      "sum_other_doc_count": 0,
      "buckets": [
        {
          "key": "technologies",
          "doc_count": 27965
        },
        {
          "key": "finance & accounting",
          "doc_count": 20727
        },
        {
          "key": "manufacturing & logistics",
          "doc_count": 18424
        },
        {
          "key": "sales & marketing",
          "doc_count": 17766
        },
        {
          "key": "life sciences",
          "doc_count": 15134
        },
        {
          "key": "engineering",
          "doc_count": 14805
        },
        {
          "key": "human resources",
          "doc_count": 12831
        },
        {
          "key": "business administration & operation",
          "doc_count": 12173
        }
      ]
    }
  }
}

Your Environment

JoshMock commented 1 month ago

You're looking for res?.aggregations?.unique_val but your response clearly shows res?.aggregations?.unique_industries. Is that a typo, or could that be your underlying issue?