elastic-builder
Advanced tools
Comparing version 0.1.1 to 0.1.2
@@ -19,3 +19,3 @@ 'use strict'; | ||
* | ||
* This aggregation relies on the _parent field in the mapping. | ||
* This aggregation relies on the `_parent` field in the mapping. | ||
* | ||
@@ -22,0 +22,0 @@ * [Elasticsearch reference](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-children-aggregation.html) |
@@ -16,2 +16,3 @@ 'use strict'; | ||
* The interval can be specified by date/time expressions. | ||
* | ||
* [Elasticsearch reference](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-datehistogram-aggregation.html#_scripts) | ||
@@ -18,0 +19,0 @@ * |
@@ -5,2 +5,4 @@ 'use strict'; | ||
var _get = function get(object, property, receiver) { if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { return get(parent, property, receiver); } } else if ("value" in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } }; | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
@@ -12,2 +14,5 @@ | ||
var isEmpty = require('lodash.isempty'), | ||
forEach = require('lodash.foreach'); | ||
var _require = require('../../core'), | ||
@@ -71,2 +76,3 @@ checkType = _require.util.checkType; | ||
* @returns {RangeAggregationBase} returns `this` so that calls can be chained | ||
* | ||
* @throws {TypeError} If `range` is not an instance of object | ||
@@ -90,2 +96,28 @@ * @throws {Error} If none of the required keys, | ||
/** | ||
* Adds the list of ranges to the list of existing range expressions. | ||
* | ||
* @param {Array<Object>} ranges Ranges to aggregate over. | ||
* Each item must be an object with keys `from`, `to` and `key`. | ||
* @returns {RangeAggregationBase} returns `this` so that calls can be chained | ||
* | ||
* @throws {TypeError} If `ranges` is not an instance of an array or | ||
* and item in the array is not an instance of object | ||
* @throws {Error} If none of the required keys, | ||
* `from`, `to` or `mask`(for IP range) is passed | ||
*/ | ||
}, { | ||
key: 'ranges', | ||
value: function ranges(_ranges) { | ||
var _this2 = this; | ||
checkType(_ranges, Array); | ||
forEach(_ranges, function (range) { | ||
return _this2.range(range); | ||
}); | ||
return this; | ||
} | ||
/** | ||
* Sets the missing parameter ehich defines how documents | ||
@@ -119,2 +151,19 @@ * that are missing a value should be treated. | ||
} | ||
/** | ||
* Override default `toJSON` to return DSL representation for the `aggregation` query. | ||
* | ||
* @override | ||
* @returns {Object} returns an Object which maps to the elasticsearch query DSL | ||
*/ | ||
}, { | ||
key: 'toJSON', | ||
value: function toJSON() { | ||
if (isEmpty(this._aggsDef.ranges)) { | ||
throw new Error('`ranges` cannot be empty.'); | ||
} | ||
return _get(RangeAggregationBase.prototype.__proto__ || Object.getPrototypeOf(RangeAggregationBase.prototype), 'toJSON', this).call(this); | ||
} | ||
}]); | ||
@@ -121,0 +170,0 @@ |
@@ -12,3 +12,3 @@ 'use strict'; | ||
var has = require('lodash.has'), | ||
invokeMap = require('lodash.invokemap'); | ||
forEach = require('lodash.foreach'); | ||
@@ -164,3 +164,3 @@ var MetricsAggregationBase = require('./metrics-aggregation-base'), | ||
invokeMap(_sorts, function (sort) { | ||
forEach(_sorts, function (sort) { | ||
return _this2.sort(sort); | ||
@@ -167,0 +167,0 @@ }); |
@@ -8,3 +8,3 @@ 'use strict'; | ||
var has = require('lodash.has'), | ||
invokeMap = require('lodash.invokemap'); | ||
forEach = require('lodash.foreach'); | ||
@@ -105,3 +105,3 @@ var Sort = require('./sort'), | ||
invokeMap(_sorts, function (sort) { | ||
forEach(_sorts, function (sort) { | ||
return _this.sort(sort); | ||
@@ -108,0 +108,0 @@ }); |
@@ -14,3 +14,3 @@ 'use strict'; | ||
isEmpty = require('lodash.isempty'), | ||
invokeMap = require('lodash.invokemap'); | ||
forEach = require('lodash.foreach'); | ||
@@ -197,3 +197,3 @@ var Query = require('./query'), | ||
invokeMap(_sorts, function (sort) { | ||
forEach(_sorts, function (sort) { | ||
return _this.sort(sort); | ||
@@ -200,0 +200,0 @@ }); |
@@ -56,4 +56,4 @@ 'use strict'; | ||
/** | ||
* Set order for sorting. The order defaults to desc when sorting on the _score, | ||
* and defaults to asc when sorting on anything else. | ||
* Set order for sorting. The order defaults to `desc` when sorting on the `_score`, | ||
* and defaults to `asc` when sorting on anything else. | ||
* | ||
@@ -60,0 +60,0 @@ * @param {string} order The `order` option can have the following values. |
@@ -90,5 +90,7 @@ 'use strict'; | ||
var json = {}, | ||
baseLevelJSON = hasIn(obj, 'toJSON') ? obj.toJSON() : obj; | ||
if (hasIn(obj, 'toJSON') && obj.constructor !== Object) { | ||
return recursiveToJSON(obj.toJSON()); | ||
} | ||
var json = {}; | ||
var _iteratorNormalCompletion = true; | ||
@@ -99,6 +101,6 @@ var _didIteratorError = false; | ||
try { | ||
for (var _iterator = Object.keys(baseLevelJSON)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { | ||
for (var _iterator = Object.keys(obj)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { | ||
var key = _step.value; | ||
json[key] = recursiveToJSON(baseLevelJSON[key]); | ||
json[key] = recursiveToJSON(obj[key]); | ||
} | ||
@@ -105,0 +107,0 @@ } catch (err) { |
@@ -14,3 +14,3 @@ 'use strict'; | ||
var has = require('lodash.has'), | ||
invokeMap = require('lodash.invokemap'), | ||
forEach = require('lodash.foreach'), | ||
reduce = require('lodash.reduce'), | ||
@@ -84,3 +84,3 @@ filter = require('lodash.filter'), | ||
if (Array.isArray(queries)) invokeMap(queries, function (qry) { | ||
if (Array.isArray(queries)) forEach(queries, function (qry) { | ||
return _this2._addQuery(clause, qry); | ||
@@ -87,0 +87,0 @@ });else this._addQuery(clause, queries); |
@@ -12,3 +12,3 @@ 'use strict'; | ||
var has = require('lodash.has'), | ||
invokeMap = require('lodash.invokemap'); | ||
forEach = require('lodash.foreach'); | ||
@@ -92,3 +92,3 @@ var _require = require('../../core'), | ||
if (Array.isArray(_queries)) invokeMap(_queries, function (qry) { | ||
if (Array.isArray(_queries)) forEach(_queries, function (qry) { | ||
return _this2._addQuery(qry); | ||
@@ -95,0 +95,0 @@ });else this._addQuery(_queries); |
@@ -16,3 +16,3 @@ 'use strict'; | ||
var invokeMap = require('lodash.invokemap'), | ||
var forEach = require('lodash.foreach'), | ||
head = require('lodash.head'), | ||
@@ -178,3 +178,3 @@ omit = require('lodash.omit'); | ||
invokeMap(funcs, function (func) { | ||
forEach(funcs, function (func) { | ||
return _this2.function(func); | ||
@@ -181,0 +181,0 @@ }); |
@@ -11,3 +11,3 @@ 'use strict'; | ||
var invokeMap = require('lodash.invokemap'); | ||
var forEach = require('lodash.foreach'); | ||
@@ -65,3 +65,3 @@ var _require = require('../../core'), | ||
checkType(_clauses, Array); | ||
invokeMap(_clauses, function (clause) { | ||
forEach(_clauses, function (clause) { | ||
return checkType(clause, SpanQueryBase); | ||
@@ -68,0 +68,0 @@ }); |
@@ -11,3 +11,3 @@ 'use strict'; | ||
var invokeMap = require('lodash.invokemap'); | ||
var forEach = require('lodash.foreach'); | ||
@@ -61,3 +61,3 @@ var _require = require('../../core'), | ||
checkType(_clauses, Array); | ||
invokeMap(_clauses, function (clause) { | ||
forEach(_clauses, function (clause) { | ||
return checkType(clause, SpanQueryBase); | ||
@@ -64,0 +64,0 @@ }); |
{ | ||
"name": "elastic-builder", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"description": "A JavaScript implementation of the elasticsearch Query DSL", | ||
@@ -15,3 +15,3 @@ "main": "lib/index.js", | ||
"build:umd": "webpack lib browser/elastic-builder.min.js", | ||
"build:docs": "documentation build src/index.js -o docs -f html --github --name elastic-builder", | ||
"build:docs": "documentation build src/index.js --github -o docs -f html --name elastic-builder", | ||
"build": "npm run build:babel && npm run build:umd && npm run build:docs", | ||
@@ -75,6 +75,6 @@ "lint": "eslint src test", | ||
"lodash.filter": "^4.6.0", | ||
"lodash.foreach": "^4.5.0", | ||
"lodash.has": "^4.5.2", | ||
"lodash.hasin": "^4.5.2", | ||
"lodash.head": "^4.0.1", | ||
"lodash.invokemap": "^4.6.0", | ||
"lodash.isempty": "^4.4.0", | ||
@@ -81,0 +81,0 @@ "lodash.isnil": "^4.0.0", |
@@ -73,7 +73,8 @@ # elastic-builder | ||
## API Reference | ||
API reference can be accessed here - http://elastic-builder.js.org/docs. | ||
API documentation was generated using [documentation.js](https://github.com/documentationjs/documentation) | ||
It can be accessed here - http://elastic-builder.js.org/docs. | ||
It is being hosted with help from this awesome project - https://github.com/js-org/dns.js.org | ||
Dcoumentation is a WIP. See [roadmap](roadmap.md). | ||
Documentation is a WIP. See [roadmap](roadmap.md). | ||
@@ -174,2 +175,49 @@ ## Examples | ||
// } | ||
// Sort | ||
const requestBody = bob.requestBodySearch() | ||
.query( | ||
bob.boolQuery() | ||
.filter(bob.termQuery('message', 'test')) | ||
) | ||
.sort(bob.sort('timestamp', 'desc')) | ||
.sorts([ | ||
bob.sort('channel', 'desc'), | ||
bob.sort('categories', 'desc'), | ||
// The order defaults to desc when sorting on the _score, | ||
// and defaults to asc when sorting on anything else. | ||
bob.sort('content'), | ||
bob.sort('price').order('desc').mode('avg') | ||
]); | ||
// requestBody.toJSON() | ||
// { | ||
// "query": { | ||
// "bool": { | ||
// "filter": { | ||
// "term": { "message": "test" } | ||
// } | ||
// } | ||
// }, | ||
// "sort": [ | ||
// { "timestamp": { "order": "desc" } }, | ||
// { "channel": { "order": "desc" } }, | ||
// { "categories": { "order": "desc" } }, | ||
// "content", | ||
// { "price": { "order": "desc", "mode": "avg" } } | ||
// ] | ||
// } | ||
// From / size | ||
const requestBody = bob.requestBodySearch() | ||
.query(bob.matchAllQuery()) | ||
.size(5) | ||
.from(10); | ||
// requestBody.toJSON() | ||
// { | ||
// "query": { | ||
// "match_all": {} | ||
// }, | ||
// "size": 5, | ||
// "from": 10 | ||
// } | ||
``` | ||
@@ -204,4 +252,9 @@ | ||
## Tests | ||
Tests are yet to be added. See [roadmap](roadmap.md). | ||
Tests are being added. See [roadmap](roadmap.md). | ||
For running whatever tests _have_ been added: | ||
``` | ||
npm test | ||
``` | ||
## Credits | ||
@@ -208,0 +261,0 @@ `elastic-builder` is heavily inspired by [`elastic.js`](https://github.com/fullscale/elastic.js) |
@@ -12,3 +12,3 @@ 'use strict'; | ||
* | ||
* This aggregation relies on the _parent field in the mapping. | ||
* This aggregation relies on the `_parent` field in the mapping. | ||
* | ||
@@ -15,0 +15,0 @@ * [Elasticsearch reference](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-children-aggregation.html) |
@@ -8,2 +8,3 @@ 'use strict'; | ||
* The interval can be specified by date/time expressions. | ||
* | ||
* [Elasticsearch reference](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-datehistogram-aggregation.html#_scripts) | ||
@@ -10,0 +11,0 @@ * |
'use strict'; | ||
const isEmpty = require('lodash.isempty'), | ||
forEach = require('lodash.foreach'); | ||
const { util: { checkType } } = require('../../core'); | ||
@@ -50,2 +53,3 @@ | ||
* @returns {RangeAggregationBase} returns `this` so that calls can be chained | ||
* | ||
* @throws {TypeError} If `range` is not an instance of object | ||
@@ -70,2 +74,21 @@ * @throws {Error} If none of the required keys, | ||
/** | ||
* Adds the list of ranges to the list of existing range expressions. | ||
* | ||
* @param {Array<Object>} ranges Ranges to aggregate over. | ||
* Each item must be an object with keys `from`, `to` and `key`. | ||
* @returns {RangeAggregationBase} returns `this` so that calls can be chained | ||
* | ||
* @throws {TypeError} If `ranges` is not an instance of an array or | ||
* and item in the array is not an instance of object | ||
* @throws {Error} If none of the required keys, | ||
* `from`, `to` or `mask`(for IP range) is passed | ||
*/ | ||
ranges(ranges) { | ||
checkType(ranges, Array); | ||
forEach(ranges, range => this.range(range)); | ||
return this; | ||
} | ||
/** | ||
* Sets the missing parameter ehich defines how documents | ||
@@ -93,4 +116,18 @@ * that are missing a value should be treated. | ||
} | ||
/** | ||
* Override default `toJSON` to return DSL representation for the `aggregation` query. | ||
* | ||
* @override | ||
* @returns {Object} returns an Object which maps to the elasticsearch query DSL | ||
*/ | ||
toJSON() { | ||
if (isEmpty(this._aggsDef.ranges)) { | ||
throw new Error('`ranges` cannot be empty.'); | ||
} | ||
return super.toJSON(); | ||
} | ||
} | ||
module.exports = RangeAggregationBase; |
'use strict'; | ||
const has = require('lodash.has'), | ||
invokeMap = require('lodash.invokemap'); | ||
forEach = require('lodash.foreach'); | ||
@@ -121,3 +121,3 @@ const MetricsAggregationBase = require('./metrics-aggregation-base'), | ||
sorts(sorts) { | ||
invokeMap(sorts, sort => this.sort(sort)); | ||
forEach(sorts, sort => this.sort(sort)); | ||
return this; | ||
@@ -124,0 +124,0 @@ } |
'use strict'; | ||
const has = require('lodash.has'), | ||
invokeMap = require('lodash.invokemap'); | ||
forEach = require('lodash.foreach'); | ||
@@ -79,3 +79,3 @@ const Sort = require('./sort'), | ||
sorts(sorts) { | ||
invokeMap(sorts, sort => this.sort(sort)); | ||
forEach(sorts, sort => this.sort(sort)); | ||
return this; | ||
@@ -82,0 +82,0 @@ } |
@@ -6,3 +6,3 @@ 'use strict'; | ||
isEmpty = require('lodash.isempty'), | ||
invokeMap = require('lodash.invokemap'); | ||
forEach = require('lodash.foreach'); | ||
@@ -153,3 +153,3 @@ const Query = require('./query'), | ||
sorts(sorts) { | ||
invokeMap(sorts, sort => this.sort(sort)); | ||
forEach(sorts, sort => this.sort(sort)); | ||
return this; | ||
@@ -156,0 +156,0 @@ } |
@@ -40,4 +40,4 @@ 'use strict'; | ||
/** | ||
* Set order for sorting. The order defaults to desc when sorting on the _score, | ||
* and defaults to asc when sorting on anything else. | ||
* Set order for sorting. The order defaults to `desc` when sorting on the `_score`, | ||
* and defaults to `asc` when sorting on anything else. | ||
* | ||
@@ -44,0 +44,0 @@ * @param {string} order The `order` option can have the following values. |
@@ -82,9 +82,12 @@ 'use strict'; | ||
const json = {}, | ||
baseLevelJSON = hasIn(obj, 'toJSON') ? obj.toJSON() : obj; | ||
if (hasIn(obj, 'toJSON') && obj.constructor !== Object) { | ||
return recursiveToJSON(obj.toJSON()); | ||
} | ||
for (const key of Object.keys(baseLevelJSON)) { | ||
json[key] = recursiveToJSON(baseLevelJSON[key]); | ||
const json = {}; | ||
for (const key of Object.keys(obj)) { | ||
json[key] = recursiveToJSON(obj[key]); | ||
} | ||
return json; | ||
}; |
'use strict'; | ||
const has = require('lodash.has'), | ||
invokeMap = require('lodash.invokemap'), | ||
forEach = require('lodash.foreach'), | ||
reduce = require('lodash.reduce'), | ||
@@ -58,3 +58,3 @@ filter = require('lodash.filter'), | ||
if (Array.isArray(queries)) invokeMap(queries, qry => this._addQuery(clause, qry)); | ||
if (Array.isArray(queries)) forEach(queries, qry => this._addQuery(clause, qry)); | ||
else this._addQuery(clause, queries); | ||
@@ -61,0 +61,0 @@ } |
'use strict'; | ||
const has = require('lodash.has'), | ||
invokeMap = require('lodash.invokemap'); | ||
forEach = require('lodash.foreach'); | ||
@@ -67,3 +67,3 @@ const { | ||
if (Array.isArray(queries)) invokeMap(queries, qry => this._addQuery(qry)); | ||
if (Array.isArray(queries)) forEach(queries, qry => this._addQuery(qry)); | ||
else this._addQuery(queries); | ||
@@ -70,0 +70,0 @@ |
@@ -5,3 +5,3 @@ 'use strict'; | ||
const invokeMap = require('lodash.invokemap'), | ||
const forEach = require('lodash.foreach'), | ||
head = require('lodash.head'), | ||
@@ -139,3 +139,3 @@ omit = require('lodash.omit'); | ||
invokeMap(funcs, func => this.function(func)); | ||
forEach(funcs, func => this.function(func)); | ||
return this; | ||
@@ -142,0 +142,0 @@ } |
'use strict'; | ||
const invokeMap = require('lodash.invokemap'); | ||
const forEach = require('lodash.foreach'); | ||
@@ -49,3 +49,3 @@ const { | ||
checkType(clauses, Array); | ||
invokeMap(clauses, clause => checkType(clause, SpanQueryBase)); | ||
forEach(clauses, clause => checkType(clause, SpanQueryBase)); | ||
@@ -52,0 +52,0 @@ this._queryOpts.clauses = clauses; |
'use strict'; | ||
const invokeMap = require('lodash.invokemap'); | ||
const forEach = require('lodash.foreach'); | ||
@@ -45,3 +45,3 @@ const { | ||
checkType(clauses, Array); | ||
invokeMap(clauses, clause => checkType(clause, SpanQueryBase)); | ||
forEach(clauses, clause => checkType(clause, SpanQueryBase)); | ||
@@ -48,0 +48,0 @@ this._queryOpts.clauses = clauses; |
Sorry, the diff of this file is too big to display
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
1293795
22802
265
+ Addedlodash.foreach@^4.5.0
+ Addedlodash.foreach@4.5.0(transitive)
- Removedlodash.invokemap@^4.6.0
- Removedlodash.invokemap@4.6.0(transitive)