Count using a query
omundy opened this issue · comments
Owen Mundy commented
Looking at the source code it appears there is no way to count with a query? Or am I doing something wrong? Trying to use this:
var options = {
_index : 'cats',
_type : 'cat',
body: {
"query": {
"geo_bounding_box": {
"location": {
"top_left": {
"lat": 43,
"lon": -72
},
"bottom_right": {
"lat": 40,
"lon": -74
}
}
}
}
}
}
this.es.count(options,function (err, data) {
console.log(data);
});
To run this:
GET cats/_count
{
"query": {
"geo_bounding_box": {
"location": {
"top_left": {
"lat": 43,
"lon": -72
},
"bottom_right": {
"lat": 40,
"lon": -74
}
}
}
}
}
Owen Mundy commented
Scratch that, I now see this is possible. Thanks.
this.es.search({
search_type : 'count'
}, {
"query": {
"geo_bounding_box": {
"location": {
"top_left": {
"lat": 43,
"lon": -72
},
"bottom_right": {
"lat": 40,
"lon": -74
}
}
}
}
}, function (err, data) {
console.log(data);
});
Joshua Thomas commented
@omundy - thank you for the report... noticed there is also missing documentation for the count
method (which accepts an optional query
parameter, but this is not clearly noted in the docs): https://github.com/ncb000gt/node-es#count
Owen Mundy commented
Sweet, thanks.
Joshua Thomas commented
@omundy - I've updated the docs now, but this should work as well (modified your original code example slightly):
var options = {
_index : 'cats',
_type : 'cat'
};
var query = {
"query": {
"geo_bounding_box": {
"location": {
"top_left": {
"lat": 43,
"lon": -72
},
"bottom_right": {
"lat": 40,
"lon": -74
}
}
}
}
}
};
this.es.count(options, query, function (err, data) {
console.log(data);
});
Joshua Thomas commented
Closing issue as resolved - thank you @omundy !