Javascript, where's my output?


#1

Hi guys.

Trying to do some searching via javascript to which I'm pretty noob. But I have this request done via curl:

user@localhost /tmp $ curl -XGET 192.168.20.145:9500/_search?pretty -d'
{ "size": 0,"query": {"filtered": {"query": {"query_string": {"query": "event:"Capture"","analyze_wildcard": true}},"filter": {"bool": {"must": [{
"range": {
"@timestamp": {
"gte": 1448146800000,
"lte": 1448751599999,
"format": "epoch_millis"
}
}
}
],
"must_not": []
}
}
}
},
"aggs": {
"2": {
"date_histogram": {
"field": "@timestamp",
"interval": "1d",
"time_zone": "Europe/Berlin",
"min_doc_count": 1,
"extended_bounds": {
"min": 1448146800000,
"max": 1448751599999
}
}
}
}
}'
{
"took" : 34489,
"timed_out" : false,
"_shards" : {
"total" : 281,
"successful" : 281,
"failed" : 0
},
"hits" : {
"total" : 3877723,
"max_score" : 0.0,
"hits" : [ ]
},
"aggregations" : {
"2" : {
"buckets" : [ {
"key_as_string" : "2015-11-22T00:00:00.000+01:00",
"key" : 1448146800000,
"doc_count" : 462396
}, {
"key_as_string" : "2015-11-23T00:00:00.000+01:00",
"key" : 1448233200000,
"doc_count" : 621186
}, {
"key_as_string" : "2015-11-24T00:00:00.000+01:00",
"key" : 1448319600000,
"doc_count" : 600470
}, {
"key_as_string" : "2015-11-25T00:00:00.000+01:00",
"key" : 1448406000000,
"doc_count" : 613689
}, {
"key_as_string" : "2015-11-26T00:00:00.000+01:00",
"key" : 1448492400000,
"doc_count" : 651160
}, {
"key_as_string" : "2015-11-27T00:00:00.000+01:00",
"key" : 1448578800000,
"doc_count" : 446081
}, {
"key_as_string" : "2015-11-28T00:00:00.000+01:00",
"key" : 1448665200000,
"doc_count" : 482741
} ]
}
}
}

Gives me some buckets as I want. Then I have the same search done via javascript in node-js:

var elasticsearch = require('elasticsearch');
var client = new elasticsearch.Client({
host: '192.168.20.145:9500',
log: 'trace'
});

client.search({
"size": 0,"query": {"filtered": {"query": {"query_string": {"query": "event:"Capture"","analyze_wildcard": true}},"filter": {"bool": {"must": [{
"range": {
"@timestamp": {
"gte": 1448146800000,
"lte": 1448751599999,
"format": "epoch_millis"
}
}
}
],
"must_not": []
}
}
}
},
"aggs": {
"2": {
"date_histogram": {
"field": "@timestamp",
"interval": "1d",
"time_zone": "Europe/Berlin",
"min_doc_count": 1,
"extended_bounds": {
"min": 1448146800000,
"max": 1448751599999
}
}
}
}
}).then(function (resp) {
var hits = resp.hits.hits;
}, function (err) {
console.trace(err.message);
});
Running that in node:
root@mgp-es-101 opt # node test2.js
Elasticsearch INFO: 2015-12-06T14:36:50Z
Adding connection to http://192.168.20.145:9500/

Elasticsearch DEBUG: 2015-12-06T14:36:50Z
starting request { method: 'POST',
path: '/_search',
query:
{ size: 0,
query: { filtered: [Object] },

var elasticsearch = require('elasticsearch');
aggs: { '2': [Object] } } }

Elasticsearch TRACE: 2015-12-06T14:36:50Z
-> POST http://192.168.20.145:9500/_search?size=0&query=&aggs=

<- 200
{
"took": 4,
"timed_out": false,
"_shards": {
"total": 281,
"successful": 281,
"failed": 0
},
"hits": {
"total": 553273927,
"max_score": 0,
"hits": []
}
}

Where are my buckets?


(system) #2