I am using the following query to get the total unique values for the field website
-
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 -
{
"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 -
{
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 -
- The
aggregations
key is not present - 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.