Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

elastic-particles

Package Overview
Dependencies
Maintainers
2
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 0.0.5 to 0.0.7

lib/filters/filter.js

12

lib/aggregations/aggregation.js

@@ -5,7 +5,9 @@ 'use strict';

/**
* Base elastic aggregation.
* {@link http://www.elastic.co/guide/en/elasticsearch/reference/1.x/search-aggregations.html}
* TODO: Add script option.
* @param {string} type Aggregation type, ex: "geo_bounds";
* @param {string} field Optionally set the aggregation field. Commonly used in simple
* @class Base elastic aggregation.
*
* {@link http://www.elastic.co/guide/en/elasticsearch/reference/1.x/search-aggregations.html|link}
* @todo: Add script option.
*
* @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.

@@ -12,0 +14,0 @@ */

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

/**
* Elastic metrics aggregation that calculates an approximate count of distinct values for a field.
* {@link http://www.elastic.co/guide/en/elasticsearch/reference/1.x/search-aggregations-metrics-cardinality-aggregation.html}
* @class Elastic metrics aggregation that calculates an approximate count of distinct values for a field.
*
* {@link http://www.elastic.co/guide/en/elasticsearch/reference/1.x/search-aggregations-metrics-cardinality-aggregation.html|link}
* @augments {Aggregation}
* @param {string} field Name of field to aggregate on.

@@ -22,6 +24,5 @@ */

/**
* @override
* Get the name of the aggregation object.
* Defaults to '{{field}}Cardinality'
* @return {string} Name of aggregation.
* @default '{{field}}Cardinality'
*/

