New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

elastic-particles

Package Overview
Dependencies
Maintainers
3
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

elastic-particles - npm Package Compare versions

Comparing version 2.2.6 to 2.2.8

8

lib/aggregations/aggregation.js

@@ -11,6 +11,7 @@ 'use strict';

* @param {string} type Aggregation type, ex: "geo_bounds";
* @param {string=} field Set the aggregation field. Commonly used in simple
* aggs such as min or max.
* @param {string=} field Set the aggregation field. Commonly used in simple aggs such as min or max.
* @param {boolean} [respectPostFilter=false] flag to respect any post_filters by applying the filter to the aggregation. Defaults to false.
*/
function Aggregation(type, field) {
function Aggregation(type, field, respectPostFilter) {
respectPostFilter = respectPostFilter || false;
if (!type) {

@@ -23,2 +24,3 @@ throw new Error('Must specify an aggregation type');

util.createNonEnumerableProperty(this, '_root', this[type]);
util.createNonEnumerableProperty(this, '_respectPostFilter', respectPostFilter);

@@ -25,0 +27,0 @@ if (field) {

@@ -10,4 +10,5 @@ 'use strict';

* @param {string} field Name of field to aggregate on.
* @param {boolean} [respectPostFilter=false] flag to respect any post_filters by applying the filter to the aggregation. Defaults to false.
*/
function CardinalityAgg(field) {
function CardinalityAgg(field, respectPostFilter) {
if (!field) {

@@ -17,3 +18,3 @@ throw new Error('Cardinality aggregation requires an aggregation field');

Aggregation.call(this, 'cardinality', field);
Aggregation.call(this, 'cardinality', field, respectPostFilter);
}

@@ -20,0 +21,0 @@

@@ -12,4 +12,5 @@ 'use strict';

* @param {string} format Date format pattern {@link http://www.elastic.co/guide/en/elasticsearch/reference/1.x/search-aggregations-bucket-daterange-aggregation.html#date-format-pattern|link}
* @param [respectPostFilter=false] flag to respect any post_filters by applying the filter to the aggregation. Defaults to false.
*/
function DateHistogramAgg(field, interval, format) {
function DateHistogramAgg(field, interval, format, respectPostFilter) {
if (!field) {

@@ -19,3 +20,3 @@ throw new Error('Cardinality aggregation requires an aggregation field');

Aggregation.call(this, 'date_histogram', field);
Aggregation.call(this, 'date_histogram', field, respectPostFilter);
this._root.interval = interval;

@@ -22,0 +23,0 @@

@@ -6,10 +6,10 @@ 'use strict';

* @class Elastic Filtered Aggregation.
*
*
* {@link http://www.elastic.co/guide/en/elasticsearch/reference/1.x/search-aggregations-bucket-filter-aggregation.html|link}
* @augments {Aggregation}
* Top level object will contain an 'aggs' and 'filter'.
* @param {Aggregation} innerAgg Aggregation object to be filtered.
* @param {Filter|obj} innerFilter Filter object to apply to the innerAgg.
* @param {string} innerAggname innerAgg name. Defaults to filteredAggName.
*
* @param {Aggregation} innerAgg Aggregation object to be filtered.
* @param {Filter|Object} innerFilter Filter object to apply to the innerAgg.
* @param {string} [innerAggName] innerAgg name. Defaults to filteredAggName.
*
* @todo: Inherit from Aggregation using node util when prototype funcs needed.

@@ -38,2 +38,3 @@ */

util.createNonEnumerableProperty(this, '_innerAgg', innerAgg);
}

@@ -52,2 +53,2 @@

module.exports = FilteredAgg;
module.exports = FilteredAgg;

@@ -14,6 +14,7 @@ 'use strict';

* @param {number} ringRadiusInterval For each concetric ring, increase radius but this many units.
* @param [respectPostFilter=false] flag to respect any post_filters by applying the filter to the aggregation. Defaults to false.
*
* @todo: Optionally pass in "ranges" array directly or provide 2 methods.
*/
function GeoDistanceAgg(field, origin, unit, rings, ringRadiusInterval) {
function GeoDistanceAgg(field, origin, unit, rings, ringRadiusInterval, respectPostFilter) {
if (!field) {

@@ -27,3 +28,3 @@ throw new Error('Geo Distance aggregation requires an aggregation field.');

Aggregation.call(this, 'geo_distance', field);
Aggregation.call(this, 'geo_distance', field, respectPostFilter);
this._root.origin = origin;

@@ -30,0 +31,0 @@ this._root.ranges = [];

@@ -10,4 +10,5 @@ 'use strict';

* @param {string} field Name of field to aggregate on.
* @param [respectPostFilter=false] flag to respect any post_filters by applying the filter to the aggregation. Defaults to false.
*/
function MaxAgg(field) {
function MaxAgg(field, respectPostFilter) {
if (!field) {

@@ -17,3 +18,3 @@ throw new Error('Max aggregation requires an aggregation field');

Aggregation.call(this, 'max', field);
Aggregation.call(this, 'max', field, respectPostFilter);
}

@@ -20,0 +21,0 @@

@@ -19,7 +19,8 @@ 'use strict';

* Ex: innerAgg field='x.y.z', path will be 'x.y'.
* @param {string} innerAggName @optional Aggregation name for inner agg.
* @param {string} [innerAggName] @optional Aggregation name for inner agg.
* @param [respectPostFilter=false] flag to respect any post_filters by applying the filter to the aggregation. Defaults to false.
* @todo: allow multiple 'this.aggs'
*/
function NestedAgg(innerAgg, nestPath, innerAggName) {
function NestedAgg(innerAgg, nestPath, innerAggName, respectPostFilter) {

@@ -36,3 +37,3 @@ if (!(innerAgg instanceof Aggregation)) {

Aggregation.call(this, 'nested');
Aggregation.call(this, 'nested', undefined, respectPostFilter);
this._root.path = nestPath || extractField(innerAgg);

@@ -39,0 +40,0 @@

@@ -11,4 +11,5 @@ 'use strict';

* @param {Object[]} ranges Array of objects containing 'to' and 'from' properties for each bucket.
* @param [respectPostFilter=false] flag to respect any post_filters by applying the filter to the aggregation. Defaults to false.
*/
function RangeAgg(field, ranges) {
function RangeAgg(field, ranges, respectPostFilter) {
if (!field) {

@@ -22,3 +23,3 @@ throw new Error('Range aggregation requires an aggregation field');

Aggregation.call(this, 'range', field);
Aggregation.call(this, 'range', field, respectPostFilter);
this._root.ranges = ranges;

@@ -25,0 +26,0 @@

@@ -10,6 +10,7 @@ 'use strict';

* @param {Object} scripts Scripts object containing map-reduce logic.
* @param [respectPostFilter=false] flag to respect any post_filters by applying the filter to the aggregation. Defaults to false.
*
{ 'init_script': 'script', 'map_script':'script', 'combine_script':'script', 'reduce_script':'script' }
*/
function ScriptedMetricAgg(scripts) {
function ScriptedMetricAgg(scripts, respectPostFilter) {
if (!scripts) {

@@ -23,3 +24,3 @@ throw new Error('Scripted metric aggregation requires a scripts object');

Aggregation.call(this, 'scripted_metric');
Aggregation.call(this, 'scripted_metric', undefined, respectPostFilter);

@@ -26,0 +27,0 @@ this._root.init_script = scripts.init_script;

@@ -10,6 +10,6 @@ 'use strict';

* @param {string} field Name of field to aggregate on.
* @param {int=} size Number of buckets to return.
* Size 0 returns all buckets.
* @param {int=} size Number of buckets to return. Size 0 returns all buckets.
* @param [respectPostFilter=false] flag to respect any post_filters by applying the filter to the aggregation. Defaults to false.
*/
function TermsAgg(field, size) {
function TermsAgg(field, size, respectPostFilter) {
if (!field) {

@@ -19,3 +19,3 @@ throw new Error('Terms aggregation requires an aggregation field');

Aggregation.call(this, 'terms', field);
Aggregation.call(this, 'terms', field, respectPostFilter);
if (size || size === 0) {

@@ -22,0 +22,0 @@ this._root.size = size;

'use strict';
var _ = require('lodash');
const _ = require('lodash');
const FilteredAgg = require('./aggregations/filteredAgg');

@@ -12,2 +13,3 @@

this._query = undefined;
this._post_filter = undefined;
this._disableTermCaching = false;

@@ -40,2 +42,13 @@

/**
* Sets the post_filter to an instance of an Elastic Filter.
* @param {Filter} postFilter instance of ./elasticsearch/filters filter.
*/
ElasticQuery.prototype.setPostFilter = function setPostFilter(postFilter) {
if (postFilter === null || postFilter === undefined) { return this; }
this._post_filter = postFilter;
return this;
};
ElasticQuery.prototype.setSize = function setSize(size) {

@@ -129,5 +142,2 @@ if (!_.isInteger(size)) {throw new Error('size must be an integer');}

}
if (this._aggs) {
q.aggs = this._aggs;
}

@@ -143,2 +153,17 @@ if (this._query) {

if (this._post_filter) {
q.post_filter = this._post_filter;
}
if (this._aggs) {
q.aggs = this._aggs;
if (q.post_filter) {
_.forOwn(q.aggs, (value, key) => {
if (q.aggs[key]._respectPostFilter) {
q.aggs[key] = new FilteredAgg(value, q.post_filter);
}
})
}
}
if (this._source || typeof this._source === 'boolean') {

@@ -145,0 +170,0 @@ q._source = this._source;

@@ -29,2 +29,4 @@ 'use strict';

exports.ScriptedMetricAgg = require('./aggregations/scriptedMetricAgg');
exports.TermsAgg = require('./aggregations/termsAgg');
exports.TermsAgg = require('./aggregations/termsAgg');
exports.AggParser = require('./util').parseAggResponse;

@@ -9,3 +9,3 @@ 'use strict';

* @param {string} prop Property to set as non enumerable.
* @param {anything} value Sets the property to this value.
* @param {Object} value Sets the property to this value.
*/

@@ -21,3 +21,3 @@ function createNonEnumerableProperty(scope, prop, value) {

/**
* Merges two objects, concatonating matching arrays instead of overwriting them.
* Merges two objects, concatenating matching arrays instead of overwriting them.
*/

@@ -30,5 +30,15 @@ function merge(obj1, obj2) {

function parseAggResponse(response, aggName, propertyToReturn) {
if (response.aggregations[aggName]){
if (response.aggregations[aggName][aggName]){
return response.aggregations[aggName][aggName][propertyToReturn];
}
return response.aggregations[aggName][propertyToReturn];
}
}
module.exports = {
createNonEnumerableProperty: createNonEnumerableProperty,
merge: merge
merge: merge,
parseAggResponse: parseAggResponse
};
{
"name": "elastic-particles",
"version": "2.2.6",
"version": "2.2.8",
"description": "Building blocks for Elastic queries, filters, and aggregations which can be re-used, combed, and nested.",

@@ -5,0 +5,0 @@ "author": {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc