# Queries not working with node js

**URL:** <https://discuss.elastic.co/t/queries-not-working-with-node-js/322590>\
**Category:** Elasticsearch\
**Created:** [January 6, 2023, 5:52am UTC](https://discuss.elastic.co/t/queries-not-working-with-node-js/322590 "2023-01-06T05:52:24Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hemabh\_Ravee\_Fox](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hemabh_ravee_fox/32/111494_2.png) [@Hemabh\_Ravee\_Fox](https://discuss.elastic.co/u/Hemabh_Ravee_Fox)\
**Post date:** [January 6, 2023, 5:52am UTC](https://discuss.elastic.co/t/queries-not-working-with-node-js/322590/1 "2023-01-06T05:52:24Z")

</div>

I am using the following query to get the total unique values for the field `website` -

```auto
GET events_test2/_search
{
  "size": 0,
  "aggs": {
    "unique_websites": {
      "terms": {
        "field": "website",
        "size": 1000
      }
    }
  }
}

```

This query is working fine when I run it from kibana console or postman, and has the following response -

```auto
{
    "took": 0,
    "timed_out": false,
    "_shards": {
        "total": 1,
        "successful": 1,
        "skipped": 0,
        "failed": 0
    },
    "hits": {
        "total": {
            "value": 8832,
            "relation": "eq"
        },
        "max_score": null,
        "hits": []
    },
    "aggregations": {
        "unique_websites": {
            "doc_count_error_upper_bound": 0,
            "sum_other_doc_count": 0,
            "buckets": [
                {
                    "key": "website6",
                    "doc_count": 4699
                },
                {
                    "key": "localhost:3000",
                    "doc_count": 3125
                },
                {
                    "key": "none",
                    "doc_count": 466
                },
                {
                    "key": "website5",
                    "doc_count": 166
                },
                {
                    "key": "website4",
                    "doc_count": 137
                },
                {
                    "key": "localhost:8000",
                    "doc_count": 132
                },
                {
                    "key": "localhost:3001",
                    "doc_count": 98
                },
                {
                    "key": "website3",
                    "doc_count": 4
                },
                {
                    "key": "website2",
                    "doc_count": 3
                },
                {
                    "key": "website1",
                    "doc_count": 2
                }
            ]
        }
    }
}

```

But when I make the same api call from inside my node js server, I get the following response -

```auto
{
  took: 0,
  timed_out: false,
  _shards: { total: 1, successful: 1, skipped: 0, failed: 0 },
  hits: {
    total: { value: 8832, relation: 'eq' },
    max_score: 1,
    hits: [
      [Object], [Object],
      [Object], [Object],
      [Object], [Object],
      [Object], [Object],
      [Object], [Object]
    ]
  }
}

```

I see two problems with this -

1. The `aggregations` key is not present
2. The size is not set to 0 since we're getting docs inside `hits.hits`

I was able to fix the size problem by passing it in the url as `events_test2/_search?size=0` but why is it not working from inside the body?

Can anyone please help me figure out what I'm doing wrong here?  
Thanks in advance.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [February 3, 2023, 5:53am UTC](https://discuss.elastic.co/t/queries-not-working-with-node-js/322590/2 "2023-02-03T05:53:07Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
