Comparing version 0.1.2 to 0.2.0
var elasticsearch = require('elasticsearch'); | ||
var helpers = require('./helpers'); | ||
var isArray = require('isarray'); | ||
@@ -64,3 +64,3 @@ var Elasto = { | ||
if (helpers.isArray(value)) { | ||
if (isArray(value)) { | ||
condition.terms = {}; | ||
@@ -159,3 +159,3 @@ condition.terms[key] = value; | ||
if (helpers.isArray(keys)) { | ||
if (isArray(keys)) { | ||
fields = keys; | ||
@@ -181,3 +181,3 @@ } else { | ||
if (key && helpers.isArray(interval)) { | ||
if (key && isArray(interval)) { | ||
var range = {}; | ||
@@ -340,2 +340,15 @@ range.range = {}; | ||
}; | ||
/** | ||
* Get the number of documents matching the query | ||
* @return Promise | ||
* @example | ||
* query.count().then(function(res) { | ||
* | ||
* }); | ||
*/ | ||
this.count = function() { | ||
var query = this._buildQuery(); | ||
return client.count(query); | ||
}; | ||
} | ||
@@ -342,0 +355,0 @@ |
{ | ||
"name": "elasto", | ||
"version": "0.1.2", | ||
"version": "0.2.0", | ||
"description": "ElasticSearch client", | ||
@@ -10,3 +10,4 @@ "main": "index", | ||
"dependencies": { | ||
"elasticsearch": "^3.0.1" | ||
"elasticsearch": "^3.0.1", | ||
"isarray": "0.0.1" | ||
}, | ||
@@ -13,0 +14,0 @@ "devDependencies": { |
@@ -255,2 +255,14 @@ # Elasto [![Circle CI](https://circleci.com/gh/StreetHub/elasto.svg?style=svg)](https://circleci.com/gh/StreetHub/elasto) | ||
### Count | ||
Count documents based on a query | ||
```javascript | ||
Elasto.query({ | ||
index: 'development', | ||
type: 'tweets' | ||
}) | ||
.count(); | ||
``` | ||
### License | ||
@@ -257,0 +269,0 @@ `elasto` is released under the MIT license. See `LICENSE.txt` for the complete text. |
@@ -332,2 +332,14 @@ 'use strict'; | ||
it('should count documents', function(done) { | ||
Elasto.query({ | ||
index: 'testing', | ||
type: 'tweets' | ||
}) | ||
.count() | ||
.then(function(res) { | ||
res.count.should.be.greaterThan(0); | ||
}) | ||
.should.eventually.notify(done); | ||
}); | ||
}); | ||
@@ -334,0 +346,0 @@ }); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
25415
600
276
2
10
+ Addedisarray@0.0.1
+ Addedisarray@0.0.1(transitive)