@@ -28,0 +29,0 @@ CardinalityAgg.prototype.getName = function getCardinalityName() {

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

/**
* Elastic multi-bucket aggregation that groups by dates.
* {@link http://www.elastic.co/guide/en/elasticsearch/reference/1.x/search-aggregations-bucket-datehistogram-aggregation.html}
* @class Elastic multi-bucket aggregation that groups by dates.
*
* {@link http://www.elastic.co/guide/en/elasticsearch/reference/1.x/search-aggregations-bucket-datehistogram-aggregation.html|link}
* @augments {Aggregation}
* @param {string} field Name of field to aggregate on.
* @param {string} interval One of: year, quarter, month, week, day, hour, minute, or second
* @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}
* @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}
*/
var validIntervals = ['year', 'quarter', 'month', 'week', 'day', 'hour', 'minute', 'second'];
function DateHistogramAgg(field, interval, format) {

@@ -21,6 +20,2 @@ if (!field) {

if (!_.contains(validIntervals, interval)) {
throw new Error('Date histogram requires a valid date interval (ex: "month")');
}
Aggregation.call(this, 'date_histogram', field);

@@ -38,6 +33,4 @@ this._root.interval = interval;

/**
* @override
* Get the name of the aggregation object.
* @return {string} Name of aggregation.
* @default '{{field}}DateHistogram'
* @return {string} Name of aggregation. Defaults to '{{field}}DateHistogram'
*/

@@ -44,0 +37,0 @@ DateHistogramAgg.prototype.getName = function getDateHistogramName() {

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

/**
* Elastic Filtered Aggregation.
* {@link http://www.elastic.co/guide/en/elasticsearch/reference/1.x/search-aggregations-bucket-filter-aggregation.html}
* TODO: Inherit from Aggregation using node util when prototype funcs needed.
* @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'.

@@ -13,2 +14,4 @@ * @param {Aggregation} innerAgg Aggregation object to be filtered.

* @param {string} innerAggname innerAgg name. Defaults to filteredAggName.
*
* @todo: Inherit from Aggregation using node util when prototype funcs needed.
*/

@@ -42,6 +45,4 @@ function FilteredAgg(innerAgg, innerFilter, innerAggName) {

/**
* @override
* Get the name of the aggregation object.
* @return {string} Name of aggregation.
* @default Defers to innerAgg object.
* @return {string} Name of aggregation. Defers to innerAgg object.
*/

@@ -48,0 +49,0 @@ FilteredAgg.prototype.getName = function getFilteredName() {

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

/**
* Elastic Geo Distance Aggregation.
* Abstracted to create concentric rings of uniform radius.
* TODO: Optionally pass in "ranges" array directly.
* {@link http://www.elastic.co/guide/en/elasticsearch/reference/1.x/search-aggregations-bucket-geodistance-aggregation.html}
* @param {string} field Name of term to aggregate on.
* @param {point} origin Elasticsearch geo_point type. {PS: Lat, Lon if string, [Lon, Lat] if array.}
* @param {string} unit Elasticsearch geo distance unit. @default 'm'
* @param {int} rings Number of concentric distance rings to bucket by.
* @param {number} ringRadiusInterval For each concetric ring, increase radius but this many units.
* @class Elastic Geo Distance Aggregation.
*
* {@link http://www.elastic.co/guide/en/elasticsearch/reference/1.x/search-aggregations-bucket-geodistance-aggregation.html|link}
* @augments {Aggregation}
* @param {string} field Name of term to aggregate on.
* @param {number[]|string} origin Elasticsearch geo_point type. {PS: Lat, Lon if string, [Lon, Lat] if array.}
* @param {string} unit Elasticsearch geo distance unit. @default 'm'
* @param {int} rings Number of concentric distance rings to bucket by.
* @param {number} ringRadiusInterval For each concetric ring, increase radius but this many units.
*
* @todo: Optionally pass in "ranges" array directly or provide 2 methods.
*/

@@ -46,6 +48,4 @@ function GeoDistanceAgg(field, origin, unit, rings, ringRadiusInterval) {

/**
* @override
* Get the name of the aggregation object.
* @return {string} Name of aggregation.
* @default '{{field}}GeoDistance'
* @return {string} Name of aggregation. Defaults to '{{field}}GeoDistance'
*/

@@ -52,0 +52,0 @@ GeoDistanceAgg.prototype.getName = function getGeoDistanceName() {

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

/**
* Elastic metrics aggregation that calculates the max value for the field.
* {@link http://www.elastic.co/guide/en/elasticsearch/reference/1.x/search-aggregations-metrics-max-aggregation.html}
* @class Elastic metrics aggregation that calculates the max value for the field.
*
* {@link http://www.elastic.co/guide/en/elasticsearch/reference/1.x/search-aggregations-metrics-max-aggregation.html|link}
* @augments {Aggregation}
* @param {string} field Name of field to aggregate on.

@@ -22,6 +24,4 @@ */

/**
* @override
* Get the name of the aggregation object.
* @return {string} Name of aggregation.
* @default '{{field}}Max'
* @return {string} Name of aggregation. Default to '{{field}}Max'
*/

@@ -28,0 +28,0 @@ MaxAgg.prototype.getName = function getMaxName() {

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

/**
* Elastic Nested Aggregation.
* @class Elastic Nested Aggregation.
* Wraps other aggregation instances.
* TODO: allow multiple 'this.aggs'
* {@link http://www.elastic.co/guide/en/elasticsearch/reference/1.x/search-aggregations-bucket-nested-aggregation.html}
*
* Structure works around [this issue]{@link https://github.com/elasticsearch/elasticsearch/issues/4449}
*
* {nested: { path: 'pathstring' }, aggs: { 'innerAggName': { AGGREGATION } }}
*
* {@link http://www.elastic.co/guide/en/elasticsearch/reference/1.x/search-aggregations-bucket-nested-aggregation.html|link}
* @augments {Aggregation}
* @param {Aggregation} innerAgg Inner aggregation object.

@@ -17,3 +21,4 @@ * @param {string} nestPath @optional path of nested document fields.

* @param {string} innerAggName @optional Aggregation name for inner agg.
* Structure works around {@link/https://github.com/elasticsearch/elasticsearch/issues/4449}
* @todo: allow multiple 'this.aggs'
*/

@@ -45,6 +50,4 @@ function NestedAgg(innerAgg, nestPath, innerAggName) {

/**
* @override
* Get the name of the aggregation object.
* @return {string} Name of aggregation.
* @default Defers to innerAgg object.
* @return {string} Name of aggregation. Defers to innerAgg object.
*/

@@ -51,0 +54,0 @@ NestedAgg.prototype.getName = function getNestedName() {

@@ -5,6 +5,8 @@ 'use strict';

/**
* Elastic multi-bucket aggregation that groups by defined ranges.
* {@link http://www.elastic.co/guide/en/elasticsearch/reference/1.x/search-aggregations-bucket-range-aggregation.html}
* @param {string} field Name of field to aggregate on.
* @param {Array} ranges Array of objects containing 'to' and 'from' properties for each bucket.
* @class Elastic multi-bucket aggregation that groups by defined ranges.
*
* {@link http://www.elastic.co/guide/en/elasticsearch/reference/1.x/search-aggregations-bucket-range-aggregation.html|link}
* @augments {Aggregation}
* @param {string} field Name of field to aggregate on.
* @param {Object[]} ranges Array of objects containing 'to' and 'from' properties for each bucket.
*/

@@ -29,6 +31,4 @@ function RangeAgg(field, ranges) {

/**
* @override
* Get the name of the aggregation object.
* @return {string} Name of aggregation.
* @default '{{field}}Range'
* @return {string} Name of aggregation. Default to '{{field}}Range'
*/

@@ -35,0 +35,0 @@ RangeAgg.prototype.getName = function getRangeName() {

@@ -5,7 +5,9 @@ 'use strict';

/**
* Elastic metrics aggregation that executes map-reduce style scripts.
* {@link http://www.elastic.co/guide/en/elasticsearch/reference/1.x/search-aggregations-metrics-scripted-metric-aggregation.html}
* @param {object} scripts Scripts object containing map-reduce logic.
* {@link http://www.elastic.co/guide/en/elasticsearch/reference/1.x/search-aggregations-metrics-scripted-metric-aggregation.html#_scope_of_scripts}
* Scripts can include: 'init_script', 'map_script', 'combine_script', 'reduce_script'
* @class Elastic metrics aggregation that executes map-reduce style scripts.
*
* {@link http://www.elastic.co/guide/en/elasticsearch/reference/1.x/search-aggregations-metrics-scripted-metric-aggregation.html|link}
* @augments {Aggregation}
* @param {Object} scripts Scripts object containing map-reduce logic.
*
{ 'init_script': 'script', 'map_script':'script', 'combine_script':'script', 'reduce_script':'script' }
*/

@@ -12,0 +14,0 @@ function ScriptedMetricAgg(scripts) {

@@ -5,6 +5,8 @@ 'use strict';

/**
* Elastic metrics aggregation that calculates an approximate count of distinct values for a field.
* {@link http://www.elastic.co/guide/en/elasticsearch/reference/1.x/search-aggregations-metrics-cardinality-aggregation.html}
* @class Elastic metrics aggregation that calculates an approximate count of distinct values for a field.
*
* {@link http://www.elastic.co/guide/en/elasticsearch/reference/1.x/search-aggregations-metrics-cardinality-aggregation.html|link}
* @augments {Aggregation}
* @param {string} field Name of field to aggregate on.
* @param {int} size Aggregation size for number of buckets to return.
* @param {int=} size Number of buckets to return.
* Size 0 returns all buckets.

@@ -27,6 +29,4 @@ */

/**
* @override
* Get the name of the aggregation object.
* @return {string} Name of aggregation.
* @default '{{field}}Terms'
* @return {string} Name of aggregation. Default to '{{field}}Terms'
*/

@@ -33,0 +33,0 @@ TermsAgg.prototype.getName = function getTermsName() {

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

/**
* ElasticSearch AND filter.
* @param {Filter or [Filters]} Filters to logically AND together. Can be a single filter.
* @class ElasticSearch And filter.
*
* {@link http://www.elastic.co/guide/en/elasticsearch/reference/1.x/query-dsl-and-filter.html|link}
* @augments {Filter}
* @param {Filter|Filter[]} filters=[]] Filters to logically AND together. Can be a single filter.
*/

@@ -13,2 +16,8 @@ function AndFilter(filters) {

/**
* Shorthand to create and add a term filter.
* @param {string} field Term filter field.
* @param {any} value Value to filter on.
* @param {bool=} noNest If true, term filter will not automatically infer nesting.
*/
AndFilter.prototype.addTerm = function addTerm(termName, value, noNest) {

@@ -19,2 +28,6 @@ this.and.push(new TermFilter(termName, value, noNest));

/**
* Add a filter.
* @param {Filter} filter Filter instance to add.
*/
AndFilter.prototype.addFilter = function addFilter(filter) {

@@ -21,0 +34,0 @@ if (filter) { this.and.push(filter); }

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

/**
* ElasticSearch boolean filter.
* @param {string} field If provided, creates a "must" condition on this term.
* @param {any} value If provided, field must equal this value.
* @class ElasticSearch Bool filter.
*
* @{@link http://www.elastic.co/guide/en/elasticsearch/reference/1.x/query-dsl-bool-filter.html|link}
* @augments {Filter}
*/

@@ -10,0 +11,0 @@ function BoolFilter() {

@@ -8,3 +8,4 @@ 'use strict';

/**
* Abstraction that mimics mongoDB's $elemMatch.
* @class Abstraction that mimics mongoDB's $elemMatch.
* @augments {Filter}
* Creates a nested "AND" filter including each property.

@@ -11,0 +12,0 @@ */

'use strict';
/**
* Creates a geo bounding box ElasticSearch filter.
* @class ElasticSearch geo bounding box filter.
* @augments {Filter}
* Sets _cache to true.
* @todo implement base filter with cache control
* Note: lon before lat, to match GeoJson spec.

@@ -10,7 +12,7 @@ *

*
* @param {string} termPath document path to term containing location.
* @param {string|int|float} west Longitude of WESTERN point.
* @param {string|int|float} south Latitude of SOUTHERN point.
* @param {string|int|float} east Longitude of EASTERN point.
* @param {string|int|float} north Latitude of NORTHERN point.
* @param {string} termPath document path to term containing location.
* @param {string|number} west Longitude of WESTERN point.
* @param {string|number} south Latitude of SOUTHERN point.
* @param {string|number} east Longitude of EASTERN point.
* @param {string|number} north Latitude of NORTHERN point.
* @return {Filter} Filter object constructed. Serializes to geo filter.

@@ -17,0 +19,0 @@ */

'use strict';
/**
* Creates a geo distance ElasticSearch filter.
* @class ElasticSearch geo distance filter.
* @augments {Filter}
* Note: lon before lat, to match GeoJson spec.
* @param {int} distanceValue Distance scalar.
* @param {string} distanceUnit Distance unit: See bit.ly/1yjZaiy
* @param {[number, number]} geoJsonArry [lon, lat] to match GeoJson spec.
* @param {string} termPath document path to term containing location.
* @param {bool} cache Determine whether to cache the filter. Defaults to true.
* @return {Filter} Filter object constructed. Serializes to geo filter.
* @param {number} distanceValue Distance scalar.
* @param {string} distanceUnit Distance unit: See bit.ly/1yjZaiy
* @param {number[]} geoJsonArry [lon, lat] to match GeoJson spec.
* @param {string} termPath document path to term containing location.
* @param {bool=} cache Determine whether to cache the filter. Defaults to true.
*/

@@ -13,0 +13,0 @@ function GeoDistanceFilter(distanceValue, distanceUnit, geoJsonArry, termPath, cache) {

'use strict';
function MissingFilter(term) {
/**
* @class Elasticsearch Missing filter
* @augments {Filter}
* @param {string} field Field for missing filter.
*/
function MissingFilter(field) {
this.missing = {
'field': term
'field': field
};

@@ -7,0 +12,0 @@ }

'use strict';
/**
* Elasticsearch Nested filter.
* @param {path} path Nest path for document to filter.
* @class Elasticsearch Nested filter.
* @augments {Filter}
* @param {string} path Nest path for document to filter.
* @param {Filter} filter Elastic filter instance to filter on the path.

@@ -7,0 +8,0 @@ */

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

/**
* ElasticSearch OR filter.
* @param {Filter or [Filters]} Filters to logically OR together. Can be a single filter.
* @class ElasticSearch Or filter.
* @augments {Filter}
* @param {Filter|Filter[]} filters Filters to logically OR together. Can be a single filter.
*/

@@ -13,6 +14,6 @@ function OrFilter(filters) {

OrFilter.prototype.addTerm = function addTerm(termName, value) {
OrFilter.prototype.addTerm = function addTerm(field, value) {
if (!value) return this;
this.or.push(new TermFilter(termName, value));
this.or.push(new TermFilter(field, value));
return this;

@@ -19,0 +20,0 @@ };

'use strict';
var _ = require('lodash');
function RangeFilter(term) {
/**
* @class ElasticSearch Range filter.
* @augments {Filter}
* @param {string} field Name of field to filter.
*/
function RangeFilter(field) {
this.range = {};
this.range[term] = {};
this.range[field] = {};
}

@@ -11,4 +16,4 @@ module.exports = RangeFilter;

RangeFilter.prototype.lte = function lte(value) {
var term = _.keys(this.range)[0];
this.range[term].lte = value;
var field = _.keys(this.range)[0];
this.range[field].lte = value;
return this;

@@ -18,4 +23,4 @@ };

RangeFilter.prototype.gte = function gte(value) {
var term = _.keys(this.range)[0];
this.range[term].gte = value;
var field = _.keys(this.range)[0];
this.range[field].gte = value;
return this;

@@ -25,4 +30,4 @@ };

RangeFilter.prototype.lt = function lt(value) {
var term = _.keys(this.range)[0];
this.range[term].lt = value;
var field = _.keys(this.range)[0];
this.range[field].lt = value;
return this;

@@ -32,5 +37,5 @@ };

RangeFilter.prototype.gt = function gt(value) {
var term = _.keys(this.range)[0];
this.range[term].gt = value;
var field = _.keys(this.range)[0];
this.range[field].gt = value;
return this;
};

@@ -6,8 +6,9 @@ 'use strict';

/**
* Elastic Term or Terms filter. Handles nested term filters if necessary.
* @param {termName} termName Term property - can be nested [x.y].
* @param {any} value Value to match property.
* @param {doNotNest} bool If true, will not automatically create nested term.
* @class Elastic Term or Terms filter. Automatically handles nested term filters if necessary.
* @augments {Filter}
* @param {string} fieldPath Field property - can be nested [x.y].
* @param {any} value Value to match property.
* @param {bool=} doNotNest If true, will not automatically create nested term.
*/
function TermFilter(termName, value, doNotNest) {
function TermFilter(fieldPath, value, doNotNest) {

@@ -18,6 +19,6 @@ //Build term or terms depending on value type.

//Check if we want to infer a nested term filter.
if (termName.indexOf('.') > -1 && !doNotNest) {
createNested(this, termName, value);
if (fieldPath.indexOf('.') > -1 && !doNotNest) {
createNested(this, fieldPath, value);
} else {
createTerm(this, termName, value, filterType);
createTerm(this, fieldPath, value, filterType);
}

@@ -33,5 +34,5 @@ }

function createTerm(scope, termName, value, filterType) {
function createTerm(scope, fieldPath, value, filterType) {
scope[filterType] = {};
scope[filterType][termName] = value;
scope[filterType][fieldPath] = value;
}

@@ -38,0 +39,0 @@

'use strict';
exports.ElasticQuery = require('./elasticQuery');
exports.ElasticClient = require('./elasticClient');
exports.MultiMatchQuery = require('./queries/multiMatchQuery');

@@ -7,0 +4,0 @@ exports.BoolQuery = require('./queries/boolQuery');

'use strict';
/**
* ElasticSearch boolean query.
* {@link http://www.elastic.co/guide/en/elasticsearch/reference/1.5/query-dsl-bool-query.html}
* @class ElasticSearch boolean query.
* {@link http://www.elastic.co/guide/en/elasticsearch/reference/1.x/query-dsl-bool-query.html}
*/

@@ -7,0 +7,0 @@ function BoolQuery() {

'use strict';
/**
* @class Elastic Match query
* @param {string} field Field to match against.
* @param {string} query Query to match againt.
*/
function MatchQuery(field, query) {

@@ -4,0 +9,0 @@ if (!field) {

'use strict';
/**
* Elastic match query allowing multiple fields.
* @class Elastic match query allowing multiple fields.
* {@link http://www.elastic.co/guide/en/elasticsearch/reference/1.x/query-dsl-multi-match-query.html}
* @param {string} query query string
* @param {Array} fields Array of fields to query on.
* @param {string} query query string
* @param {string[]} fields Array of fields to query on.
*/

@@ -14,3 +14,2 @@ function MultiMatchQuery(query, fields) {

};
};

@@ -30,3 +29,3 @@

* Set a tie breaker for the query to reduce the weight of additional matching fields.
* @param {[number]} weight Number between 0 and 1.
* @param {number[]} weight Number between 0 and 1.
*/

@@ -33,0 +32,0 @@ MultiMatchQuery.prototype.setTieBreaker = function setTieBreaker(weight) {

{
"name": "elastic-particles",
"version": "0.0.5",
"version": "0.0.7",
"description": "Building blocks for Elastic queries, filters, and aggregations which can be re-used, combed, and nested.",

@@ -35,5 +35,2 @@ "author": {

"dependencies": {
"bluebird": "^2.9.24",
"lodash": "~3.6.0",
"q-io": "^1.12.0"
},

@@ -43,3 +40,5 @@ "devDependencies": {

"assert": "~1.3.0",
"jshint": "~2.6.3"
"jshint": "~2.6.3",
"jsdoc": "~3.3.0-beta3",
"jsdoc-simple-template": "0.0.1"
},

@@ -63,4 +62,5 @@ "keywords": [

"test": "mocha",
"lint": "jshint -c test/.jshintrc lib"
"lint": "jshint -c test/.jshintrc lib",
"docs": "node ./node_modules/jsdoc/jsdoc.js -c jsdoc-config.json"
}
}
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