diff --git a/.gitignore b/.gitignore index f8a0a25..050fd90 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,15 @@ +# Logs +logs +*.log + +# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# Users Environment Variables +.lock-wscript +.idea + dist/docs node_modules/ + + diff --git a/dist/elastic.js b/dist/elastic.js index 7aca7ed..8c39146 100644 --- a/dist/elastic.js +++ b/dist/elastic.js @@ -1,6 +1,6 @@ -/*! elastic.js - v1.2.0 - 2014-10-13 +/*! elastic.js - v1.2.0 - 2018-05-08 * https://github.com/fullscale/elastic.js - * Copyright (c) 2014 FullScale Labs, LLC; Licensed MIT */ + * Copyright (c) 2018 FullScale Labs, LLC; Licensed MIT */ /** @namespace @@ -55,6 +55,7 @@ isSuggest, // checks valid ejs Suggest object isGenerator, // checks valid ejs Generator object isScoreFunction, // checks valid ejs ScoreFunction object + isScript, // checks valid ejs Script object // create ejs object ejs; @@ -232,6 +233,11 @@ return (isEJSObject(obj) && obj._type() === 'score function'); }; + isScript = function (obj) { + return (isEJSObject(obj) && obj._type() === 'script'); + }; + + /** @mixin

The AggregationMixin provides support for common options used across @@ -3785,6 +3791,61 @@ }); }; + /** + @class +

Defines a single bucket of all the documents in the current document set + context that match a specified filter. Often this will be used to narrow down + the current aggregation context to a specific set of documents.

+ + @name ejs.FilterAggregation + @ejs aggregation + @borrows ejs.AggregationMixin.aggregation as aggregation + @borrows ejs.AggregationMixin.agg as agg + @borrows ejs.AggregationMixin._type as _type + @borrows ejs.AggregationMixin.toJSON as toJSON + + @desc +

Defines a single bucket of all the documents that match a given filter.

+ + @param {String} name The name which be used to refer to this aggregation. + + */ + ejs.FiltersAggregation = function (name) { + + var + _common = ejs.AggregationMixin(name), + agg = _common.toJSON(); + + return extend(_common, { + + /** +

Sets the filters to be used for this aggregation.

+ + @member ejs.FilterAggregation + @param {Filter} oFilter A valid Filter object. + @returns {Object} returns this so that calls can be chained. + */ + filters: function (oFilters) { + if (oFilters == null) { + return agg[name].filters; + } + var filters = {}, key, oFilter; + agg[name].filters = { + filters: filters + }; + for (key in oFilters) { + oFilter = oFilters[key]; + if (!isFilter(oFilter)) { + throw new TypeError('Argument must be a Filter'); + } + filters[key] = oFilter.toJSON(); + } + return this; + } + + }); + }; + /** @class

A multi-bucket aggregation that works on geo_point fields and conceptually @@ -4805,11 +4866,15 @@ @returns {Object} returns this so that calls can be chained. */ compression: function (c) { + var tdigest = agg[name].percentiles.tdigest; if (c == null) { - return agg[name].percentiles.compression; + return tdigest && tdigest.compression; + } + if (!tdigest) { + tdigest = agg[name].percentiles.tdigest = {}; } - agg[name].percentiles.compression = c; + tdigest.compression = c; return this; } @@ -4987,6 +5052,54 @@ }); }; + /** + @class +

A special single bucket aggregation that enables aggregating nested + documents.

+ + @name ejs.ReverseNestedAggregation + @ejs aggregation + @borrows ejs.AggregationMixin.aggregation as aggregation + @borrows ejs.AggregationMixin.agg as agg + @borrows ejs.AggregationMixin._type as _type + @borrows ejs.AggregationMixin.toJSON as toJSON + + @desc +

A special single bucket aggregation that enables aggregating nested + documents.

+ + @param {String} name The name which be used to refer to this aggregation. + + */ + ejs.ReverseNestedAggregation = function (name) { + + var + _common = ejs.AggregationMixin(name), + agg = _common.toJSON(); + + agg[name].reverse_nested = {}; + + return extend(_common, { + + /** +

Sets the nested path.

+ + @member ejs.ReverseNestedAggregation + @param {String} path The nested path value. + @returns {Object} returns this so that calls can be chained. + */ + reversePath: function (path) { + if (path == null) { + return agg[name].reverse_nested.path; + } + + agg[name].reverse_nested.path = path; + return this; + } + + }); + }; + /** @class

An aggregation that returns interesting or unusual occurrences of terms in @@ -5587,6 +5700,11 @@ _common = ejs.MetricsAggregationMixin(name, 'top_hits'), agg = _common.toJSON(); + agg[name].top_hits = { + size: 0, + from: 0 + }; + return extend(_common, { /**

The offset from the first result you want to fetch.

@@ -5596,7 +5714,7 @@ @returns {Object} returns this so that calls can be chained. */ from: function (from) { - if (from === null) { + if (from == null) { return agg[name].top_hits.from; } @@ -5612,7 +5730,7 @@ @returns {Object} returns this so that calls can be chained. */ size: function (size) { - if (size === null) { + if (size == null) { return agg[name].top_hits.size; } @@ -5623,16 +5741,80 @@ /**

The maximum number of top matching hits to return per bucket.

+
+
sort() - The current sorting values are returned.
+
sort(fieldName) - Adds the field to the current list of sorting values.
+
sort(fieldName, order) - Adds the field to the current list of + sorting with the specified order. Order must be asc or desc.
+
sort(ejs.Sort) - Adds the Sort value to the current list of sorting values.
+
sort(array) - Replaces all current sorting values with values + from the array. The array must contain only strings and Sort objects.
+
+ +

Multi-level sorting is supported so the order in which sort fields + are added to the query requests is relevant.

+ +

It is recommended to use Sort objects when possible.

+ @member ejs.TopHitsAggregation @param {Array} sort How to sort the the top matching hits @returns {Object} returns this so that calls can be chained. */ - sort: function (sort) { - if (sort === null) { - return agg[name].top_hits.sort; + sort: function () { + var i, len; + var query = agg[name].top_hits; + + if (!has(query, "sort")) { + query.sort = []; + } + + if (arguments.length === 0) { + return query.sort; + } + + // if passed a single argument + if (arguments.length === 1) { + var sortVal = arguments[0]; + + if (isString(sortVal)) { + // add a single field name + query.sort.push(sortVal); + } else if (isSort(sortVal)) { + // add the Sort object + query.sort.push(sortVal.toJSON()); + } else if (isArray(sortVal)) { + // replace with all values in the array + // the values must be a fieldName (string) or a + // Sort object. Any other type throws an Error. + query.sort = []; + for (i = 0, len = sortVal.length; i < len; i++) { + if (isString(sortVal[i])) { + query.sort.push(sortVal[i]); + } else if (isSort(sortVal[i])) { + query.sort.push(sortVal[i].toJSON()); + } else { + throw new TypeError('Invalid object in array'); + } + } + } else { + // Invalid object type as argument. + throw new TypeError('Argument must be string, Sort, or array'); + } + } else if (arguments.length === 2) { + // handle the case where a single field name and order are passed + var field = arguments[0], + order = arguments[1]; + + if (isString(field) && isString(order)) { + order = order.toLowerCase(); + if (order === 'asc' || order === 'desc') { + var sortObj = {}; + sortObj[field] = {order: order}; + query.sort.push(sortObj); + } + } } - agg[name].top_hits.sort = sort; return this; }, @@ -5645,7 +5827,7 @@ @returns {Object} returns this so that calls can be chained. */ trackScores: function (trueFalse) { - if (trueFalse === null) { + if (trueFalse == null) { return agg[name].top_hits.track_scores; } @@ -5661,7 +5843,7 @@ @returns {Object} returns this so that calls can be chained. */ version: function (trueFalse) { - if (trueFalse === null) { + if (trueFalse == null) { return agg[name].top_hits.version; } @@ -5677,7 +5859,7 @@ @returns {Object} returns this so that calls can be chained. */ explain: function (trueFalse) { - if (trueFalse === null) { + if (trueFalse == null) { return agg[name].top_hits.explain; } @@ -5693,7 +5875,7 @@ @returns {Object} returns this so that calls can be chained. */ highlight: function (h) { - if (h === null) { + if (h == null) { return agg[name].top_hits.highlight; } @@ -5713,11 +5895,11 @@ @returns {Object} returns this so that calls can be chained. */ scriptField: function (oScriptField) { - if (oScriptField === null) { + if (oScriptField == null) { return agg[name].top_hits.script_fields; } - if (agg[name].top_hits.script_fields === undefined) { + if (agg[name].top_hits.script_fields == null) { agg[name].top_hits.script_fields = {}; } @@ -5736,12 +5918,24 @@ @param {Array} Fields to return field data representation for. @returns {Object} returns this so that calls can be chained. */ - fieldDataFields: function (fielddata_fields) { - if (fielddata_fields === null) { - return agg[name].top_hits.fielddata_fields; + docValueFields: function (fieldList) { + var query = agg[name].top_hits; + if (fieldList == null) { + return query.docvalue_fields; + } + + if (query.docvalue_fields == null) { + query.docvalue_fields = []; + } + + if (isString(fieldList)) { + query.docvalue_fields.push(fieldList); + } else if (isArray(fieldList)) { + query.docvalue_fields = fieldList; + } else { + throw new TypeError('Argument must be a string or an array'); } - agg[name].top_hits.fielddata_fields = fielddata_fields; return this; }, @@ -5759,27 +5953,28 @@ @returns {Object} returns this so that calls can be chained. */ source: function (includes, excludes) { - if (includes === undefined && excludes === undefined) { - return agg[name].top_hits._source; + var query = agg[name].top_hits; + if (includes == null && excludes == null) { + return query._source; } if (!isArray(includes) && !isString(includes) && !isBoolean(includes)) { throw new TypeError('Argument includes must be a string, an array, or a boolean'); } - if (excludes !== undefined && !isArray(excludes) && !isString(excludes)) { + if (excludes != null && !isArray(excludes) && !isString(excludes)) { throw new TypeError('Argument excludes must be a string or an array'); } if (isBoolean(includes)) { - agg[name].top_hits._source = includes; + query._source = includes; } else { - agg[name].top_hits._source = { + query._source = { includes: includes }; - if (excludes !== undefined) { - agg[name].top_hits._source = excludes; + if (excludes != null) { + query._source.excludes = excludes; } } @@ -6324,11 +6519,11 @@ return filter.geo_distance.distance; } - if (!isNumber(numericDistance)) { - throw new TypeError('Argument must be a numeric value'); + if (!isNumber(numericDistance) && !isString(numericDistance)) { + throw new TypeError('Argument must be a numeric or string value'); } - filter.geo_distance.distance = numericDistance; + filter.geo_distance.distance = numericDistance + ""; return this; }, @@ -9176,8 +9371,28 @@ query.bool.minimum_number_should_match = minMatch; return this; + }, + + /** + Adds the filter to apply a constant score to. + + @member ejs.BoolQuery + @param {Object} oFilter A valid Filter object + @returns {Object} returns this so that calls can be chained. + */ + filter: function (oFilter) { + if (oFilter == null) { + return query.bool.filter; + } + + if (!isFilter(oFilter)) { + throw new TypeError('Argument must be a Filter'); + } + + query.bool.filter = oFilter.toJSON(); + return this; } - + }); }; @@ -15131,6 +15346,81 @@ }); }; + /** + @class +

The script_score function allows you to wrap another query and customize + the scoring of it optionally with a computation derived from other numeric + field values in the doc using a script expression.

+ + @name ejs.FieldValueScoreFunction + @ejs scorefunction + @borrows ejs.ScoreFunctionMixin.filter as filter + @borrows ejs.ScoreFunctionMixin._type as _type + @borrows ejs.ScoreFunctionMixin.toJSON as toJSON + + @desc +

Modify a documents score using a script.

+ + */ + ejs.FieldValueScoreFunction = function () { + + var + _common = ejs.ScoreFunctionMixin('field_value_factor'), + func = _common.toJSON(); + + return extend(_common, { + + /** + Set the field that will modify the score. + + @member ejs.FieldValueScoreFunction + @param {String} field A valid field string. + @returns {Object} returns this so that calls can be chained. + */ + field: function (field) { + if (field == null) { + return func.field_value_factor.field; + } + + func.field_value_factor.field = field; + return this; + }, + + /** + The factor being used. + + @member ejs.FieldValueScoreFunction + @param {String} factor The factor. + @returns {Object} returns this so that calls can be chained. + */ + factor: function (factor) { + if (factor == null) { + return func.field_value_factor.factor; + } + + func.field_value_factor.factor = factor; + return this; + }, + + /** + The modifier being used. + + @member ejs.FieldValueScoreFunction + @param {String} factor The modifier. + @returns {Object} returns this so that calls can be chained. + */ + modifier: function (modifier) { + if (modifier == null) { + return func.field_value_factor.modifier; + } + + func.field_value_factor.modifier = modifier; + return this; + } + + }); + }; + /** @class

The random_score generates scores via a pseudo random number algorithm @@ -15204,51 +15494,141 @@ @param {String} scriptCode A valid script string to execute. @returns {Object} returns this so that calls can be chained. */ - script: function (scriptCode) { - if (scriptCode == null) { + script: function (oScript) { + if (oScript == null) { return func.script_score.script; } - func.script_score.script = scriptCode; + if (!isScript(oScript)) { + throw new TypeError('Argument must be a Script'); + } + + func.script_score.script = oScript.toJSON(); return this; }, + }); + }; + + /** + @class +

Script's allow you create srcipt to call it at script score + + @name ejs.Script + @ejs request + + @desc +

Computes dynamic document properties based on information from other fields.

+ + @param {String} fieldName A name of the script field to create. + + */ + ejs.Script = function (fieldName) { + var script = {}; + + return { /** - The script language being used. + The script language being used. Currently supported values are + javascript and mvel. - @member ejs.ScriptScoreFunction - @param {String} language The language of the script. - @returns {Object} returns this so that calls can be chained. - */ + @member ejs.Script + @param {String} language The language of the script. + @returns {Object} returns this so that calls can be chained. + */ lang: function (language) { if (language == null) { - return func.script_score.lang; + return script.lang; } + + script.lang = language; + return this; + }, + + /** + Sets the script/code that will be used to perform the calculation. - func.script_score.lang = language; + @member ejs.Script + @param {String} expression The script/code to use. + @returns {Object} returns this so that calls can be chained. + */ + inline: function (expression) { + if (expression == null) { + return script.inline; + } + + script.inline = expression; return this; }, /** - Sets parameters that will be applied to the script. Overwrites - any existing params. + Sets the script/code file that will be used to perform the calculation. - @member ejs.ScriptScoreFunction - @param {Object} p An object where the keys are the parameter name and - values are the parameter value. - @returns {Object} returns this so that calls can be chained. - */ - params: function (p) { - if (p == null) { - return func.script_score.params; + @member ejs.Script + @param {String} file The script/code to use. + @returns {Object} returns this so that calls can be chained. + */ + file: function (file) { + if (file == null) { + return script.file; } - func.script_score.params = p; + script.file = file; return this; - } + }, + /** + Allows you to set script parameters to be used during the execution of the script. - }); + @member ejs.Script + @param {Object} oParams An object containing key/value pairs representing param name/value. + @returns {Object} returns this so that calls can be chained. + */ + params: function (oParams) { + if (oParams == null) { + return script.params; + } + + script.params = oParams; + return this; + }, + + /** + Set the script id that will modify the score. + + @member ejs.Script + @param {Boolean} string + @returns {Object} returns this so that calls can be chained. + */ + scriptId: function (scriptId) { + if (scriptId == null) { + return script.id; + } + + script.id = scriptId; + return this; + }, + + /** + The type of ejs object. For internal use only. + + @member ejs.Script + @returns {String} the type of object + */ + _type: function () { + return 'script'; + }, + + /** + Retrieves the internal script object. This is typically used by + internal API functions so use with caution. + + @member ejs.Script + @returns {String} returns this object's internal facet property. + */ + toJSON: function () { + return script; + } + }; }; /** @@ -16180,6 +16560,26 @@ return this; }, + docValueFields: function (fieldList) { + if (fieldList == null) { + return query.docvalue_fields; + } + + if (query.docvalue_fields == null) { + query.docvalue_fields = []; + } + + if (isString(fieldList)) { + query.docvalue_fields.push(fieldList); + } else if (isArray(fieldList)) { + query.docvalue_fields = fieldList; + } else { + throw new TypeError('Argument must be a string or an array'); + } + + return this; + }, + /** Allows to control how the _source field is returned with every hit. By default operations return the contents of the _source field @@ -16339,14 +16739,14 @@ */ filter: function (filter) { if (filter == null) { - return query.filter; + return query.post_filter; } if (!isFilter(filter)) { throw new TypeError('Argument must be a Filter'); } - query.filter = filter.toJSON(); + query.post_filter = filter.toJSON(); return this; }, diff --git a/dist/elastic.min.js b/dist/elastic.min.js index e12d3d5..c08e9cb 100644 --- a/dist/elastic.min.js +++ b/dist/elastic.min.js @@ -1,8 +1,8 @@ -/*! elastic.js - v1.2.0 - 2014-10-13 +/*! elastic.js - v1.2.0 - 2018-05-08 * https://github.com/fullscale/elastic.js - * Copyright (c) 2014 FullScale Labs, LLC; Licensed MIT */ + * Copyright (c) 2018 FullScale Labs, LLC; Licensed MIT */ -(function(){"use strict";var a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,A=this,B=A&&A.ejs,C=Array.prototype,D=Object.prototype,E=C.slice,F=D.toString,G=D.hasOwnProperty,H=C.forEach,I=Array.isArray,J=C.indexOf,K={};z="undefined"!=typeof exports?exports:A.ejs={},a=function(a,b){return G.call(a,b)},b=function(b,c,d){if(null!=b)if(H&&b.forEach===H)b.forEach(c,d);else if(b.length===+b.length){for(var e=0,f=b.length;f>e;e++)if(c.call(d,b[e],e,b)===K)return}else for(var g in b)if(a(b,g)&&c.call(d,b[g],g,b)===K)return},c=function(a){return b(E.call(arguments,1),function(b){for(var c in b)a[c]=b[c]}),a},d=function(a,b){if(null==a)return-1;var c=0,d=a.length;if(J&&a.indexOf===J)return a.indexOf(b);for(;d>c;c++)if(a[c]===b)return c;return-1},e=I||function(a){return"[object Array]"===F.call(a)},f=function(a){return a===Object(a)},g=function(a){return"[object String]"===F.call(a)},h=function(a){return"[object Number]"===F.call(a)},i=function(a){return a===!0||a===!1||"[object Boolean]"===F.call(a)},j="function"!=typeof/./?function(a){return"function"==typeof a}:function(a){return"[object Function]"===F.call(a)},k=function(b){return f(b)&&a(b,"_type")&&a(b,"toJSON")},l=function(a){return k(a)&&"query"===a._type()},m=function(a){return k(a)&&"rescore"===a._type()},n=function(a){return k(a)&&"filter"===a._type()},o=function(a){return k(a)&&"facet"===a._type()},p=function(a){return k(a)&&"aggregation"===a._type()},q=function(a){return k(a)&&"script field"===a._type()},r=function(a){return k(a)&&"geo point"===a._type()},s=function(a){return k(a)&&"indexed shape"===a._type()},t=function(a){return k(a)&&"shape"===a._type()},u=function(a){return k(a)&&"sort"===a._type()},v=function(a){return k(a)&&"highlight"===a._type()},w=function(a){return k(a)&&"suggest"===a._type()},x=function(a){return k(a)&&"generator"===a._type()},y=function(a){return k(a)&&"score function"===a._type()},z.AggregationMixin=function(a){var b={};return b[a]={},{aggregation:function(d){if(null==d)return b[a].aggs;if(null==b[a].aggs&&(b[a].aggs={}),!p(d))throw new TypeError("Argument must be an Aggregation");return c(b[a].aggs,d.toJSON()),this},agg:function(a){return this.aggregation(a)},_type:function(){return"aggregation"},toJSON:function(){return b}}},z.DirectSettingsMixin=function(a){return{accuracy:function(b){return null==b?a.accuracy:(a.accuracy=b,this)},suggestMode:function(b){return null==b?a.suggest_mode:(b=b.toLowerCase(),("missing"===b||"popular"===b||"always"===b)&&(a.suggest_mode=b),this)},sort:function(b){return null==b?a.sort:(b=b.toLowerCase(),("score"===b||"frequency"===b)&&(a.sort=b),this)},stringDistance:function(b){return null==b?a.string_distance:(b=b.toLowerCase(),("internal"===b||"damerau_levenshtein"===b||"levenstein"===b||"jarowinkler"===b||"ngram"===b)&&(a.string_distance=b),this)},maxEdits:function(b){return null==b?a.max_edits:(a.max_edits=b,this)},maxInspections:function(b){return null==b?a.max_inspections:(a.max_inspections=b,this)},maxTermFreq:function(b){return null==b?a.max_term_freq:(a.max_term_freq=b,this)},prefixLen:function(b){return null==b?a.prefix_len:(a.prefix_len=b,this)},minWordLen:function(b){return null==b?a.min_word_len:(a.min_word_len=b,this)},minDocFreq:function(b){return null==b?a.min_doc_freq:(a.min_doc_freq=b,this)}}},z.FacetMixin=function(a){var b={};return b[a]={},{facetFilter:function(c){if(null==c)return b[a].facet_filter;if(!n(c))throw new TypeError("Argument must be a Filter");return b[a].facet_filter=c.toJSON(),this},global:function(c){return null==c?b[a].global:(b[a].global=c,this)},mode:function(c){return null==c?b[a].mode:(c=c.toLowerCase(),("collector"===c||"post"===c)&&(b[a].mode=c),this)},cacheFilter:function(c){return null==c?b[a].cache_filter:(b[a].cache_filter=c,this)},scope:function(){return this},nested:function(c){return null==c?b[a].nested:(b[a].nested=c,this)},_type:function(){return"facet"},toJSON:function(){return b}}},z.FilterMixin=function(a){var b={};return b[a]={},{name:function(c){return null==c?b[a]._name:(b[a]._name=c,this)},cache:function(c){return null==c?b[a]._cache:(b[a]._cache=c,this)},cacheKey:function(c){return null==c?b[a]._cache_key:(b[a]._cache_key=c,this)},_type:function(){return"filter"},toJSON:function(){return b}}},z.MetricsAggregationMixin=function(a,b){var d=z.AggregationMixin(a),e=d.toJSON();return delete d.aggregation,delete d.agg,e[a][b]={},c(d,{field:function(c){return null==c?e[a][b].field:(e[a][b].field=c,this)},script:function(c){return null==c?e[a][b].script:(e[a][b].script=c,this)},lang:function(c){return null==c?e[a][b].lang:(e[a][b].lang=c,this)},scriptValuesSorted:function(c){return null==c?e[a][b].script_values_sorted:(e[a][b].script_values_sorted=c,this)},params:function(c){return null==c?e[a][b].params:(e[a][b].params=c,this)}})},z.QueryMixin=function(a){var b={};return b[a]={},{boost:function(c){return null==c?b[a].boost:(b[a].boost=c,this)},_type:function(){return"query"},toJSON:function(){return b}}},z.ScoreFunctionMixin=function(a){var b={};return b[a]={},{filter:function(a){if(null==a)return b.filter;if(!n(a))throw new TypeError("Argument must be a Filter");return b.filter=a.toJSON(),this},_type:function(){return"score function"},toJSON:function(){return b}}},z.SuggestContextMixin=function(a){return{analyzer:function(b){return null==b?a.analyzer:(a.analyzer=b,this)},field:function(b){return null==b?a.field:(a.field=b,this)},size:function(b){return null==b?a.size:(a.size=b,this)},shardSize:function(b){return null==b?a.shard_size:(a.shard_size=b,this)}}},z.SuggesterMixin=function(a){var b={};return b[a]={},{text:function(c){return null==c?b[a].text:(b[a].text=c,this)},_type:function(){return"suggest"},toJSON:function(){return b}}},z.DateHistogramFacet=function(a){var b=z.FacetMixin(a),d=b.toJSON();return d[a].date_histogram={},c(b,{field:function(b){return null==b?d[a].date_histogram.field:(d[a].date_histogram.field=b,this)},keyField:function(b){return null==b?d[a].date_histogram.key_field:(d[a].date_histogram.key_field=b,this)},valueField:function(b){return null==b?d[a].date_histogram.value_field:(d[a].date_histogram.value_field=b,this)},interval:function(b){return null==b?d[a].date_histogram.interval:(d[a].date_histogram.interval=b,this)},timeZone:function(b){return null==b?d[a].date_histogram.time_zone:(d[a].date_histogram.time_zone=b,this)},preZone:function(b){return null==b?d[a].date_histogram.pre_zone:(d[a].date_histogram.pre_zone=b,this)},preZoneAdjustLargeInterval:function(b){return null==b?d[a].date_histogram.pre_zone_adjust_large_interval:(d[a].date_histogram.pre_zone_adjust_large_interval=b,this)},postZone:function(b){return null==b?d[a].date_histogram.post_zone:(d[a].date_histogram.post_zone=b,this)},preOffset:function(b){return null==b?d[a].date_histogram.pre_offset:(d[a].date_histogram.pre_offset=b,this)},postOffset:function(b){return null==b?d[a].date_histogram.post_offset:(d[a].date_histogram.post_offset=b,this)},factor:function(b){return null==b?d[a].date_histogram.factor:(d[a].date_histogram.factor=b,this)},valueScript:function(b){return null==b?d[a].date_histogram.value_script:(d[a].date_histogram.value_script=b,this)},order:function(b){return null==b?d[a].date_histogram.order:(b=b.toLowerCase(),("time"===b||"count"===b||"total"===b)&&(d[a].date_histogram.order=b),this)},lang:function(b){return null==b?d[a].date_histogram.lang:(d[a].date_histogram.lang=b,this)},params:function(b){return null==b?d[a].date_histogram.params:(d[a].date_histogram.params=b,this)}})},z.FilterFacet=function(a){var b=z.FacetMixin(a),d=b.toJSON();return c(b,{filter:function(b){if(null==b)return d[a].filter;if(!n(b))throw new TypeError("Argument must be a Filter");return d[a].filter=b.toJSON(),this}})},z.GeoDistanceFacet=function(a){var b=z.FacetMixin(a),d=b.toJSON(),e=z.GeoPoint([0,0]),f="location";return d[a].geo_distance={location:e.toJSON(),ranges:[]},c(b,{field:function(b){var c=d[a].geo_distance[f];return null==b?f:(delete d[a].geo_distance[f],f=b,d[a].geo_distance[b]=c,this)},point:function(b){if(null==b)return e;if(!r(b))throw new TypeError("Argument must be a GeoPoint");return e=b,d[a].geo_distance[f]=b.toJSON(),this},addRange:function(b,c){return 0===arguments.length?d[a].geo_distance.ranges:(d[a].geo_distance.ranges.push({from:b,to:c}),this)},addUnboundedFrom:function(b){return null==b?d[a].geo_distance.ranges:(d[a].geo_distance.ranges.push({from:b}),this)},addUnboundedTo:function(b){return null==b?d[a].geo_distance.ranges:(d[a].geo_distance.ranges.push({to:b}),this)},unit:function(b){return null==b?d[a].geo_distance.unit:(b=b.toLowerCase(),("mi"===b||"km"===b)&&(d[a].geo_distance.unit=b),this)},distanceType:function(b){return null==b?d[a].geo_distance.distance_type:(b=b.toLowerCase(),("arc"===b||"plane"===b)&&(d[a].geo_distance.distance_type=b),this)},normalize:function(b){return null==b?d[a].geo_distance.normalize:(d[a].geo_distance.normalize=b,this)},valueField:function(b){return null==b?d[a].geo_distance.value_field:(d[a].geo_distance.value_field=b,this)},valueScript:function(b){return null==b?d[a].geo_distance.value_script:(d[a].geo_distance.value_script=b,this)},lang:function(b){return null==b?d[a].geo_distance.lang:(d[a].geo_distance.lang=b,this)},params:function(b){return null==b?d[a].geo_distance.params:(d[a].geo_distance.params=b,this)}})},z.HistogramFacet=function(a){var b=z.FacetMixin(a),d=b.toJSON();return d[a].histogram={},c(b,{field:function(b){return null==b?d[a].histogram.field:(d[a].histogram.field=b,this)},interval:function(b){return null==b?d[a].histogram.interval:(d[a].histogram.interval=b,this)},timeInterval:function(b){return null==b?d[a].histogram.time_interval:(d[a].histogram.time_interval=b,this)},from:function(b){return null==b?d[a].histogram.from:(d[a].histogram.from=b,this)},to:function(b){return null==b?d[a].histogram.to:(d[a].histogram.to=b,this)},valueField:function(b){return null==b?d[a].histogram.value_field:(d[a].histogram.value_field=b,this)},keyField:function(b){return null==b?d[a].histogram.key_field:(d[a].histogram.key_field=b,this)},valueScript:function(b){return null==b?d[a].histogram.value_script:(d[a].histogram.value_script=b,this)},keyScript:function(b){return null==b?d[a].histogram.key_script:(d[a].histogram.key_script=b,this)},lang:function(b){return null==b?d[a].histogram.lang:(d[a].histogram.lang=b,this)},params:function(b){return null==b?d[a].histogram.params:(d[a].histogram.params=b,this)},order:function(b){return null==b?d[a].histogram.order:(b=b.toLowerCase(),("key"===b||"count"===b||"total"===b)&&(d[a].histogram.order=b),this)}})},z.QueryFacet=function(a){var b=z.FacetMixin(a),d=b.toJSON();return c(b,{query:function(b){if(null==b)return d[a].query;if(!l(b))throw new TypeError("Argument must be a Query");return d[a].query=b.toJSON(),this}})},z.RangeFacet=function(a){var b=z.FacetMixin(a),d=b.toJSON();return d[a].range={ranges:[]},c(b,{field:function(b){return null==b?d[a].range.field:(d[a].range.field=b,this)},keyField:function(b){return null==b?d[a].range.key_field:(d[a].range.key_field=b,this)},valueField:function(b){return null==b?d[a].range.value_field:(d[a].range.value_field=b,this)},valueScript:function(b){return null==b?d[a].range.value_script:(d[a].range.value_script=b,this)},keyScript:function(b){return null==b?d[a].range.key_script:(d[a].range.key_script=b,this)},lang:function(b){return null==b?d[a].range.lang:(d[a].range.lang=b,this)},params:function(b){return null==b?d[a].range.params:(d[a].range.params=b,this)},addRange:function(b,c){return 0===arguments.length?d[a].range.ranges:(d[a].range.ranges.push({from:b,to:c}),this)},addUnboundedFrom:function(b){return null==b?d[a].range.ranges:(d[a].range.ranges.push({from:b}),this)},addUnboundedTo:function(b){return null==b?d[a].range.ranges:(d[a].range.ranges.push({to:b}),this)}})},z.StatisticalFacet=function(a){var b=z.FacetMixin(a),d=b.toJSON();return d[a].statistical={},c(b,{field:function(b){return null==b?d[a].statistical.field:(d[a].statistical.field=b,this)},fields:function(b){if(null==b)return d[a].statistical.fields;if(!e(b))throw new TypeError("Argument must be an array");return d[a].statistical.fields=b,this},script:function(b){return null==b?d[a].statistical.script:(d[a].statistical.script=b,this)},lang:function(b){return null==b?d[a].statistical.lang:(d[a].statistical.lang=b,this)},params:function(b){return null==b?d[a].statistical.params:(d[a].statistical.params=b,this)}})},z.TermStatsFacet=function(a){var b=z.FacetMixin(a),d=b.toJSON();return d[a].terms_stats={},c(b,{valueField:function(b){return null==b?d[a].terms_stats.value_field:(d[a].terms_stats.value_field=b,this)},keyField:function(b){return null==b?d[a].terms_stats.key_field:(d[a].terms_stats.key_field=b,this)},scriptField:function(b){return null==b?d[a].terms_stats.script_field:(d[a].terms_stats.script_field=b,this)},valueScript:function(b){return null==b?d[a].terms_stats.value_script:(d[a].terms_stats.value_script=b,this)},allTerms:function(b){return null==b?d[a].terms_stats.all_terms:(d[a].terms_stats.all_terms=b,this)},lang:function(b){return null==b?d[a].terms_stats.lang:(d[a].terms_stats.lang=b,this)},params:function(b){return null==b?d[a].terms_stats.params:(d[a].terms_stats.params=b,this)},size:function(b){return null==b?d[a].terms_stats.size:(d[a].terms_stats.size=b,this)},order:function(b){return null==b?d[a].terms_stats.order:(b=b.toLowerCase(),("count"===b||"term"===b||"reverse_count"===b||"reverse_term"===b||"total"===b||"reverse_total"===b||"min"===b||"reverse_min"===b||"max"===b||"reverse_max"===b||"mean"===b||"reverse_mean"===b)&&(d[a].terms_stats.order=b),this)}})},z.TermsFacet=function(a){var b=z.FacetMixin(a),d=b.toJSON();return d[a].terms={},c(b,{field:function(b){return null==b?d[a].terms.field:(d[a].terms.field=b,this)},fields:function(b){if(null==b)return d[a].terms.fields;if(!e(b))throw new TypeError("Argument must be an array");return d[a].terms.fields=b,this},scriptField:function(b){return null==b?d[a].terms.script_field:(d[a].terms.script_field=b,this)},size:function(b){return null==b?d[a].terms.size:(d[a].terms.size=b,this)},shardSize:function(b){return null==b?d[a].terms.shard_size:(d[a].terms.shard_size=b,this)},order:function(b){return null==b?d[a].terms.order:(b=b.toLowerCase(),("count"===b||"term"===b||"reverse_count"===b||"reverse_term"===b)&&(d[a].terms.order=b),this)},allTerms:function(b){return null==b?d[a].terms.all_terms:(d[a].terms.all_terms=b,this)},exclude:function(b){if(null==d[a].terms.exclude&&(d[a].terms.exclude=[]),null==b)return d[a].terms.exclude;if(g(b))d[a].terms.exclude.push(b);else{if(!e(b))throw new TypeError("Argument must be string or array");d[a].terms.exclude=b}return this},regex:function(b){return null==b?d[a].terms.regex:(d[a].terms.regex=b,this)},regexFlags:function(b){return null==b?d[a].terms.regex_flags:(d[a].terms.regex_flags=b,this)},script:function(b){return null==b?d[a].terms.script:(d[a].terms.script=b,this)},lang:function(b){return null==b?d[a].terms.lang:(d[a].terms.lang=b,this)},params:function(b){return null==b?d[a].terms.params:(d[a].terms.params=b,this)},executionHint:function(b){return null==b?d[a].terms.execution_hint:(d[a].terms.execution_hint=b,this)}})},z.AvgAggregation=function(a){{var b=z.MetricsAggregationMixin(a,"avg");b.toJSON()}return b},z.CardinalityAggregation=function(a){var b=z.MetricsAggregationMixin(a,"cardinality"),d=b.toJSON();return delete b.scriptValuesSorted,c(b,{rehash:function(b){return null==b?d[a].cardinality.rehash:(d[a].cardinality.rehash=b,this)},precisionThreshold:function(b){return null==b?d[a].cardinality.precision_threshold:(d[a].cardinality.precision_threshold=b,this)}})},z.DateHistogramAggregation=function(a){var b=z.AggregationMixin(a),d=b.toJSON();return d[a].date_histogram={},c(b,{field:function(b){return null==b?d[a].date_histogram.field:(d[a].date_histogram.field=b,this)},script:function(b){return null==b?d[a].date_histogram.script:(d[a].date_histogram.script=b,this)},lang:function(b){return null==b?d[a].date_histogram.lang:(d[a].date_histogram.lang=b,this)},timeZone:function(b){return null==b?d[a].date_histogram.time_zone:(d[a].date_histogram.time_zone=b,this)},preZone:function(b){return null==b?d[a].date_histogram.pre_zone:(d[a].date_histogram.pre_zone=b,this)},postZone:function(b){return null==b?d[a].date_histogram.post_zone:(d[a].date_histogram.post_zone=b,this)},preOffset:function(b){return null==b?d[a].date_histogram.pre_offset:(d[a].date_histogram.pre_offset=b,this)},postOffset:function(b){return null==b?d[a].date_histogram.post_offset:(d[a].date_histogram.post_offset=b,this)},extendedBounds:function(b,c){var e;return null==b&&null==c?d[a].date_histogram.extended_bounds:(e={},null!=b&&(e.min=b),null!=c&&(e.max=c),d[a].date_histogram.extended_bounds=e,this)},interval:function(b){return null==b?d[a].date_histogram.interval:(d[a].date_histogram.interval=b,this)},format:function(b){return null==b?d[a].date_histogram.format:(d[a].date_histogram.format=b,this)},keyed:function(b){return null==b?d[a].date_histogram.keyed:(d[a].date_histogram.keyed=b,this)},scriptValuesSorted:function(b){return null==b?d[a].date_histogram.script_values_sorted:(d[a].date_histogram.script_values_sorted=b,this)},preZoneAdjustLargeInterval:function(b){return null==b?d[a].date_histogram.pre_zone_adjust_large_interval:(d[a].date_histogram.pre_zone_adjust_large_interval=b,this)},minDocCount:function(b){return null==b?d[a].date_histogram.min_doc_count:(d[a].date_histogram.min_doc_count=b,this)},params:function(b){return null==b?d[a].date_histogram.params:(d[a].date_histogram.params=b,this)},order:function(b,c){return null==b?d[a].date_histogram.order:(null==c&&(c="desc"),c=c.toLowerCase(),"asc"!==c&&"desc"!==c&&(c="desc"),d[a].date_histogram.order={},d[a].date_histogram.order[b]=c,this)}})},z.DateRangeAggregation=function(a){var b=z.AggregationMixin(a),d=b.toJSON();return d[a].date_range={},c(b,{field:function(b){return null==b?d[a].date_range.field:(d[a].date_range.field=b,this)},script:function(b){return null==b?d[a].date_range.script:(d[a].date_range.script=b,this)},lang:function(b){return null==b?d[a].date_range.lang:(d[a].date_range.lang=b,this)},format:function(b){return null==b?d[a].date_range.format:(d[a].date_range.format=b,this)},range:function(b,c,e){var f={};return null==d[a].date_range.ranges&&(d[a].date_range.ranges=[]),null==b&&null==c?d[a].date_range.ranges:(null!=b&&(f.from=b),null!=c&&(f.to=c),null!=e&&(f.key=e),d[a].date_range.ranges.push(f),this)},keyed:function(b){return null==b?d[a].date_range.keyed:(d[a].date_range.keyed=b,this)},scriptValuesSorted:function(b){return null==b?d[a].date_range.script_values_sorted:(d[a].date_range.script_values_sorted=b,this)},params:function(b){return null==b?d[a].date_range.params:(d[a].date_range.params=b,this)}})},z.ExtendedStatsAggregation=function(a){{var b=z.MetricsAggregationMixin(a,"extended_stats");b.toJSON()}return b},z.FilterAggregation=function(a){var b=z.AggregationMixin(a),d=b.toJSON();return c(b,{filter:function(b){if(null==b)return d[a].filter;if(!n(b))throw new TypeError("Argument must be a Filter");return d[a].filter=b.toJSON(),this}})},z.GeoDistanceAggregation=function(a){var b=z.AggregationMixin(a),d=z.GeoPoint([0,0]),e=b.toJSON();return e[a].geo_distance={},c(b,{field:function(b){return null==b?e[a].geo_distance.field:(e[a].geo_distance.field=b,this)},unit:function(b){return null==b?e[a].geo_distance.unit:(("in"===b||"yd"===b||"ft"===b||"km"===b||"NM"===b||"mm"===b||"cm"===b||"mi"===b||"m"===b)&&(e[a].geo_distance.unit=b),this)},distanceType:function(b){return null==b?e[a].geo_distance.distance_type:(b=b.toLowerCase(),("plane"===b||"arc"===b||"sloppy_arc"===b||"factor"===b)&&(e[a].geo_distance.distance_type=b),this)},origin:function(b){if(null==b)return d;if(!r(b))throw new TypeError("Argument must be a GeoPoint");return d=b,e[a].geo_distance.origin=b.toJSON(),this},point:function(b){if(null==b)return d;if(!r(b))throw new TypeError("Argument must be a GeoPoint");return d=b,e[a].geo_distance.point=b.toJSON(),this},center:function(b){if(null==b)return d;if(!r(b))throw new TypeError("Argument must be a GeoPoint");return d=b,e[a].geo_distance.center=b.toJSON(),this},range:function(b,c,d){var f={};return null==e[a].geo_distance.ranges&&(e[a].geo_distance.ranges=[]),null==b&&null==c?e[a].geo_distance.ranges:(null!=b&&(f.from=b),null!=c&&(f.to=c),null!=d&&(f.key=d),e[a].geo_distance.ranges.push(f),this)},keyed:function(b){return null==b?e[a].geo_distance.keyed:(e[a].geo_distance.keyed=b,this)}})},z.GeoHashGridAggregation=function(a){var b=z.AggregationMixin(a),d=b.toJSON();return d[a].geohash_grid={},c(b,{field:function(b){return null==b?d[a].geohash_grid.field:(d[a].geohash_grid.field=b,this)},precision:function(b){return null==b?d[a].geohash_grid.precision:(d[a].geohash_grid.precision=b,this)},size:function(b){return null==b?d[a].geohash_grid.size:(d[a].geohash_grid.size=b,this)},shardSize:function(b){return null==b?d[a].geohash_grid.shard_size:(d[a].geohash_grid.shard_size=b,this)}})},z.GlobalAggregation=function(a){var b=z.AggregationMixin(a),c=b.toJSON();return c[a].global={},b},z.HistogramAggregation=function(a){var b=z.AggregationMixin(a),d=b.toJSON();return d[a].histogram={},c(b,{field:function(b){return null==b?d[a].histogram.field:(d[a].histogram.field=b,this)},script:function(b){return null==b?d[a].histogram.script:(d[a].histogram.script=b,this)},lang:function(b){return null==b?d[a].histogram.lang:(d[a].histogram.lang=b,this)},format:function(b){return null==b?d[a].histogram.format:(d[a].histogram.format=b,this)},extendedBounds:function(b,c){var e;return null==b&&null==c?d[a].histogram.extended_bounds:(e={},null!=b&&(e.min=b),null!=c&&(e.max=c),d[a].histogram.extended_bounds=e,this)},interval:function(b){return null==b?d[a].histogram.interval:(d[a].histogram.interval=b,this)},minDocCount:function(b){return null==b?d[a].histogram.min_doc_count:(d[a].histogram.min_doc_count=b,this)},keyed:function(b){return null==b?d[a].histogram.keyed:(d[a].histogram.keyed=b,this)},scriptValuesSorted:function(b){return null==b?d[a].histogram.script_values_sorted:(d[a].histogram.script_values_sorted=b,this)},params:function(b){return null==b?d[a].histogram.params:(d[a].histogram.params=b,this)},order:function(b,c){return null==b?d[a].histogram.order:(null==c&&(c="desc"),c=c.toLowerCase(),"asc"!==c&&"desc"!==c&&(c="desc"),d[a].histogram.order={},d[a].histogram.order[b]=c,this)}})},z.IPv4RangeAggregation=function(a){var b=z.AggregationMixin(a),d=b.toJSON();return d[a].ip_range={},c(b,{field:function(b){return null==b?d[a].ip_range.field:(d[a].ip_range.field=b,this)},script:function(b){return null==b?d[a].ip_range.script:(d[a].ip_range.script=b,this)},lang:function(b){return null==b?d[a].ip_range.lang:(d[a].ip_range.lang=b,this)},range:function(b,c,e,f){var g={};return null==d[a].ip_range.ranges&&(d[a].ip_range.ranges=[]),null==b&&null==c&&null==e?d[a].ip_range.ranges:(null!=b&&(g.from=b),null!=c&&(g.to=c),null!=e&&(g.mask=e),null!=f&&(g.key=f),d[a].ip_range.ranges.push(g),this)},keyed:function(b){return null==b?d[a].ip_range.keyed:(d[a].ip_range.keyed=b,this)},scriptValuesSorted:function(b){return null==b?d[a].ip_range.script_values_sorted:(d[a].ip_range.script_values_sorted=b,this)},params:function(b){return null==b?d[a].ip_range.params:(d[a].ip_range.params=b,this)}})},z.MaxAggregation=function(a){{var b=z.MetricsAggregationMixin(a,"max");b.toJSON()}return b},z.MinAggregation=function(a){{var b=z.MetricsAggregationMixin(a,"min");b.toJSON()}return b},z.MissingAggregation=function(a){var b=z.AggregationMixin(a),d=b.toJSON();return d[a].missing={},c(b,{field:function(b){return null==b?d[a].missing.field:(d[a].missing.field=b,this)}})},z.NestedAggregation=function(a){var b=z.AggregationMixin(a),d=b.toJSON();return d[a].nested={},c(b,{path:function(b){return null==b?d[a].nested.path:(d[a].nested.path=b,this)}})},z.PercentilesAggregation=function(a){var b=z.MetricsAggregationMixin(a,"percentiles"),d=b.toJSON();return c(b,{keyed:function(b){return null==b?d[a].percentiles.keyed:(d[a].percentiles.keyed=b,this)},percents:function(b){if(null==b)return d[a].percentiles.percents;if(!e(b))throw new TypeError("Percents must be an array of doubles");return d[a].percentiles.percents=b,this},percent:function(b){return null==d[a].percentiles.percents&&(d[a].percentiles.percents=[]),null==b?d[a].percentiles.percents:(d[a].percentiles.percents.push(b),this)},compression:function(b){return null==b?d[a].percentiles.compression:(d[a].percentiles.compression=b,this)}})},z.RangeAggregation=function(a){var b=z.AggregationMixin(a),d=b.toJSON();return d[a].range={},c(b,{field:function(b){return null==b?d[a].range.field:(d[a].range.field=b,this)},script:function(b){return null==b?d[a].range.script:(d[a].range.script=b,this)},lang:function(b){return null==b?d[a].range.lang:(d[a].range.lang=b,this)},range:function(b,c,e){var f={};return null==d[a].range.ranges&&(d[a].range.ranges=[]),null==b&&null==c?d[a].range.ranges:(null!=b&&(f.from=b),null!=c&&(f.to=c),null!=e&&(f.key=e),d[a].range.ranges.push(f),this)},keyed:function(b){return null==b?d[a].range.keyed:(d[a].range.keyed=b,this)},scriptValuesSorted:function(b){return null==b?d[a].range.script_values_sorted:(d[a].range.script_values_sorted=b,this)},params:function(b){return null==b?d[a].range.params:(d[a].range.params=b,this)}})},z.SignificantTermsAggregation=function(a){var b=z.AggregationMixin(a),d=b.toJSON();return d[a].significant_terms={},c(b,{field:function(b){return null==b?d[a].significant_terms.field:(d[a].significant_terms.field=b,this)},format:function(b){return null==b?d[a].significant_terms.format:(d[a].significant_terms.format=b,this)},include:function(b,c){return null==d[a].significant_terms.include&&(d[a].significant_terms.include={}),null==b?d[a].significant_terms.include:(d[a].significant_terms.include.pattern=b,null!=c&&(d[a].significant_terms.include.flags=c),this)},exclude:function(b,c){return null==d[a].significant_terms.exclude&&(d[a].significant_terms.exclude={}),null==b?d[a].significant_terms.exclude:(d[a].significant_terms.exclude.pattern=b,null!=c&&(d[a].significant_terms.exclude.flags=c),this)},executionHint:function(b){return null==b?d[a].significant_terms.execution_hint:(b=b.toLowerCase(),("map"===b||"ordinals"===b)&&(d[a].significant_terms.execution_hint=b),this)},size:function(b){return null==b?d[a].significant_terms.size:(d[a].significant_terms.size=b,this)},shardSize:function(b){return null==b?d[a].significant_terms.shard_size:(d[a].significant_terms.shard_size=b,this)},minDocCount:function(b){return null==b?d[a].significant_terms.min_doc_count:(d[a].significant_terms.min_doc_count=b,this)}})},z.StatsAggregation=function(a){{var b=z.MetricsAggregationMixin(a,"stats");b.toJSON()}return b},z.SumAggregation=function(a){{var b=z.MetricsAggregationMixin(a,"sum");b.toJSON()}return b},z.TermsAggregation=function(a){var b=z.AggregationMixin(a),d=b.toJSON();return d[a].terms={},c(b,{field:function(b){return null==b?d[a].terms.field:(d[a].terms.field=b,this)},script:function(b){return null==b?d[a].terms.script:(d[a].terms.script=b,this)},lang:function(b){return null==b?d[a].terms.lang:(d[a].terms.lang=b,this)},valueType:function(b){return null==b?d[a].terms.value_type:(b=b.toLowerCase(),("string"===b||"double"===b||"float"===b||"long"===b||"integer"===b||"short"===b||"byte"===b)&&(d[a].terms.value_type=b),this)},format:function(b){return null==b?d[a].terms.format:(d[a].terms.format=b,this)},include:function(b,c){return null==d[a].terms.include&&(d[a].terms.include={}),null==b?d[a].terms.include:(d[a].terms.include.pattern=b,null!=c&&(d[a].terms.include.flags=c),this)},exclude:function(b,c){return null==d[a].terms.exclude&&(d[a].terms.exclude={}),null==b?d[a].terms.exclude:(d[a].terms.exclude.pattern=b,null!=c&&(d[a].terms.exclude.flags=c),this)},executionHint:function(b){return null==b?d[a].terms.execution_hint:(b=b.toLowerCase(),("map"===b||"ordinals"===b)&&(d[a].terms.execution_hint=b),this)},scriptValuesUnique:function(b){return null==b?d[a].terms.script_values_unique:(d[a].terms.script_values_unique=b,this)},size:function(b){return null==b?d[a].terms.size:(d[a].terms.size=b,this)},shardSize:function(b){return null==b?d[a].terms.shard_size:(d[a].terms.shard_size=b,this)},minDocCount:function(b){return null==b?d[a].terms.min_doc_count:(d[a].terms.min_doc_count=b,this)},params:function(b){return null==b?d[a].terms.params:(d[a].terms.params=b,this)},order:function(b,c){return null==b?d[a].terms.order:(null==c&&(c="desc"),c=c.toLowerCase(),"asc"!==c&&"desc"!==c&&(c="desc"),d[a].terms.order={},d[a].terms.order[b]=c,this)}})},z.TopHitsAggregation=function(a){var b=z.MetricsAggregationMixin(a,"top_hits"),d=b.toJSON();return c(b,{from:function(b){return null===b?d[a].top_hits.from:(d[a].top_hits.from=b,this)},size:function(b){return null===b?d[a].top_hits.size:(d[a].top_hits.size=b,this)},sort:function(b){return null===b?d[a].top_hits.sort:(d[a].top_hits.sort=b,this)},trackScores:function(b){return null===b?d[a].top_hits.track_scores:(d[a].top_hits.track_scores=b,this)},version:function(b){return null===b?d[a].top_hits.version:(d[a].top_hits.version=b,this)},explain:function(b){return null===b?d[a].top_hits.explain:(d[a].top_hits.explain=b,this)},highlight:function(b){if(null===b)return d[a].top_hits.highlight;if(!v(b))throw new TypeError("Argument must be a Highlight object");return d[a].top_hits.highlight=b.toJSON(),this},scriptField:function(b){if(null===b)return d[a].top_hits.script_fields;if(void 0===d[a].top_hits.script_fields&&(d[a].top_hits.script_fields={}),!q(b))throw new TypeError("Argument must be a ScriptField");return c(d[a].top_hits.script_fields,b.toJSON()),this},fieldDataFields:function(b){return null===b?d[a].top_hits.fielddata_fields:(d[a].top_hits.fielddata_fields=b,this)},source:function(b,c){if(void 0===b&&void 0===c)return d[a].top_hits._source;if(!e(b)&&!g(b)&&!i(b))throw new TypeError("Argument includes must be a string, an array, or a boolean");if(void 0!==c&&!e(c)&&!g(c))throw new TypeError("Argument excludes must be a string or an array");return i(b)?d[a].top_hits._source=b:(d[a].top_hits._source={includes:b},void 0!==c&&(d[a].top_hits._source=c)),this}})},z.ValueCountAggregation=function(a){var b=z.MetricsAggregationMixin(a,"value_count"),d=b.toJSON();return delete b.scriptValuesSorted,c(b,{scriptValuesUnique:function(b){return null==b?d[a].value_count.script_values_unique:(d[a].value_count.script_values_unique=b,this)}})},z.AndFilter=function(a){var b,d,f=z.FilterMixin("and"),g=f.toJSON();if(g.and.filters=[],n(a))g.and.filters.push(a.toJSON());else{if(!e(a))throw new TypeError("Argument must be a Filter or Array of Filters");for(b=0,d=a.length;d>b;b++){if(!n(a[b]))throw new TypeError("Array must contain only Filter objects");g.and.filters.push(a[b].toJSON())}}return c(f,{filters:function(a){var b,c;if(null==a)return g.and.filters;if(n(a))g.and.filters.push(a.toJSON());else{if(!e(a))throw new TypeError("Argument must be a Filter or an Array of Filters");for(g.and.filters=[],b=0,c=a.length;c>b;b++){if(!n(a[b]))throw new TypeError("Array must contain only Filter objects");g.and.filters.push(a[b].toJSON())}}return this}})},z.BoolFilter=function(){var a=z.FilterMixin("bool"),b=a.toJSON();return c(a,{must:function(a){var c,d;if(null==b.bool.must&&(b.bool.must=[]),null==a)return b.bool.must;if(n(a))b.bool.must.push(a.toJSON());else{if(!e(a))throw new TypeError("Argument must be a Filter or array of Filters");for(b.bool.must=[],c=0,d=a.length;d>c;c++){if(!n(a[c]))throw new TypeError("Argument must be an array of Filters");b.bool.must.push(a[c].toJSON())}}return this},mustNot:function(a){var c,d;if(null==b.bool.must_not&&(b.bool.must_not=[]),null==a)return b.bool.must_not;if(n(a))b.bool.must_not.push(a.toJSON());else{if(!e(a))throw new TypeError("Argument must be a Filter or array of Filters");for(b.bool.must_not=[],c=0,d=a.length;d>c;c++){if(!n(a[c]))throw new TypeError("Argument must be an array of Filters");b.bool.must_not.push(a[c].toJSON()) -}}return this},should:function(a){var c,d;if(null==b.bool.should&&(b.bool.should=[]),null==a)return b.bool.should;if(n(a))b.bool.should.push(a.toJSON());else{if(!e(a))throw new TypeError("Argument must be a Filter or array of Filters");for(b.bool.should=[],c=0,d=a.length;d>c;c++){if(!n(a[c]))throw new TypeError("Argument must be an array of Filters");b.bool.should.push(a[c].toJSON())}}return this}})},z.ExistsFilter=function(a){var b=z.FilterMixin("exists"),d=b.toJSON();return d.exists.field=a,c(b,{field:function(a){return null==a?d.exists.field:(d.exists.field=a,this)}})},z.GeoBboxFilter=function(a){var b=z.FilterMixin("geo_bounding_box"),d=b.toJSON();return d.geo_bounding_box[a]={},c(b,{field:function(b){var c=d.geo_bounding_box[a];return null==b?a:(delete d.geo_bounding_box[a],a=b,d.geo_bounding_box[b]=c,this)},topLeft:function(b){if(null==b)return d.geo_bounding_box[a].top_left;if(!r(b))throw new TypeError("Argument must be a GeoPoint");return d.geo_bounding_box[a].top_left=b.toJSON(),this},bottomRight:function(b){if(null==b)return d.geo_bounding_box[a].bottom_right;if(!r(b))throw new TypeError("Argument must be a GeoPoint");return d.geo_bounding_box[a].bottom_right=b.toJSON(),this},type:function(a){return null==a?d.geo_bounding_box.type:(a=a.toLowerCase(),("memory"===a||"indexed"===a)&&(d.geo_bounding_box.type=a),this)},normalize:function(a){return null==a?d.geo_bounding_box.normalize:(d.geo_bounding_box.normalize=a,this)}})},z.GeoDistanceFilter=function(a){var b=z.FilterMixin("geo_distance"),d=b.toJSON();return d.geo_distance[a]=[0,0],c(b,{field:function(b){var c=d.geo_distance[a];return null==b?a:(delete d.geo_distance[a],a=b,d.geo_distance[b]=c,this)},distance:function(a){if(null==a)return d.geo_distance.distance;if(!h(a))throw new TypeError("Argument must be a numeric value");return d.geo_distance.distance=a,this},unit:function(a){return null==a?d.geo_distance.unit:(a=a.toLowerCase(),("mi"===a||"km"===a)&&(d.geo_distance.unit=a),this)},point:function(b){if(null==b)return d.geo_distance[a];if(!r(b))throw new TypeError("Argument must be a GeoPoint");return d.geo_distance[a]=b.toJSON(),this},distanceType:function(a){return null==a?d.geo_distance.distance_type:(a=a.toLowerCase(),("arc"===a||"plane"===a)&&(d.geo_distance.distance_type=a),this)},normalize:function(a){return null==a?d.geo_distance.normalize:(d.geo_distance.normalize=a,this)},optimizeBbox:function(a){return null==a?d.geo_distance.optimize_bbox:(a=a.toLowerCase(),("memory"===a||"indexed"===a||"none"===a)&&(d.geo_distance.optimize_bbox=a),this)}})},z.GeoDistanceRangeFilter=function(a){var b=z.FilterMixin("geo_distance_range"),d=b.toJSON();return d.geo_distance_range[a]=[0,0],c(b,{field:function(b){var c=d.geo_distance_range[a];return null==b?a:(delete d.geo_distance_range[a],a=b,d.geo_distance_range[b]=c,this)},from:function(a){if(null==a)return d.geo_distance_range.from;if(!h(a))throw new TypeError("Argument must be a numeric value");return d.geo_distance_range.from=a,this},to:function(a){if(null==a)return d.geo_distance_range.to;if(!h(a))throw new TypeError("Argument must be a numeric value");return d.geo_distance_range.to=a,this},includeLower:function(a){return null==a?d.geo_distance_range.include_lower:(d.geo_distance_range.include_lower=a,this)},includeUpper:function(a){return null==a?d.geo_distance_range.include_upper:(d.geo_distance_range.include_upper=a,this)},gt:function(a){if(null==a)return d.geo_distance_range.gt;if(!h(a))throw new TypeError("Argument must be a numeric value");return d.geo_distance_range.gt=a,this},gte:function(a){if(null==a)return d.geo_distance_range.gte;if(!h(a))throw new TypeError("Argument must be a numeric value");return d.geo_distance_range.gte=a,this},lt:function(a){if(null==a)return d.geo_distance_range.lt;if(!h(a))throw new TypeError("Argument must be a numeric value");return d.geo_distance_range.lt=a,this},lte:function(a){if(null==a)return d.geo_distance_range.lte;if(!h(a))throw new TypeError("Argument must be a numeric value");return d.geo_distance_range.lte=a,this},unit:function(a){return null==a?d.geo_distance_range.unit:(a=a.toLowerCase(),("mi"===a||"km"===a)&&(d.geo_distance_range.unit=a),this)},point:function(b){if(null==b)return d.geo_distance_range[a];if(!r(b))throw new TypeError("Argument must be a GeoPoint");return d.geo_distance_range[a]=b.toJSON(),this},distanceType:function(a){return null==a?d.geo_distance_range.distance_type:(a=a.toLowerCase(),("arc"===a||"plane"===a)&&(d.geo_distance_range.distance_type=a),this)},normalize:function(a){return null==a?d.geo_distance_range.normalize:(d.geo_distance_range.normalize=a,this)},optimizeBbox:function(a){return null==a?d.geo_distance_range.optimize_bbox:(a=a.toLowerCase(),("memory"===a||"indexed"===a||"none"===a)&&(d.geo_distance_range.optimize_bbox=a),this)}})},z.GeoPolygonFilter=function(a){var b=z.FilterMixin("geo_polygon"),d=b.toJSON();return d.geo_polygon[a]={points:[]},c(b,{field:function(b){var c=d.geo_polygon[a];return null==b?a:(delete d.geo_polygon[a],a=b,d.geo_polygon[b]=c,this)},points:function(b){var c,f;if(null==b)return d.geo_polygon[a].points;if(r(b))d.geo_polygon[a].points.push(b.toJSON());else{if(!e(b))throw new TypeError("Argument must be a GeoPoint or Array of GeoPoints");for(d.geo_polygon[a].points=[],c=0,f=b.length;f>c;c++){if(!r(b[c]))throw new TypeError("Argument must be Array of GeoPoints");d.geo_polygon[a].points.push(b[c].toJSON())}}return this},normalize:function(a){return null==a?d.geo_polygon.normalize:(d.geo_polygon.normalize=a,this)}})},z.GeoShapeFilter=function(a){var b=z.FilterMixin("geo_shape"),d=b.toJSON();return d.geo_shape[a]={},c(b,{field:function(b){var c=d.geo_shape[a];return null==b?a:(delete d.geo_shape[a],a=b,d.geo_shape[b]=c,this)},shape:function(b){return null==b?d.geo_shape[a].shape:(null!=d.geo_shape[a].indexed_shape&&delete d.geo_shape[a].indexed_shape,d.geo_shape[a].shape=b.toJSON(),this)},indexedShape:function(b){return null==b?d.geo_shape[a].indexed_shape:(null!=d.geo_shape[a].shape&&delete d.geo_shape[a].shape,d.geo_shape[a].indexed_shape=b.toJSON(),this)},relation:function(b){return null==b?d.geo_shape[a].relation:(b=b.toLowerCase(),("intersects"===b||"disjoint"===b||"within"===b)&&(d.geo_shape[a].relation=b),this)},strategy:function(b){return null==b?d.geo_shape[a].strategy:(b=b.toLowerCase(),("recursive"===b||"term"===b)&&(d.geo_shape[a].strategy=b),this)}})},z.HasChildFilter=function(a,b){var d=z.FilterMixin("has_child"),e=d.toJSON();if(l(a))e.has_child.query=a.toJSON();else if(n(a))e.has_child.filter=a.toJSON();else if(null!=a)throw new TypeError("Argument must be query or filter");return e.has_child.type=b,c(d,{query:function(a){if(null==a)return e.has_child.query;if(!l(a))throw new TypeError("Argument must be a Query object");return e.has_child.query=a.toJSON(),this},filter:function(a){if(null==a)return e.has_child.filter;if(!n(a))throw new TypeError("Argument must be a Filter object");return e.has_child.filter=a.toJSON(),this},type:function(a){return null==a?e.has_child.type:(e.has_child.type=a,this)},shortCircuitCutoff:function(a){return null==a?e.has_child.short_circuit_cutoff:(e.has_child.short_circuit_cutoff=a,this)},scope:function(){return this}})},z.HasParentFilter=function(a,b){var d=z.FilterMixin("has_parent"),e=d.toJSON();if(l(a))e.has_parent.query=a.toJSON();else if(n(a))e.has_parent.filter=a.toJSON();else if(null!=a)throw new TypeError("Argument must be query or filter");return e.has_parent.parent_type=b,c(d,{query:function(a){if(null==a)return e.has_parent.query;if(!l(a))throw new TypeError("Argument must be a Query object");return e.has_parent.query=a.toJSON(),this},filter:function(a){if(null==a)return e.has_parent.filter;if(!n(a))throw new TypeError("Argument must be a Filter object");return e.has_parent.filter=a.toJSON(),this},parentType:function(a){return null==a?e.has_parent.parent_type:(e.has_parent.parent_type=a,this)},scope:function(){return this}})},z.IdsFilter=function(a){var b=z.FilterMixin("ids"),d=b.toJSON();if(g(a))d.ids.values=[a];else{if(!e(a))throw new TypeError("Argument must be a string or an array");d.ids.values=a}return c(b,{values:function(a){if(null==a)return d.ids.values;if(g(a))d.ids.values.push(a);else{if(!e(a))throw new TypeError("Argument must be a string or an array");d.ids.values=a}return this},type:function(a){if(null==d.ids.type&&(d.ids.type=[]),null==a)return d.ids.type;if(g(a))d.ids.type.push(a);else{if(!e(a))throw new TypeError("Argument must be a string or an array");d.ids.type=a}return this}})},z.IndicesFilter=function(a,b){if(!n(a))throw new TypeError("Argument must be a Filter");var d=z.FilterMixin("indices"),f=d.toJSON();if(f.indices.filter=a.toJSON(),g(b))f.indices.indices=[b];else{if(!e(b))throw new TypeError("Argument must be a string or array");f.indices.indices=b}return c(d,{indices:function(a){if(null==a)return f.indices.indices;if(g(a))f.indices.indices.push(a);else{if(!e(a))throw new TypeError("Argument must be a string or array");f.indices.indices=a}return this},filter:function(a){if(null==a)return f.indices.filter;if(!n(a))throw new TypeError("Argument must be a Filter");return f.indices.filter=a.toJSON(),this},noMatchFilter:function(a){if(null==a)return f.indices.no_match_filter;if(g(a))a=a.toLowerCase(),("none"===a||"all"===a)&&(f.indices.no_match_filter=a);else{if(!n(a))throw new TypeError("Argument must be string or Filter");f.indices.no_match_filter=a.toJSON()}return this}})},z.LimitFilter=function(a){var b=z.FilterMixin("limit"),d=b.toJSON();return d.limit.value=a,c(b,{value:function(a){if(null==a)return d.limit.value;if(!h(a))throw new TypeError("Argument must be a numeric value");return d.limit.value=a,this}})},z.MatchAllFilter=function(){return z.FilterMixin("match_all")},z.MissingFilter=function(a){var b=z.FilterMixin("missing"),d=b.toJSON();return d.missing.field=a,c(b,{field:function(a){return null==a?d.missing.field:(d.missing.field=a,this)},existence:function(a){return null==a?d.missing.existence:(d.missing.existence=a,this)},nullValue:function(a){return null==a?d.missing.null_value:(d.missing.null_value=a,this)}})},z.NestedFilter=function(a){var b=z.FilterMixin("nested"),d=b.toJSON();return d.nested.path=a,c(b,{path:function(a){return null==a?d.nested.path:(d.nested.path=a,this)},query:function(a){if(null==a)return d.nested.query;if(!l(a))throw new TypeError("Argument must be a Query object");return d.nested.query=a.toJSON(),this},filter:function(a){if(null==a)return d.nested.filter;if(!n(a))throw new TypeError("Argument must be a Filter object");return d.nested.filter=a.toJSON(),this},boost:function(a){return null==a?d.nested.boost:(d.nested.boost=a,this)},join:function(a){return null==a?d.nested.join:(d.nested.join=a,this)},scope:function(){return this}})},z.NotFilter=function(a){if(!n(a))throw new TypeError("Argument must be a Filter");var b=z.FilterMixin("not"),d=b.toJSON();return d.not=a.toJSON(),c(b,{filter:function(a){if(null==a)return d.not;if(!n(a))throw new TypeError("Argument must be a Filter");return d.not=a.toJSON(),this}})},z.NumericRangeFilter=function(a){var b=z.FilterMixin("numeric_range"),d=b.toJSON();return d.numeric_range[a]={},c(b,{field:function(b){var c=d.numeric_range[a];return null==b?a:(delete d.numeric_range[a],a=b,d.numeric_range[a]=c,this)},from:function(b){if(null==b)return d.numeric_range[a].from;if(!h(b))throw new TypeError("Argument must be a numeric value");return d.numeric_range[a].from=b,this},to:function(b){if(null==b)return d.numeric_range[a].to;if(!h(b))throw new TypeError("Argument must be a numeric value");return d.numeric_range[a].to=b,this},includeLower:function(b){return null==b?d.numeric_range[a].include_lower:(d.numeric_range[a].include_lower=b,this)},includeUpper:function(b){return null==b?d.numeric_range[a].include_upper:(d.numeric_range[a].include_upper=b,this)},gt:function(b){if(null==b)return d.numeric_range[a].gt;if(!h(b))throw new TypeError("Argument must be a numeric value");return d.numeric_range[a].gt=b,this},gte:function(b){if(null==b)return d.numeric_range[a].gte;if(!h(b))throw new TypeError("Argument must be a numeric value");return d.numeric_range[a].gte=b,this},lt:function(b){if(null==b)return d.numeric_range[a].lt;if(!h(b))throw new TypeError("Argument must be a numeric value");return d.numeric_range[a].lt=b,this},lte:function(b){if(null==b)return d.numeric_range[a].lte;if(!h(b))throw new TypeError("Argument must be a numeric value");return d.numeric_range[a].lte=b,this}})},z.OrFilter=function(a){var b,d,f=z.FilterMixin("or"),g=f.toJSON();if(g.or.filters=[],n(a))g.or.filters.push(a.toJSON());else{if(!e(a))throw new TypeError("Argument must be a Filter or array of Filters");for(b=0,d=a.length;d>b;b++){if(!n(a[b]))throw new TypeError("Argument must be array of Filters");g.or.filters.push(a[b].toJSON())}}return c(f,{filters:function(a){var b,c;if(null==a)return g.or.filters;if(n(a))g.or.filters.push(a.toJSON());else{if(!e(a))throw new TypeError("Argument must be a Filter or array of Filters");for(g.or.filters=[],b=0,c=a.length;c>b;b++){if(!n(a[b]))throw new TypeError("Argument must be an array of Filters");g.or.filters.push(a[b].toJSON())}}return this}})},z.PrefixFilter=function(a,b){var d=z.FilterMixin("prefix"),e=d.toJSON();return e.prefix[a]=b,c(d,{field:function(b){var c=e.prefix[a];return null==b?a:(delete e.prefix[a],a=b,e.prefix[a]=c,this)},prefix:function(b){return null==b?e.prefix[a]:(e.prefix[a]=b,this)}})},z.QueryFilter=function(a){if(!l(a))throw new TypeError("Argument must be a Query");var b=z.FilterMixin("fquery"),d=b.toJSON();return d.fquery.query=a.toJSON(),c(b,{query:function(a){if(null==a)return d.fquery.query;if(!l(a))throw new TypeError("Argument must be a Query");return d.fquery.query=a.toJSON(),this}})},z.RangeFilter=function(a){var b=z.FilterMixin("range"),d=b.toJSON();return d.range[a]={},c(b,{field:function(b){var c=d.range[a];return null==b?a:(delete d.range[a],a=b,d.range[b]=c,this)},from:function(b){return null==b?d.range[a].from:(d.range[a].from=b,this)},to:function(b){return null==b?d.range[a].to:(d.range[a].to=b,this)},includeLower:function(b){return null==b?d.range[a].include_lower:(d.range[a].include_lower=b,this)},includeUpper:function(b){return null==b?d.range[a].include_upper:(d.range[a].include_upper=b,this)},gt:function(b){return null==b?d.range[a].gt:(d.range[a].gt=b,this)},gte:function(b){return null==b?d.range[a].gte:(d.range[a].gte=b,this)},lt:function(b){return null==b?d.range[a].lt:(d.range[a].lt=b,this)},lte:function(b){return null==b?d.range[a].lte:(d.range[a].lte=b,this)}})},z.RegexpFilter=function(a,b){var d=z.FilterMixin("regexp"),e=d.toJSON();return e.regexp[a]={value:b},c(d,{field:function(b){var c=e.regexp[a];return null==b?a:(delete e.regexp[a],a=b,e.regexp[b]=c,this)},value:function(b){return null==b?e.regexp[a].value:(e.regexp[a].value=b,this)},flags:function(b){return null==b?e.regexp[a].flags:(e.regexp[a].flags=b,this)},flagsValue:function(b){return null==b?e.regexp[a].flags_value:(e.regexp[a].flags_value=b,this)}})},z.ScriptFilter=function(a){var b=z.FilterMixin("script"),d=b.toJSON();return d.script.script=a,c(b,{script:function(a){return null==a?d.script.script:(d.script.script=a,this)},params:function(a){return null==a?d.script.params:(d.script.params=a,this)},lang:function(a){return null==a?d.script.lang:(d.script.lang=a,this)}})},z.TermFilter=function(a,b){var d=z.FilterMixin("term"),e=d.toJSON();return e.term[a]=b,c(d,{field:function(b){var c=e.term[a];return null==b?a:(delete e.term[a],a=b,e.term[a]=c,this)},term:function(b){return null==b?e.term[a]:(e.term[a]=b,this)}})},z.TermsFilter=function(a,b){var d=z.FilterMixin("terms"),f=d.toJSON(),g=function(){e(f.terms[a])||(f.terms[a]=[])},h=function(){e(f.terms[a])&&(f.terms[a]={})};return f.terms[a]=e(b)?b:[b],c(d,{field:function(b){var c=f.terms[a];return null==b?a:(delete f.terms[a],a=b,f.terms[b]=c,this)},terms:function(b){return g(),null==b?f.terms[a]:(e(b)?f.terms[a]=b:f.terms[a].push(b),this)},index:function(b){return h(),null==b?f.terms[a].index:(f.terms[a].index=b,this)},type:function(b){return h(),null==b?f.terms[a].type:(f.terms[a].type=b,this)},id:function(b){return h(),null==b?f.terms[a].id:(f.terms[a].id=b,this)},path:function(b){return h(),null==b?f.terms[a].path:(f.terms[a].path=b,this)},routing:function(b){return h(),null==b?f.terms[a].routing:(f.terms[a].routing=b,this)},cacheLookup:function(b){return h(),null==b?f.terms[a].cache:(f.terms[a].cache=b,this)},execution:function(a){return null==a?f.terms.execution:(a=a.toLowerCase(),("plain"===a||"bool"===a||"bool_nocache"===a||"and"===a||"and_nocache"===a||"or"===a||"or_nocache"===a)&&(f.terms.execution=a),this)}})},z.TypeFilter=function(a){var b=z.FilterMixin("type"),d=b.toJSON();return d.type.value=a,c(b,{type:function(a){return null==a?d.type.value:(d.type.value=a,this)}})},z.BoolQuery=function(){var a=z.QueryMixin("bool"),b=a.toJSON();return c(a,{must:function(a){var c,d;if(null==b.bool.must&&(b.bool.must=[]),null==a)return b.bool.must;if(l(a))b.bool.must.push(a.toJSON());else{if(!e(a))throw new TypeError("Argument must be a Query or array of Queries");for(b.bool.must=[],c=0,d=a.length;d>c;c++){if(!l(a[c]))throw new TypeError("Argument must be an array of Queries");b.bool.must.push(a[c].toJSON())}}return this},mustNot:function(a){var c,d;if(null==b.bool.must_not&&(b.bool.must_not=[]),null==a)return b.bool.must_not;if(l(a))b.bool.must_not.push(a.toJSON());else{if(!e(a))throw new TypeError("Argument must be a Query or array of Queries");for(b.bool.must_not=[],c=0,d=a.length;d>c;c++){if(!l(a[c]))throw new TypeError("Argument must be an array of Queries");b.bool.must_not.push(a[c].toJSON())}}return this},should:function(a){var c,d;if(null==b.bool.should&&(b.bool.should=[]),null==a)return b.bool.should;if(l(a))b.bool.should.push(a.toJSON());else{if(!e(a))throw new TypeError("Argument must be a Query or array of Queries");for(b.bool.should=[],c=0,d=a.length;d>c;c++){if(!l(a[c]))throw new TypeError("Argument must be an array of Queries");b.bool.should.push(a[c].toJSON())}}return this},adjustPureNegative:function(a){return null==a?b.bool.adjust_pure_negative:(b.bool.adjust_pure_negative=a,this)},disableCoord:function(a){return null==a?b.bool.disable_coord:(b.bool.disable_coord=a,this)},minimumNumberShouldMatch:function(a){return null==a?b.bool.minimum_number_should_match:(b.bool.minimum_number_should_match=a,this)}})},z.BoostingQuery=function(a,b,d){if(!l(a)||!l(b))throw new TypeError("Arguments must be Queries");var e=z.QueryMixin("boosting"),f=e.toJSON();return f.boosting.positive=a.toJSON(),f.boosting.negative=b.toJSON(),f.boosting.negative_boost=d,c(e,{positive:function(a){if(null==a)return f.boosting.positive;if(!l(a))throw new TypeError("Argument must be a Query");return f.boosting.positive=a.toJSON(),this},negative:function(a){if(null==a)return f.boosting.negative;if(!l(a))throw new TypeError("Argument must be a Query");return f.boosting.negative=a.toJSON(),this},negativeBoost:function(a){return null==a?f.boosting.negative_boost:(f.boosting.negative_boost=a,this)}})},z.CommonTermsQuery=function(a,b){var d=z.QueryMixin("common"),e=d.toJSON();return null==a&&(a="no_field_set"),e.common[a]={},null!=b&&(e.common[a].query=b),c(d,{field:function(b){var c=e.common[a];return null==b?a:(delete e.common[a],a=b,e.common[b]=c,this)},query:function(b){return null==b?e.common[a].query:(e.common[a].query=b,this)},analyzer:function(b){return null==b?e.common[a].analyzer:(e.common[a].analyzer=b,this)},disableCoord:function(b){return null==b?e.common[a].disable_coord:(e.common[a].disable_coord=b,this)},cutoffFrequency:function(b){return null==b?e.common[a].cutoff_frequency:(e.common[a].cutoff_frequency=b,this)},highFreqOperator:function(b){return null==b?e.common[a].high_freq_operator:(b=b.toLowerCase(),("and"===b||"or"===b)&&(e.common[a].high_freq_operator=b),this)},lowFreqOperator:function(b){return null==b?e.common[a].low_freq_operator:(b=b.toLowerCase(),("and"===b||"or"===b)&&(e.common[a].low_freq_operator=b),this)},minimumShouldMatch:function(b){return null==b?e.common[a].minimum_should_match.low_freq:(null==e.common[a].minimum_should_match&&(e.common[a].minimum_should_match={}),e.common[a].minimum_should_match.low_freq=b,this)},minimumShouldMatchLowFreq:function(a){return this.minimumShouldMatch(a)},minimumShouldMatchHighFreq:function(b){return null==b?e.common[a].minimum_should_match.high_freq:(null==e.common[a].minimum_should_match&&(e.common[a].minimum_should_match={}),e.common[a].minimum_should_match.high_freq=b,this)},boost:function(b){return null==b?e.common[a].boost:(e.common[a].boost=b,this)}})},z.ConstantScoreQuery=function(){var a=z.QueryMixin("constant_score"),b=a.toJSON();return c(a,{query:function(a){if(null==a)return b.constant_score.query;if(!l(a))throw new TypeError("Argument must be a Query");return b.constant_score.query=a.toJSON(),this},filter:function(a){if(null==a)return b.constant_score.filter;if(!n(a))throw new TypeError("Argument must be a Filter");return b.constant_score.filter=a.toJSON(),this},cache:function(a){return null==a?b.constant_score._cache:(b.constant_score._cache=a,this)},cacheKey:function(a){return null==a?b.constant_score._cache_key:(b.constant_score._cache_key=a,this)}})},z.DisMaxQuery=function(){var a=z.QueryMixin("dis_max"),b=a.toJSON();return c(a,{queries:function(a){var c,d;if(null==a)return b.dis_max.queries;if(null==b.dis_max.queries&&(b.dis_max.queries=[]),l(a))b.dis_max.queries.push(a.toJSON());else{if(!e(a))throw new TypeError("Argument must be a Query or array of Queries");for(b.dis_max.queries=[],c=0,d=a.length;d>c;c++){if(!l(a[c]))throw new TypeError("Argument must be array of Queries");b.dis_max.queries.push(a[c].toJSON())}}return this},tieBreaker:function(a){return null==a?b.dis_max.tie_breaker:(b.dis_max.tie_breaker=a,this)}})},z.FieldMaskingSpanQuery=function(a,b){if(!l(a))throw new TypeError("Argument must be a SpanQuery");var d=z.QueryMixin("field_masking_span"),e=d.toJSON();return e.field_masking_span.query=a.toJSON(),e.field_masking_span.field=b,c(d,{query:function(a){if(null==a)return e.field_masking_span.query;if(!l(a))throw new TypeError("Argument must be a SpanQuery");return e.field_masking_span.query=a.toJSON(),this},field:function(a){return null==a?e.field_masking_span.field:(e.field_masking_span.field=a,this)}})},z.FilteredQuery=function(a,b){if(!l(a))throw new TypeError("Argument must be a Query");if(null!=b&&!n(b))throw new TypeError("Argument must be a Filter");var d=z.QueryMixin("filtered"),e=d.toJSON();return e.filtered.query=a.toJSON(),null!=b&&(e.filtered.filter=b.toJSON()),c(d,{query:function(a){if(null==a)return e.filtered.query;if(!l(a))throw new TypeError("Argument must be a Query");return e.filtered.query=a.toJSON(),this},filter:function(a){if(null==a)return e.filtered.filter;if(!n(a))throw new TypeError("Argument must be a Filter");return e.filtered.filter=a.toJSON(),this},strategy:function(a){return null==a?e.filtered.strategy:(a=a.toLowerCase(),("query_first"===a||"random_access_always"===a||"leap_frog"===a||"leap_frog_filter_first"===a||0===a.indexOf("random_access_"))&&(e.filtered.strategy=a),this)},cache:function(a){return null==a?e.filtered._cache:(e.filtered._cache=a,this)},cacheKey:function(a){return null==a?e.filtered._cache_key:(e.filtered._cache_key=a,this)}})},z.FunctionScoreQuery=function(){var a=z.QueryMixin("function_score"),b=a.toJSON();return c(a,{query:function(a){if(null==a)return b.function_score.query;if(!l(a))throw new TypeError("Argument must be a Query");return b.function_score.query=a.toJSON(),this},filter:function(a){if(null==a)return b.function_score.filter;if(!n(a))throw new TypeError("Argument must be a Filter");return b.function_score.filter=a.toJSON(),this},scoreMode:function(a){return null==a?b.function_score.score_mode:(a=a.toLowerCase(),("avg"===a||"max"===a||"min"===a||"sum"===a||"multiply"===a||"first"===a)&&(b.function_score.score_mode=a),this)},boostMode:function(a){return null==a?b.function_score.boost_mode:(a=a.toLowerCase(),("multiply"===a||"replace"===a||"sum"===a||"avg"===a||"max"===a||"min"===a)&&(b.function_score.boost_mode=a),this)},boost:function(a){return null==a?b.function_score.boost:(b.function_score.boost=a,this)},"function":function(a){if(null==b.function_score.functions&&(b.function_score.functions=[]),null==a)return b.function_score.functions;if(!y(a))throw new TypeError("Argument must be a ScoreFunction");return b.function_score.functions.push(a.toJSON()),this},functions:function(a){var c,d;if(null==a)return b.function_score.functions;if(!e(a))throw new TypeError("Argument must be an array of ScoreFunctions");for(b.function_score.functions=[],c=0,d=a.length;d>c;c++){if(!y(a[c]))throw new TypeError("Argument must be an array of ScoreFunctions");b.function_score.functions.push(a[c].toJSON())}return this}})},z.FuzzyLikeThisFieldQuery=function(a,b){var d=z.QueryMixin("flt_field"),e=d.toJSON();return e.flt_field[a]={like_text:b},c(d,{field:function(b){var c=e.flt_field[a];return null==b?a:(delete e.flt_field[a],a=b,e.flt_field[b]=c,this)},likeText:function(b){return null==b?e.flt_field[a].like_text:(e.flt_field[a].like_text=b,this)},ignoreTf:function(b){return null==b?e.flt_field[a].ignore_tf:(e.flt_field[a].ignore_tf=b,this)},maxQueryTerms:function(b){return null==b?e.flt_field[a].max_query_terms:(e.flt_field[a].max_query_terms=b,this)},minSimilarity:function(b){return null==b?e.flt_field[a].min_similarity:(e.flt_field[a].min_similarity=b,this)},prefixLength:function(b){return null==b?e.flt_field[a].prefix_length:(e.flt_field[a].prefix_length=b,this)},analyzer:function(b){return null==b?e.flt_field[a].analyzer:(e.flt_field[a].analyzer=b,this)},failOnUnsupportedField:function(b){return null==b?e.flt_field[a].fail_on_unsupported_field:(e.flt_field[a].fail_on_unsupported_field=b,this)},boost:function(b){return null==b?e.flt_field[a].boost:(e.flt_field[a].boost=b,this)}})},z.FuzzyLikeThisQuery=function(a){var b=z.QueryMixin("flt"),d=b.toJSON();return d.flt.like_text=a,c(b,{fields:function(a){if(null==d.flt.fields&&(d.flt.fields=[]),null==a)return d.flt.fields;if(g(a))d.flt.fields.push(a);else{if(!e(a))throw new TypeError("Argument must be a string or array");d.flt.fields=a}return this},likeText:function(a){return null==a?d.flt.like_text:(d.flt.like_text=a,this)},ignoreTf:function(a){return null==a?d.flt.ignore_tf:(d.flt.ignore_tf=a,this)},maxQueryTerms:function(a){return null==a?d.flt.max_query_terms:(d.flt.max_query_terms=a,this)},minSimilarity:function(a){return null==a?d.flt.min_similarity:(d.flt.min_similarity=a,this)},prefixLength:function(a){return null==a?d.flt.prefix_length:(d.flt.prefix_length=a,this)},analyzer:function(a){return null==a?d.flt.analyzer:(d.flt.analyzer=a,this)},failOnUnsupportedField:function(a){return null==a?d.flt.fail_on_unsupported_field:(d.flt.fail_on_unsupported_field=a,this)}})},z.FuzzyQuery=function(a,b){var d=z.QueryMixin("fuzzy"),e=d.toJSON();return e.fuzzy[a]={value:b},c(d,{field:function(b){var c=e.fuzzy[a];return null==b?a:(delete e.fuzzy[a],a=b,e.fuzzy[b]=c,this)},value:function(b){return null==b?e.fuzzy[a].value:(e.fuzzy[a].value=b,this)},transpositions:function(b){return null==b?e.fuzzy[a].transpositions:(e.fuzzy[a].transpositions=b,this)},maxExpansions:function(b){return null==b?e.fuzzy[a].max_expansions:(e.fuzzy[a].max_expansions=b,this)},minSimilarity:function(b){return null==b?e.fuzzy[a].min_similarity:(e.fuzzy[a].min_similarity=b,this)},prefixLength:function(b){return null==b?e.fuzzy[a].prefix_length:(e.fuzzy[a].prefix_length=b,this)},rewrite:function(b){return null==b?e.fuzzy[a].rewrite:(b=b.toLowerCase(),("constant_score_auto"===b||"scoring_boolean"===b||"constant_score_boolean"===b||"constant_score_filter"===b||0===b.indexOf("top_terms_boost_")||0===b.indexOf("top_terms_"))&&(e.fuzzy[a].rewrite=b),this)},boost:function(b){return null==b?e.fuzzy[a].boost:(e.fuzzy[a].boost=b,this)}})},z.GeoShapeQuery=function(a){var b=z.QueryMixin("geo_shape"),d=b.toJSON();return d.geo_shape[a]={},c(b,{field:function(b){var c=d.geo_shape[a];return null==b?a:(delete d.geo_shape[a],a=b,d.geo_shape[b]=c,this)},shape:function(b){return null==b?d.geo_shape[a].shape:(null!=d.geo_shape[a].indexed_shape&&delete d.geo_shape[a].indexed_shape,d.geo_shape[a].shape=b.toJSON(),this)},indexedShape:function(b){return null==b?d.geo_shape[a].indexed_shape:(null!=d.geo_shape[a].shape&&delete d.geo_shape[a].shape,d.geo_shape[a].indexed_shape=b.toJSON(),this)},relation:function(b){return null==b?d.geo_shape[a].relation:(b=b.toLowerCase(),("intersects"===b||"disjoint"===b||"within"===b)&&(d.geo_shape[a].relation=b),this)},strategy:function(b){return null==b?d.geo_shape[a].strategy:(b=b.toLowerCase(),("recursive"===b||"term"===b)&&(d.geo_shape[a].strategy=b),this)},boost:function(b){return null==b?d.geo_shape[a].boost:(d.geo_shape[a].boost=b,this)}})},z.HasChildQuery=function(a,b){if(!l(a))throw new TypeError("Argument must be a valid Query");var d=z.QueryMixin("has_child"),e=d.toJSON();return e.has_child.query=a.toJSON(),e.has_child.type=b,c(d,{query:function(a){if(null==a)return e.has_child.query;if(!l(a))throw new TypeError("Argument must be a valid Query");return e.has_child.query=a.toJSON(),this},type:function(a){return null==a?e.has_child.type:(e.has_child.type=a,this)},scope:function(){return this},scoreType:function(a){return null==a?e.has_child.score_type:(a=a.toLowerCase(),("none"===a||"max"===a||"sum"===a||"avg"===a)&&(e.has_child.score_type=a),this)},scoreMode:function(a){return null==a?e.has_child.score_mode:(a=a.toLowerCase(),("none"===a||"max"===a||"sum"===a||"avg"===a)&&(e.has_child.score_mode=a),this)},shortCircuitCutoff:function(a){return null==a?e.has_child.short_circuit_cutoff:(e.has_child.short_circuit_cutoff=a,this)}})},z.HasParentQuery=function(a,b){if(!l(a))throw new TypeError("Argument must be a Query");var d=z.QueryMixin("has_parent"),e=d.toJSON();return e.has_parent.query=a.toJSON(),e.has_parent.parent_type=b,c(d,{query:function(a){if(null==a)return e.has_parent.query;if(!l(a))throw new TypeError("Argument must be a Query");return e.has_parent.query=a.toJSON(),this},parentType:function(a){return null==a?e.has_parent.parent_type:(e.has_parent.parent_type=a,this)},scope:function(){return this},scoreType:function(a){return null==a?e.has_parent.score_type:(a=a.toLowerCase(),("none"===a||"score"===a)&&(e.has_parent.score_type=a),this)},scoreMode:function(a){return null==a?e.has_parent.score_mode:(a=a.toLowerCase(),("none"===a||"score"===a)&&(e.has_parent.score_mode=a),this)}})},z.IdsQuery=function(a){var b=z.QueryMixin("ids"),d=b.toJSON();if(g(a))d.ids.values=[a];else{if(!e(a))throw new TypeError("Argument must be string or array");d.ids.values=a}return c(b,{values:function(a){if(null==a)return d.ids.values;if(g(a))d.ids.values.push(a);else{if(!e(a))throw new TypeError("Argument must be string or array");d.ids.values=a}return this},type:function(a){if(null==d.ids.type&&(d.ids.type=[]),null==a)return d.ids.type;if(g(a))d.ids.type.push(a);else{if(!e(a))throw new TypeError("Argument must be string or array");d.ids.type=a}return this}})},z.IndicesQuery=function(a,b){if(!l(a))throw new TypeError("Argument must be a Query");var d=z.QueryMixin("indices"),f=d.toJSON();if(f.indices.query=a.toJSON(),g(b))f.indices.indices=[b];else{if(!e(b))throw new TypeError("Argument must be a string or array");f.indices.indices=b}return c(d,{indices:function(a){if(null==a)return f.indices.indices;if(g(a))f.indices.indices.push(a);else{if(!e(a))throw new TypeError("Argument must be a string or array");f.indices.indices=a}return this},query:function(a){if(null==a)return f.indices.query;if(!l(a))throw new TypeError("Argument must be a Query");return f.indices.query=a.toJSON(),this},noMatchQuery:function(a){if(null==a)return f.indices.no_match_query;if(g(a))a=a.toLowerCase(),("none"===a||"all"===a)&&(f.indices.no_match_query=a);else{if(!l(a))throw new TypeError("Argument must be string or Query");f.indices.no_match_query=a.toJSON()}return this -}})},z.MatchAllQuery=function(){return z.QueryMixin("match_all")},z.MatchQuery=function(a,b){var d=z.QueryMixin("match"),e=d.toJSON();return e.match[a]={query:b},c(d,{query:function(b){return null==b?e.match[a].query:(e.match[a].query=b,this)},type:function(b){return null==b?e.match[a].type:(b=b.toLowerCase(),("boolean"===b||"phrase"===b||"phrase_prefix"===b)&&(e.match[a].type=b),this)},fuzziness:function(b){return null==b?e.match[a].fuzziness:(e.match[a].fuzziness=b,this)},cutoffFrequency:function(b){return null==b?e.match[a].cutoff_frequency:(e.match[a].cutoff_frequency=b,this)},prefixLength:function(b){return null==b?e.match[a].prefix_length:(e.match[a].prefix_length=b,this)},maxExpansions:function(b){return null==b?e.match[a].max_expansions:(e.match[a].max_expansions=b,this)},operator:function(b){return null==b?e.match[a].operator:(b=b.toLowerCase(),("and"===b||"or"===b)&&(e.match[a].operator=b),this)},slop:function(b){return null==b?e.match[a].slop:(e.match[a].slop=b,this)},analyzer:function(b){return null==b?e.match[a].analyzer:(e.match[a].analyzer=b,this)},minimumShouldMatch:function(b){return null==b?e.match[a].minimum_should_match:(e.match[a].minimum_should_match=b,this)},rewrite:function(b){return null==b?e.match[a].rewrite:(b=b.toLowerCase(),("constant_score_auto"===b||"scoring_boolean"===b||"constant_score_boolean"===b||"constant_score_filter"===b||0===b.indexOf("top_terms_boost_")||0===b.indexOf("top_terms_"))&&(e.match[a].rewrite=b),this)},fuzzyRewrite:function(b){return null==b?e.match[a].fuzzy_rewrite:(b=b.toLowerCase(),("constant_score_auto"===b||"scoring_boolean"===b||"constant_score_boolean"===b||"constant_score_filter"===b||0===b.indexOf("top_terms_boost_")||0===b.indexOf("top_terms_"))&&(e.match[a].fuzzy_rewrite=b),this)},fuzzyTranspositions:function(b){return null==b?e.match[a].fuzzy_transpositions:(e.match[a].fuzzy_transpositions=b,this)},lenient:function(b){return null==b?e.match[a].lenient:(e.match[a].lenient=b,this)},zeroTermsQuery:function(b){return null==b?e.match[a].zero_terms_query:(b=b.toLowerCase(),("all"===b||"none"===b)&&(e.match[a].zero_terms_query=b),this)},boost:function(b){return null==b?e.match[a].boost:(e.match[a].boost=b,this)}})},z.MoreLikeThisFieldQuery=function(a,b){var d=z.QueryMixin("mlt_field"),e=d.toJSON();return e.mlt_field[a]={like_text:b},c(d,{field:function(b){var c=e.mlt_field[a];return null==b?a:(delete e.mlt_field[a],a=b,e.mlt_field[b]=c,this)},likeText:function(b){return null==b?e.mlt_field[a].like_text:(e.mlt_field[a].like_text=b,this)},percentTermsToMatch:function(b){return null==b?e.mlt_field[a].percent_terms_to_match:(e.mlt_field[a].percent_terms_to_match=b,this)},minTermFreq:function(b){return null==b?e.mlt_field[a].min_term_freq:(e.mlt_field[a].min_term_freq=b,this)},maxQueryTerms:function(b){return null==b?e.mlt_field[a].max_query_terms:(e.mlt_field[a].max_query_terms=b,this)},stopWords:function(b){return null==b?e.mlt_field[a].stop_words:(e.mlt_field[a].stop_words=b,this)},minDocFreq:function(b){return null==b?e.mlt_field[a].min_doc_freq:(e.mlt_field[a].min_doc_freq=b,this)},maxDocFreq:function(b){return null==b?e.mlt_field[a].max_doc_freq:(e.mlt_field[a].max_doc_freq=b,this)},minWordLen:function(b){return null==b?e.mlt_field[a].min_word_len:(e.mlt_field[a].min_word_len=b,this)},maxWordLen:function(b){return null==b?e.mlt_field[a].max_word_len:(e.mlt_field[a].max_word_len=b,this)},analyzer:function(b){return null==b?e.mlt_field[a].analyzer:(e.mlt_field[a].analyzer=b,this)},boostTerms:function(b){return null==b?e.mlt_field[a].boost_terms:(e.mlt_field[a].boost_terms=b,this)},failOnUnsupportedField:function(b){return null==b?e.mlt_field[a].fail_on_unsupported_field:(e.mlt_field[a].fail_on_unsupported_field=b,this)},boost:function(b){return null==b?e.mlt_field[a].boost:(e.mlt_field[a].boost=b,this)}})},z.MoreLikeThisQuery=function(a,b){var d=z.QueryMixin("mlt"),f=d.toJSON();if(f.mlt.like_text=b,f.mlt.fields=[],g(a))f.mlt.fields.push(a);else{if(!e(a))throw new TypeError("Argument must be string or array");f.mlt.fields=a}return c(d,{fields:function(a){if(null==a)return f.mlt.fields;if(g(a))f.mlt.fields.push(a);else{if(!e(a))throw new TypeError("Argument must be a string or array");f.mlt.fields=a}return this},likeText:function(a){return null==a?f.mlt.like_text:(f.mlt.like_text=a,this)},percentTermsToMatch:function(a){return null==a?f.mlt.percent_terms_to_match:(f.mlt.percent_terms_to_match=a,this)},minTermFreq:function(a){return null==a?f.mlt.min_term_freq:(f.mlt.min_term_freq=a,this)},maxQueryTerms:function(a){return null==a?f.mlt.max_query_terms:(f.mlt.max_query_terms=a,this)},stopWords:function(a){return null==a?f.mlt.stop_words:(f.mlt.stop_words=a,this)},minDocFreq:function(a){return null==a?f.mlt.min_doc_freq:(f.mlt.min_doc_freq=a,this)},maxDocFreq:function(a){return null==a?f.mlt.max_doc_freq:(f.mlt.max_doc_freq=a,this)},minWordLen:function(a){return null==a?f.mlt.min_word_len:(f.mlt.min_word_len=a,this)},maxWordLen:function(a){return null==a?f.mlt.max_word_len:(f.mlt.max_word_len=a,this)},analyzer:function(a){return null==a?f.mlt.analyzer:(f.mlt.analyzer=a,this)},boostTerms:function(a){return null==a?f.mlt.boost_terms:(f.mlt.boost_terms=a,this)},failOnUnsupportedField:function(a){return null==a?f.mlt.fail_on_unsupported_field:(f.mlt.fail_on_unsupported_field=a,this)}})},z.MultiMatchQuery=function(a,b){var d=z.QueryMixin("multi_match"),f=d.toJSON();if(f.multi_match.query=b,f.multi_match.fields=[],g(a))f.multi_match.fields.push(a);else{if(!e(a))throw new TypeError("Argument must be string or array");f.multi_match.fields=a}return c(d,{fields:function(a){if(null==a)return f.multi_match.fields;if(g(a))f.multi_match.fields.push(a);else{if(!e(a))throw new TypeError("Argument must be string or array");f.multi_match.fields=a}return this},useDisMax:function(a){return null==a?f.multi_match.use_dis_max:(f.multi_match.use_dis_max=a,this)},tieBreaker:function(a){return null==a?f.multi_match.tie_breaker:(f.multi_match.tie_breaker=a,this)},cutoffFrequency:function(a){return null==a?f.multi_match.cutoff_frequency:(f.multi_match.cutoff_frequency=a,this)},minimumShouldMatch:function(a){return null==a?f.multi_match.minimum_should_match:(f.multi_match.minimum_should_match=a,this)},rewrite:function(a){return null==a?f.multi_match.rewrite:(a=a.toLowerCase(),("constant_score_auto"===a||"scoring_boolean"===a||"constant_score_boolean"===a||"constant_score_filter"===a||0===a.indexOf("top_terms_boost_")||0===a.indexOf("top_terms_"))&&(f.multi_match.rewrite=a),this)},fuzzyRewrite:function(a){return null==a?f.multi_match.fuzzy_rewrite:(a=a.toLowerCase(),("constant_score_auto"===a||"scoring_boolean"===a||"constant_score_boolean"===a||"constant_score_filter"===a||0===a.indexOf("top_terms_boost_")||0===a.indexOf("top_terms_"))&&(f.multi_match.fuzzy_rewrite=a),this)},lenient:function(a){return null==a?f.multi_match.lenient:(f.multi_match.lenient=a,this)},query:function(a){return null==a?f.multi_match.query:(f.multi_match.query=a,this)},type:function(a){return null==a?f.multi_match.type:(a=a.toLowerCase(),("boolean"===a||"phrase"===a||"phrase_prefix"===a)&&(f.multi_match.type=a),this)},fuzziness:function(a){return null==a?f.multi_match.fuzziness:(f.multi_match.fuzziness=a,this)},prefixLength:function(a){return null==a?f.multi_match.prefix_length:(f.multi_match.prefix_length=a,this)},maxExpansions:function(a){return null==a?f.multi_match.max_expansions:(f.multi_match.max_expansions=a,this)},operator:function(a){return null==a?f.multi_match.operator:(a=a.toLowerCase(),("and"===a||"or"===a)&&(f.multi_match.operator=a),this)},slop:function(a){return null==a?f.multi_match.slop:(f.multi_match.slop=a,this)},analyzer:function(a){return null==a?f.multi_match.analyzer:(f.multi_match.analyzer=a,this)},zeroTermsQuery:function(a){return null==a?f.multi_match.zero_terms_query:(a=a.toLowerCase(),("all"===a||"none"===a)&&(f.multi_match.zero_terms_query=a),this)}})},z.NestedQuery=function(a){var b=z.QueryMixin("nested"),d=b.toJSON();return d.nested.path=a,c(b,{path:function(a){return null==a?d.nested.path:(d.nested.path=a,this)},query:function(a){if(null==a)return d.nested.query;if(!l(a))throw new TypeError("Argument must be a Query");return d.nested.query=a.toJSON(),this},filter:function(a){if(null==a)return d.nested.filter;if(!n(a))throw new TypeError("Argument must be a Filter");return d.nested.filter=a.toJSON(),this},scoreMode:function(a){return null==a?d.nested.score_mode:(a=a.toLowerCase(),("avg"===a||"total"===a||"max"===a||"none"===a||"sum"===a)&&(d.nested.score_mode=a),this)},scope:function(){return this}})},z.PrefixQuery=function(a,b){var d=z.QueryMixin("prefix"),e=d.toJSON();return e.prefix[a]={value:b},c(d,{field:function(b){var c=e.prefix[a];return null==b?a:(delete e.prefix[a],a=b,e.prefix[b]=c,this)},value:function(b){return null==b?e.prefix[a].value:(e.prefix[a].value=b,this)},rewrite:function(b){return null==b?e.prefix[a].rewrite:(b=b.toLowerCase(),("constant_score_auto"===b||"scoring_boolean"===b||"constant_score_boolean"===b||"constant_score_filter"===b||0===b.indexOf("top_terms_boost_")||0===b.indexOf("top_terms_"))&&(e.prefix[a].rewrite=b),this)},boost:function(b){return null==b?e.prefix[a].boost:(e.prefix[a].boost=b,this)}})},z.QueryStringQuery=function(a){var b=z.QueryMixin("query_string"),d=b.toJSON();return d.query_string.query=a,c(b,{query:function(a){return null==a?d.query_string.query:(d.query_string.query=a,this)},defaultField:function(a){return null==a?d.query_string.default_field:(d.query_string.default_field=a,this)},fields:function(a){if(null==d.query_string.fields&&(d.query_string.fields=[]),null==a)return d.query_string.fields;if(g(a))d.query_string.fields.push(a);else{if(!e(a))throw new TypeError("Argument must be a string or array");d.query_string.fields=a}return this},useDisMax:function(a){return null==a?d.query_string.use_dis_max:(d.query_string.use_dis_max=a,this)},defaultOperator:function(a){return null==a?d.query_string.default_operator:(a=a.toUpperCase(),("AND"===a||"OR"===a)&&(d.query_string.default_operator=a),this)},analyzer:function(a){return null==a?d.query_string.analyzer:(d.query_string.analyzer=a,this)},quoteAnalyzer:function(a){return null==a?d.query_string.quote_analyzer:(d.query_string.quote_analyzer=a,this)},allowLeadingWildcard:function(a){return null==a?d.query_string.allow_leading_wildcard:(d.query_string.allow_leading_wildcard=a,this)},lowercaseExpandedTerms:function(a){return null==a?d.query_string.lowercase_expanded_terms:(d.query_string.lowercase_expanded_terms=a,this)},enablePositionIncrements:function(a){return null==a?d.query_string.enable_position_increments:(d.query_string.enable_position_increments=a,this)},fuzzyPrefixLength:function(a){return null==a?d.query_string.fuzzy_prefix_length:(d.query_string.fuzzy_prefix_length=a,this)},fuzzyMinSim:function(a){return null==a?d.query_string.fuzzy_min_sim:(d.query_string.fuzzy_min_sim=a,this)},phraseSlop:function(a){return null==a?d.query_string.phrase_slop:(d.query_string.phrase_slop=a,this)},analyzeWildcard:function(a){return null==a?d.query_string.analyze_wildcard:(d.query_string.analyze_wildcard=a,this)},autoGeneratePhraseQueries:function(a){return null==a?d.query_string.auto_generate_phrase_queries:(d.query_string.auto_generate_phrase_queries=a,this)},minimumShouldMatch:function(a){return null==a?d.query_string.minimum_should_match:(d.query_string.minimum_should_match=a,this)},tieBreaker:function(a){return null==a?d.query_string.tie_breaker:(d.query_string.tie_breaker=a,this)},escape:function(a){return null==a?d.query_string.escape:(d.query_string.escape=a,this)},fuzzyMaxExpansions:function(a){return null==a?d.query_string.fuzzy_max_expansions:(d.query_string.fuzzy_max_expansions=a,this)},fuzzyRewrite:function(a){return null==a?d.query_string.fuzzy_rewrite:(a=a.toLowerCase(),("constant_score_auto"===a||"scoring_boolean"===a||"constant_score_boolean"===a||"constant_score_filter"===a||0===a.indexOf("top_terms_boost_")||0===a.indexOf("top_terms_"))&&(d.query_string.fuzzy_rewrite=a),this)},rewrite:function(a){return null==a?d.query_string.rewrite:(a=a.toLowerCase(),("constant_score_auto"===a||"scoring_boolean"===a||"constant_score_boolean"===a||"constant_score_filter"===a||0===a.indexOf("top_terms_boost_")||0===a.indexOf("top_terms_"))&&(d.query_string.rewrite=a),this)},quoteFieldSuffix:function(a){return null==a?d.query_string.quote_field_suffix:(d.query_string.quote_field_suffix=a,this)},lenient:function(a){return null==a?d.query_string.lenient:(d.query_string.lenient=a,this)}})},z.RangeQuery=function(a){var b=z.QueryMixin("range"),d=b.toJSON();return d.range[a]={},c(b,{field:function(b){var c=d.range[a];return null==b?a:(delete d.range[a],a=b,d.range[b]=c,this)},from:function(b){return null==b?d.range[a].from:(d.range[a].from=b,this)},to:function(b){return null==b?d.range[a].to:(d.range[a].to=b,this)},includeLower:function(b){return null==b?d.range[a].include_lower:(d.range[a].include_lower=b,this)},includeUpper:function(b){return null==b?d.range[a].include_upper:(d.range[a].include_upper=b,this)},gt:function(b){return null==b?d.range[a].gt:(d.range[a].gt=b,this)},gte:function(b){return null==b?d.range[a].gte:(d.range[a].gte=b,this)},lt:function(b){return null==b?d.range[a].lt:(d.range[a].lt=b,this)},lte:function(b){return null==b?d.range[a].lte:(d.range[a].lte=b,this)},boost:function(b){return null==b?d.range[a].boost:(d.range[a].boost=b,this)}})},z.RegexpQuery=function(a,b){var d=z.QueryMixin("regexp"),e=d.toJSON();return e.regexp[a]={value:b},c(d,{field:function(b){var c=e.regexp[a];return null==b?a:(delete e.regexp[a],a=b,e.regexp[b]=c,this)},value:function(b){return null==b?e.regexp[a].value:(e.regexp[a].value=b,this)},flags:function(b){return null==b?e.regexp[a].flags:(e.regexp[a].flags=b,this)},flagsValue:function(b){return null==b?e.regexp[a].flags_value:(e.regexp[a].flags_value=b,this)},rewrite:function(b){return null==b?e.regexp[a].rewrite:(b=b.toLowerCase(),("constant_score_auto"===b||"scoring_boolean"===b||"constant_score_boolean"===b||"constant_score_filter"===b||0===b.indexOf("top_terms_boost_")||0===b.indexOf("top_terms_"))&&(e.regexp[a].rewrite=b),this)},boost:function(b){return null==b?e.regexp[a].boost:(e.regexp[a].boost=b,this)}})},z.SpanFirstQuery=function(a,b){if(!l(a))throw new TypeError("Argument must be a SpanQuery");var d=z.QueryMixin("span_first"),e=d.toJSON();return e.span_first.match=a.toJSON(),e.span_first.end=b,c(d,{match:function(a){if(null==a)return e.span_first.match;if(!l(a))throw new TypeError("Argument must be a SpanQuery");return e.span_first.match=a.toJSON(),this},end:function(a){return null==a?e.span_first.end:(e.span_first.end=a,this)}})},z.SpanMultiTermQuery=function(a){if(null!=a&&!l(a))throw new TypeError("Argument must be a MultiTermQuery");var b=z.QueryMixin("span_multi"),d=b.toJSON();return d.span_multi.match={},null!=a&&(d.span_multi.match=a.toJSON()),c(b,{match:function(a){if(null==a)return d.span_multi.match;if(!l(a))throw new TypeError("Argument must be a MultiTermQuery");return d.span_multi.match=a.toJSON(),this}})},z.SpanNearQuery=function(a,b){var d,f,g=z.QueryMixin("span_near"),h=g.toJSON();if(h.span_near.clauses=[],h.span_near.slop=b,l(a))h.span_near.clauses.push(a.toJSON());else{if(!e(a))throw new TypeError("Argument must be SpanQuery or array of SpanQueries");for(d=0,f=a.length;f>d;d++){if(!l(a[d]))throw new TypeError("Argument must be array of SpanQueries");h.span_near.clauses.push(a[d].toJSON())}}return c(g,{clauses:function(a){var b,c;if(null==a)return h.span_near.clauses;if(l(a))h.span_near.clauses.push(a.toJSON());else{if(!e(a))throw new TypeError("Argument must be SpanQuery or array of SpanQueries");for(h.span_near.clauses=[],b=0,c=a.length;c>b;b++){if(!l(a[b]))throw new TypeError("Argument must be array of SpanQueries");h.span_near.clauses.push(a[b].toJSON())}}return this},slop:function(a){return null==a?h.span_near.slop:(h.span_near.slop=a,this)},inOrder:function(a){return null==a?h.span_near.in_order:(h.span_near.in_order=a,this)},collectPayloads:function(a){return null==a?h.span_near.collect_payloads:(h.span_near.collect_payloads=a,this)}})},z.SpanNotQuery=function(a,b){if(!l(a)||!l(b))throw new TypeError("Argument must be a SpanQuery");var d=z.QueryMixin("span_not"),e=d.toJSON();return e.span_not.include=a.toJSON(),e.span_not.exclude=b.toJSON(),c(d,{include:function(a){if(null==a)return e.span_not.include;if(!l(a))throw new TypeError("Argument must be a SpanQuery");return e.span_not.include=a.toJSON(),this},exclude:function(a){if(null==a)return e.span_not.exclude;if(!l(a))throw new TypeError("Argument must be a SpanQuery");return e.span_not.exclude=a.toJSON(),this}})},z.SpanOrQuery=function(a){var b,d,f=z.QueryMixin("span_or"),g=f.toJSON();if(g.span_or.clauses=[],l(a))g.span_or.clauses.push(a.toJSON());else{if(!e(a))throw new TypeError("Argument must be SpanQuery or array of SpanQueries");for(b=0,d=a.length;d>b;b++){if(!l(a[b]))throw new TypeError("Argument must be array of SpanQueries");g.span_or.clauses.push(a[b].toJSON())}}return c(f,{clauses:function(a){var b,c;if(null==a)return g.span_or.clauses;if(l(a))g.span_or.clauses.push(a.toJSON());else{if(!e(a))throw new TypeError("Argument must be SpanQuery or array of SpanQueries");for(g.span_or.clauses=[],b=0,c=a.length;c>b;b++){if(!l(a[b]))throw new TypeError("Argument must be array of SpanQueries");g.span_or.clauses.push(a[b].toJSON())}}return this}})},z.SpanTermQuery=function(a,b){var d=z.QueryMixin("span_term"),e=d.toJSON();return e.span_term[a]={term:b},c(d,{field:function(b){var c=e.span_term[a];return null==b?a:(delete e.span_term[a],a=b,e.span_term[b]=c,this)},term:function(b){return null==b?e.span_term[a].term:(e.span_term[a].term=b,this)},boost:function(b){return null==b?e.span_term[a].boost:(e.span_term[a].boost=b,this)}})},z.TermQuery=function(a,b){var d=z.QueryMixin("term"),e=d.toJSON();return e.term[a]={term:b},c(d,{field:function(b){var c=e.term[a];return null==b?a:(delete e.term[a],a=b,e.term[b]=c,this)},term:function(b){return null==b?e.term[a].term:(e.term[a].term=b,this)},boost:function(b){return null==b?e.term[a].boost:(e.term[a].boost=b,this)}})},z.TermsQuery=function(a,b){var d=z.QueryMixin("terms"),f=d.toJSON();if(g(b))f.terms[a]=[b];else{if(!e(b))throw new TypeError("Argument must be string or array");f.terms[a]=b}return c(d,{field:function(b){var c=f.terms[a];return null==b?a:(delete f.terms[a],a=b,f.terms[b]=c,this)},terms:function(b){if(null==b)return f.terms[a];if(g(b))f.terms[a].push(b);else{if(!e(b))throw new TypeError("Argument must be string or array");f.terms[a]=b}return this},minimumShouldMatch:function(a){return null==a?f.terms.minimum_should_match:(f.terms.minimum_should_match=a,this)},disableCoord:function(a){return null==a?f.terms.disable_coord:(f.terms.disable_coord=a,this)}})},z.TopChildrenQuery=function(a,b){if(!l(a))throw new TypeError("Argument must be a Query");var d=z.QueryMixin("top_children"),e=d.toJSON();return e.top_children.query=a.toJSON(),e.top_children.type=b,c(d,{query:function(a){if(null==a)return e.top_children.query;if(!l(a))throw new TypeError("Argument must be a Query");return e.top_children.query=a.toJSON(),this},type:function(a){return null==a?e.top_children.type:(e.top_children.type=a,this)},scope:function(){return this},score:function(a){return null==a?e.top_children.score:(a=a.toLowerCase(),("max"===a||"sum"===a||"avg"===a||"total"===a)&&(e.top_children.score=a),this)},scoreMode:function(a){return null==a?e.top_children.score_mode:(a=a.toLowerCase(),("max"===a||"sum"===a||"avg"===a||"total"===a)&&(e.top_children.score_mode=a),this)},factor:function(a){return null==a?e.top_children.factor:(e.top_children.factor=a,this)},incrementalFactor:function(a){return null==a?e.top_children.incremental_factor:(e.top_children.incremental_factor=a,this)}})},z.WildcardQuery=function(a,b){var d=z.QueryMixin("wildcard"),e=d.toJSON();return e.wildcard[a]={value:b},c(d,{field:function(b){var c=e.wildcard[a];return null==b?a:(delete e.wildcard[a],a=b,e.wildcard[b]=c,this)},value:function(b){return null==b?e.wildcard[a].value:(e.wildcard[a].value=b,this)},rewrite:function(b){return null==b?e.wildcard[a].rewrite:(b=b.toLowerCase(),("constant_score_auto"===b||"scoring_boolean"===b||"constant_score_boolean"===b||"constant_score_filter"===b||0===b.indexOf("top_terms_boost_")||0===b.indexOf("top_terms_"))&&(e.wildcard[a].rewrite=b),this)},boost:function(b){return null==b?e.wildcard[a].boost:(e.wildcard[a].boost=b,this)}})},z.BoostFactorScoreFunction=function(a){var b=z.ScoreFunctionMixin("boost_factor"),d=b.toJSON();return d.boost_factor=a,c(b,{boost:function(a){return null==a?d.boost_factor:(d.boost_factor=a,this)}})},z.DecayScoreFunction=function(a){var b="gauss",d=z.ScoreFunctionMixin(b),e=d.toJSON(),f=function(a){var c;b!==a&&(c=e[b],delete e[b],b=a,e[b]=c)};return e[b][a]={},c(d,{linear:function(){f("linear")},exp:function(){f("exp")},gauss:function(){f("gauss")},field:function(c){var d=e[b][a];return null==c?a:(delete e[b][a],a=c,e[b][a]=d,this)},scale:function(c){return null==c?e[b][a].scale:(e[b][a].scale=c,this)},origin:function(c){if(null==c)return e[b][a].origin;if(r(c))e[b][a].origin=c.toJSON();else{if(k(c))throw new TypeError("origin must be a GeoPoint or native type");e[b][a].origin=c}return this},decay:function(c){return null==c?e[b][a].decay:(e[b][a].decay=c,this)},offset:function(c){return null==c?e[b][a].offset:(e[b][a].offset=c,this)}})},z.RandomScoreFunction=function(){var a=z.ScoreFunctionMixin("random_score"),b=a.toJSON();return c(a,{seed:function(a){return null==a?b.random_score.seed:(b.random_score.seed=a,this)}})},z.ScriptScoreFunction=function(){var a=z.ScoreFunctionMixin("script_score"),b=a.toJSON();return c(a,{script:function(a){return null==a?b.script_score.script:(b.script_score.script=a,this)},lang:function(a){return null==a?b.script_score.lang:(b.script_score.lang=a,this)},params:function(a){return null==a?b.script_score.params:(b.script_score.params=a,this)}})},z.GeoPoint=function(b){var c=[0,0];return null!=b&&e(b)&&2===b.length&&(c=[b[1],b[0]]),{properties:function(b){return null==b?c:(f(b)&&a(b,"lat")&&a(b,"lon")?c={lat:b.lat,lon:b.lon}:f(b)&&a(b,"geohash")&&(c={geohash:b.geohash}),this)},string:function(a){return null==a?c:(g(a)&&-1!==a.indexOf(",")&&(c=a),this)},geohash:function(a,b){return b=null!=b&&h(b)?b:12,null==a?c:(g(a)&&a.length===b&&(c=a),this)},array:function(a){return null==a?c:(e(a)&&2===a.length&&(c=[a[1],a[0]]),this)},_type:function(){return"geo point"},toJSON:function(){return c}}},z.Highlight=function(c){var d={fields:{}},h=function(b,c,e){null==b?d[c]=e:(a(d.fields,b)||(d.fields[b]={}),d.fields[b][c]=e)};return null!=c&&(g(c)?d.fields[c]={}:e(c)&&b(c,function(a){d.fields[a]={}})),{fields:function(c){return null==c?d.fields:void(g(c)?a(d.fields,c)||(d.fields[c]={}):e(c)&&b(c,function(b){a(d.fields,b)||(d.fields[b]={})}))},preTags:function(a,b){return null===a&&null!=b?d.fields[b].pre_tags:null==a?d.pre_tags:(g(a)?h(b,"pre_tags",[a]):e(a)&&h(b,"pre_tags",a),this)},postTags:function(a,b){return null===a&&null!=b?d.fields[b].post_tags:null==a?d.post_tags:(g(a)?h(b,"post_tags",[a]):e(a)&&h(b,"post_tags",a),this)},order:function(a,b){return null===a&&null!=b?d.fields[b].order:null==a?d.order:(a=a.toLowerCase(),"score"===a&&h(b,"order",a),this)},tagsSchema:function(a){return null==a?d.tags_schema:(a=a.toLowerCase(),"styled"===a&&(d.tags_schema=a),this)},highlightFilter:function(a,b){return null===a&&null!=b?d.fields[b].highlight_filter:null==a?d.highlight_filter:(h(b,"highlight_filter",a),this)},fragmentSize:function(a,b){return null===a&&null!=b?d.fields[b].fragment_size:null==a?d.fragment_size:(h(b,"fragment_size",a),this)},numberOfFragments:function(a,b){return null===a&&null!=b?d.fields[b].number_of_fragments:null==a?d.number_of_fragments:(h(b,"number_of_fragments",a),this)},encoder:function(a){return null==a?d.encoder:(a=a.toLowerCase(),("default"===a||"html"===a)&&(d.encoder=a),this)},requireFieldMatch:function(a,b){return null===a&&null!=b?d.fields[b].require_field_match:null==a?d.require_field_match:(h(b,"require_field_match",a),this)},boundaryMaxScan:function(a,b){return null===a&&null!=b?d.fields[b].boundary_max_scan:null==a?d.boundary_max_scan:(h(b,"boundary_max_scan",a),this)},boundaryChars:function(a,b){return null===a&&null!=b?d.fields[b].boundary_chars:null==a?d.boundary_chars:(h(b,"boundary_chars",a),this)},type:function(a,b){return null===a&&null!=b?d.fields[b].type:null==a?d.type:(a=a.toLowerCase(),("fvh"===a||"plain"===a||"postings"===a)&&h(b,"type",a),this)},fragmenter:function(a,b){return null===a&&null!=b?d.fields[b].fragmenter:null==a?d.fragmenter:(a=a.toLowerCase(),("simple"===a||"span"===a)&&h(b,"fragmenter",a),this)},options:function(a,b){if(null===a&&null!=b)return d.fields[b].options;if(null==a)return d.options;if(!f(a)||e(a)||k(a))throw new TypeError("Parameter must be an object");return h(b,"options",a),this},_type:function(){return"highlight"},toJSON:function(){return d}}},z.IndexedShape=function(a,b){var c={type:a,id:b};return{type:function(a){return null==a?c.type:(c.type=a,this)},id:function(a){return null==a?c.id:(c.id=a,this)},index:function(a){return null==a?c.index:(c.index=a,this)},shapeFieldName:function(a){return null==a?c.shape_field_name:(c.shape_field_name=a,this)},_type:function(){return"indexed shape"},toJSON:function(){return c}}},z.Request=function(){var b={};return{sort:function(){var c,d;if(a(b,"sort")||(b.sort=[]),0===arguments.length)return b.sort;if(1===arguments.length){var f=arguments[0];if(g(f))b.sort.push(f);else if(u(f))b.sort.push(f.toJSON());else{if(!e(f))throw new TypeError("Argument must be string, Sort, or array");for(b.sort=[],c=0,d=f.length;d>c;c++)if(g(f[c]))b.sort.push(f[c]);else{if(!u(f[c]))throw new TypeError("Invalid object in array");b.sort.push(f[c].toJSON())}}}else if(2===arguments.length){var h=arguments[0],i=arguments[1];if(g(h)&&g(i)&&(i=i.toLowerCase(),"asc"===i||"desc"===i)){var j={};j[h]={order:i},b.sort.push(j)}}return this},trackScores:function(a){return null==a?b.track_scores:(b.track_scores=a,this)},from:function(a){return null==a?b.from:(b.from=a,this)},size:function(a){return null==a?b.size:(b.size=a,this)},timeout:function(a){return null==a?b.timeout:(b.timeout=a,this)},fields:function(a){if(null==a)return b.fields;if(null==b.fields&&(b.fields=[]),g(a))b.fields.push(a);else{if(!e(a))throw new TypeError("Argument must be a string or an array");b.fields=a}return this},source:function(a,c){if(null==a&&null==c)return b._source;if(!e(a)&&!g(a)&&!i(a))throw new TypeError("Argument includes must be a string, an array, or a boolean");if(null!=c&&!e(c)&&!g(c))throw new TypeError("Argument excludes must be a string or an array");return i(a)?b._source=a:(b._source={includes:a},null!=c&&(b._source.excludes=c)),this},rescore:function(a){if(null==a)return b.rescore;if(!m(a))throw new TypeError("Argument must be a Rescore");return b.rescore=a.toJSON(),this},query:function(a){if(null==a)return b.query;if(!l(a))throw new TypeError("Argument must be a Query");return b.query=a.toJSON(),this},facet:function(a){if(null==a)return b.facets;if(null==b.facets&&(b.facets={}),!o(a))throw new TypeError("Argument must be a Facet");return c(b.facets,a.toJSON()),this},aggregation:function(a){if(null==a)return b.aggs;if(null==b.aggs&&(b.aggs={}),!p(a))throw new TypeError("Argument must be an Aggregation");return c(b.aggs,a.toJSON()),this},agg:function(a){return this.aggregation(a)},filter:function(a){if(null==a)return b.filter;if(!n(a))throw new TypeError("Argument must be a Filter");return b.filter=a.toJSON(),this},highlight:function(a){if(null==a)return b.highlight;if(!v(a))throw new TypeError("Argument must be a Highlight object");return b.highlight=a.toJSON(),this},suggest:function(a){if(null==a)return b.suggest;if(null==b.suggest&&(b.suggest={}),g(a))b.suggest.text=a;else{if(!w(a))throw new TypeError("Argument must be a string or Suggest object");c(b.suggest,a.toJSON())}return this},scriptField:function(a){if(null==a)return b.script_fields;if(null==b.script_fields&&(b.script_fields={}),!q(a))throw new TypeError("Argument must be a ScriptField");return c(b.script_fields,a.toJSON()),this},indexBoost:function(a,c){return null==b.indices_boost&&(b.indices_boost={}),0===arguments.length?b.indices_boost:(b.indices_boost[a]=c,this)},explain:function(a){return null==a?b.explain:(b.explain=a,this)},version:function(a){return null==a?b.version:(b.version=a,this)},minScore:function(a){return null==a?b.min_score:(b.min_score=a,this)},_type:function(){return"request"},toJSON:function(){return b}}},z.Rescore=function(a,b){if(null!=a&&!h(a))throw new TypeError("Argument must be a Number");if(null!=b&&!l(b))throw new TypeError("Argument must be a Query");var c={query:{}};return null!=a&&(c.window_size=a),null!=b&&(c.query.rescore_query=b.toJSON()),{rescoreQuery:function(a){if(null==a)return c.query.rescore_query;if(!l(a))throw new TypeError("Argument must be a Query");return c.query.rescore_query=a.toJSON(),this},queryWeight:function(a){if(null==a)return c.query.query_weight;if(!h(a))throw new TypeError("Argument must be a Number");return c.query.query_weight=a,this},rescoreQueryWeight:function(a){if(null==a)return c.query.rescore_query_weight;if(!h(a))throw new TypeError("Argument must be a Number");return c.query.rescore_query_weight=a,this},windowSize:function(a){if(null==a)return c.window_size;if(!h(a))throw new TypeError("Argument must be a Number");return c.window_size=a,this},scoreMode:function(a){return null==a?c.query.score_mode:(a=a.toLowerCase(),("total"===a||"min"===a||"max"===a||"multiply"===a||"avg"===a)&&(c.query.score_mode=a),this)},_type:function(){return"rescore"},toJSON:function(){return c}}},z.ScriptField=function(a){var b={};return b[a]={},{lang:function(c){return null==c?b[a].lang:(b[a].lang=c,this)},script:function(c){return null==c?b[a].script:(b[a].script=c,this)},params:function(c){return null==c?b[a].params:(b[a].params=c,this)},ignoreFailure:function(c){return null==c?b[a].ignore_failure:(b[a].ignore_failure=c,this)},_type:function(){return"script field"},toJSON:function(){return b}}},z.Shape=function(a,b){var c={},d=function(a){var b=!1;return("point"===a||"linestring"===a||"polygon"===a||"multipoint"===a||"envelope"===a||"multipolygon"===a||"circle"===a||"multilinestring"===a)&&(b=!0),b};return a=a.toLowerCase(),d(a)&&(c.type=a,c.coordinates=b),{type:function(a){return null==a?c.type:(a=a.toLowerCase(),d(a)&&(c.type=a),this)},coordinates:function(a){return null==a?c.coordinates:(c.coordinates=a,this)},radius:function(a){return null==a?c.radius:(c.radius=a,this)},_type:function(){return"shape"},toJSON:function(){return c}}},z.Sort=function(a){null==a&&(a="_score");var b={},c=a,d="_geo_distance",e="_script";return b[c]={},{field:function(d){var e=b[c];return null==d?a:(delete b[c],a=d,c=d,b[c]=e,this)},geoDistance:function(e){var f=b[c];if(null==e)return b[c][a];if(!r(e))throw new TypeError("Argument must be a GeoPoint");return delete b[c],c=d,b[c]=f,b[c][a]=e.toJSON(),this},script:function(a){var d=b[c];return null==a?b[c].script:(delete b[c],c=e,b[c]=d,b[c].script=a,this)},order:function(a){return null==a?b[c].order:(a=a.toLowerCase(),("asc"===a||"desc"===a)&&(b[c].order=a),this)},asc:function(){return b[c].order="asc",this},desc:function(){return b[c].order="desc",this},reverse:function(a){return null==a?b[c].reverse:(b[c].reverse=a,this)},missing:function(a){return null==a?b[c].missing:(b[c].missing=a,this)},ignoreUnmapped:function(a){return null==a?b[c].ignore_unmapped:(b[c].ignore_unmapped=a,this)},unit:function(a){return null==a?b[c].unit:(a=a.toLowerCase(),("mi"===a||"km"===a)&&(b[c].unit=a),this)},normalize:function(a){return null==a?b[c].normalize:(b[c].normalize=a,this)},distanceType:function(a){return null==a?b[c].distance_type:(a=a.toLowerCase(),("arc"===a||"plane"===a)&&(b[c].distance_type=a),this)},params:function(a){return null==a?b[c].params:(b[c].params=a,this)},lang:function(a){return null==a?b[c].lang:(b[c].lang=a,this) -},type:function(a){return null==a?b[c].type:(a=a.toLowerCase(),("string"===a||"number"===a)&&(b[c].type=a),this)},mode:function(a){return null==a?b[c].mode:(a=a.toLowerCase(),("min"===a||"max"===a||"sum"===a||"avg"===a)&&(b[c].mode=a),this)},nestedPath:function(a){return null==a?b[c].nested_path:(b[c].nested_path=a,this)},nestedFilter:function(a){if(null==a)return b[c].nested_filter;if(!n(a))throw new TypeError("Argument must be a Filter");return b[c].nested_filter=a.toJSON(),this},_type:function(){return"sort"},toJSON:function(){return b}}},z.CompletionSuggester=function(a){var b,d=z.SuggesterMixin(a),e=d.toJSON();return e[a].completion={},b=z.SuggestContextMixin(e[a].completion),c(d,b,{fuzzy:function(b){return null==b?e[a].completion.fuzzy:(b&&null==e[a].completion.fuzzy?e[a].completion.fuzzy={}:b||null==e[a].completion.fuzzy||delete e[a].completion.fuzzy,this)},transpositions:function(b){return null==e[a].completion.fuzzy&&(e[a].completion.fuzzy={}),null==b?e[a].completion.fuzzy.transpositions:(e[a].completion.fuzzy.transpositions=b,this)},unicodeAware:function(b){return null==e[a].completion.fuzzy&&(e[a].completion.fuzzy={}),null==b?e[a].completion.fuzzy.unicode_aware:(e[a].completion.fuzzy.unicode_aware=b,this)},editDistance:function(b){return null==e[a].completion.fuzzy&&(e[a].completion.fuzzy={}),null==b?e[a].completion.fuzzy.edit_distance:(e[a].completion.fuzzy.edit_distance=b,this)},minLength:function(b){return null==e[a].completion.fuzzy&&(e[a].completion.fuzzy={}),null==b?e[a].completion.fuzzy.min_length:(e[a].completion.fuzzy.min_length=b,this)},prefixLength:function(b){return null==e[a].completion.fuzzy&&(e[a].completion.fuzzy={}),null==b?e[a].completion.fuzzy.prefix_length:(e[a].completion.fuzzy.prefix_length=b,this)}})},z.DirectGenerator=function(){var a={},b=z.DirectSettingsMixin(a);return c(b,{preFilter:function(b){return null==b?a.pre_filter:(a.pre_filter=b,this)},postFilter:function(b){return null==b?a.post_filter:(a.post_filter=b,this)},field:function(b){return null==b?a.field:(a.field=b,this)},size:function(b){return null==b?a.size:(a.size=b,this)},_type:function(){return"generator"},toJSON:function(){return a}})},z.PhraseSuggester=function(a){var b,d=z.SuggesterMixin(a),f=d.toJSON();return f[a].phrase={},b=z.SuggestContextMixin(f[a].phrase),c(d,b,{realWordErrorLikelihood:function(b){return null==b?f[a].phrase.real_word_error_likelihood:(f[a].phrase.real_word_error_likelihood=b,this)},confidence:function(b){return null==b?f[a].phrase.confidence:(f[a].phrase.confidence=b,this)},separator:function(b){return null==b?f[a].phrase.separator:(f[a].phrase.separator=b,this)},maxErrors:function(b){return null==b?f[a].phrase.max_errors:(f[a].phrase.max_errors=b,this)},gramSize:function(b){return null==b?f[a].phrase.gram_size:(f[a].phrase.gram_size=b,this)},forceUnigrams:function(b){return null==b?f[a].phrase.force_unigrams:(f[a].phrase.force_unigrams=b,this)},tokenLimit:function(b){return null==b?f[a].phrase.token_limit:(f[a].phrase.token_limit=b,this)},linearSmoothing:function(b,c,d){return 0===arguments.length?f[a].phrase.smoothing:(f[a].phrase.smoothing={linear:{trigram_lambda:b,bigram_lambda:c,unigram_lambda:d}},this)},laplaceSmoothing:function(b){return null==b?f[a].phrase.smoothing:(f[a].phrase.smoothing={laplace:{alpha:b}},this)},stupidBackoffSmoothing:function(b){return null==b?f[a].phrase.smoothing:(f[a].phrase.smoothing={stupid_backoff:{discount:b}},this)},highlight:function(b,c){return 0===arguments.length?f[a].phrase.highlight:(f[a].phrase.highlight={pre_tag:b,post_tag:c},this)},directGenerator:function(b){var c,d;if(null==f[a].phrase.direct_generator&&(f[a].phrase.direct_generator=[]),null==b)return f[a].phrase.direct_generator;if(x(b))f[a].phrase.direct_generator.push(b.toJSON());else{if(!e(b))throw new TypeError("Argument must be a Generator or array of Generators");for(f[a].phrase.direct_generator=[],c=0,d=b.length;d>c;c++){if(!x(b[c]))throw new TypeError("Argument must be an array of Generators");f[a].phrase.direct_generator.push(b[c].toJSON())}}return this}})},z.TermSuggester=function(a){var b,d,e=z.SuggesterMixin(a),f=e.toJSON();return f[a].term={},b=z.DirectSettingsMixin(f[a].term),d=z.SuggestContextMixin(f[a].term),c(e,b,d)},z.noConflict=function(){return A.ejs=B,this}}).call(this); \ No newline at end of file +(function(){"use strict";var a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,A,B=this,C=B&&B.ejs,D=Array.prototype,E=Object.prototype,F=D.slice,G=E.toString,H=E.hasOwnProperty,I=D.forEach,J=Array.isArray,K=D.indexOf,L={};A="undefined"!=typeof exports?exports:B.ejs={},a=function(a,b){return H.call(a,b)},b=function(b,c,d){if(null!=b)if(I&&b.forEach===I)b.forEach(c,d);else if(b.length===+b.length){for(var e=0,f=b.length;f>e;e++)if(c.call(d,b[e],e,b)===L)return}else for(var g in b)if(a(b,g)&&c.call(d,b[g],g,b)===L)return},c=function(a){return b(F.call(arguments,1),function(b){for(var c in b)a[c]=b[c]}),a},d=function(a,b){if(null==a)return-1;var c=0,d=a.length;if(K&&a.indexOf===K)return a.indexOf(b);for(;d>c;c++)if(a[c]===b)return c;return-1},e=J||function(a){return"[object Array]"===G.call(a)},f=function(a){return a===Object(a)},g=function(a){return"[object String]"===G.call(a)},h=function(a){return"[object Number]"===G.call(a)},i=function(a){return a===!0||a===!1||"[object Boolean]"===G.call(a)},j="function"!=typeof/./?function(a){return"function"==typeof a}:function(a){return"[object Function]"===G.call(a)},k=function(b){return f(b)&&a(b,"_type")&&a(b,"toJSON")},l=function(a){return k(a)&&"query"===a._type()},m=function(a){return k(a)&&"rescore"===a._type()},n=function(a){return k(a)&&"filter"===a._type()},o=function(a){return k(a)&&"facet"===a._type()},p=function(a){return k(a)&&"aggregation"===a._type()},q=function(a){return k(a)&&"script field"===a._type()},r=function(a){return k(a)&&"geo point"===a._type()},s=function(a){return k(a)&&"indexed shape"===a._type()},t=function(a){return k(a)&&"shape"===a._type()},u=function(a){return k(a)&&"sort"===a._type()},v=function(a){return k(a)&&"highlight"===a._type()},w=function(a){return k(a)&&"suggest"===a._type()},x=function(a){return k(a)&&"generator"===a._type()},y=function(a){return k(a)&&"score function"===a._type()},z=function(a){return k(a)&&"script"===a._type()},A.AggregationMixin=function(a){var b={};return b[a]={},{aggregation:function(d){if(null==d)return b[a].aggs;if(null==b[a].aggs&&(b[a].aggs={}),!p(d))throw new TypeError("Argument must be an Aggregation");return c(b[a].aggs,d.toJSON()),this},agg:function(a){return this.aggregation(a)},_type:function(){return"aggregation"},toJSON:function(){return b}}},A.DirectSettingsMixin=function(a){return{accuracy:function(b){return null==b?a.accuracy:(a.accuracy=b,this)},suggestMode:function(b){return null==b?a.suggest_mode:(b=b.toLowerCase(),("missing"===b||"popular"===b||"always"===b)&&(a.suggest_mode=b),this)},sort:function(b){return null==b?a.sort:(b=b.toLowerCase(),("score"===b||"frequency"===b)&&(a.sort=b),this)},stringDistance:function(b){return null==b?a.string_distance:(b=b.toLowerCase(),("internal"===b||"damerau_levenshtein"===b||"levenstein"===b||"jarowinkler"===b||"ngram"===b)&&(a.string_distance=b),this)},maxEdits:function(b){return null==b?a.max_edits:(a.max_edits=b,this)},maxInspections:function(b){return null==b?a.max_inspections:(a.max_inspections=b,this)},maxTermFreq:function(b){return null==b?a.max_term_freq:(a.max_term_freq=b,this)},prefixLen:function(b){return null==b?a.prefix_len:(a.prefix_len=b,this)},minWordLen:function(b){return null==b?a.min_word_len:(a.min_word_len=b,this)},minDocFreq:function(b){return null==b?a.min_doc_freq:(a.min_doc_freq=b,this)}}},A.FacetMixin=function(a){var b={};return b[a]={},{facetFilter:function(c){if(null==c)return b[a].facet_filter;if(!n(c))throw new TypeError("Argument must be a Filter");return b[a].facet_filter=c.toJSON(),this},global:function(c){return null==c?b[a].global:(b[a].global=c,this)},mode:function(c){return null==c?b[a].mode:(c=c.toLowerCase(),("collector"===c||"post"===c)&&(b[a].mode=c),this)},cacheFilter:function(c){return null==c?b[a].cache_filter:(b[a].cache_filter=c,this)},scope:function(a){return this},nested:function(c){return null==c?b[a].nested:(b[a].nested=c,this)},_type:function(){return"facet"},toJSON:function(){return b}}},A.FilterMixin=function(a){var b={};return b[a]={},{name:function(c){return null==c?b[a]._name:(b[a]._name=c,this)},cache:function(c){return null==c?b[a]._cache:(b[a]._cache=c,this)},cacheKey:function(c){return null==c?b[a]._cache_key:(b[a]._cache_key=c,this)},_type:function(){return"filter"},toJSON:function(){return b}}},A.MetricsAggregationMixin=function(a,b){var d=A.AggregationMixin(a),e=d.toJSON();return delete d.aggregation,delete d.agg,e[a][b]={},c(d,{field:function(c){return null==c?e[a][b].field:(e[a][b].field=c,this)},script:function(c){return null==c?e[a][b].script:(e[a][b].script=c,this)},lang:function(c){return null==c?e[a][b].lang:(e[a][b].lang=c,this)},scriptValuesSorted:function(c){return null==c?e[a][b].script_values_sorted:(e[a][b].script_values_sorted=c,this)},params:function(c){return null==c?e[a][b].params:(e[a][b].params=c,this)}})},A.QueryMixin=function(a){var b={};return b[a]={},{boost:function(c){return null==c?b[a].boost:(b[a].boost=c,this)},_type:function(){return"query"},toJSON:function(){return b}}},A.ScoreFunctionMixin=function(a){var b={};return b[a]={},{filter:function(a){if(null==a)return b.filter;if(!n(a))throw new TypeError("Argument must be a Filter");return b.filter=a.toJSON(),this},_type:function(){return"score function"},toJSON:function(){return b}}},A.SuggestContextMixin=function(a){return{analyzer:function(b){return null==b?a.analyzer:(a.analyzer=b,this)},field:function(b){return null==b?a.field:(a.field=b,this)},size:function(b){return null==b?a.size:(a.size=b,this)},shardSize:function(b){return null==b?a.shard_size:(a.shard_size=b,this)}}},A.SuggesterMixin=function(a){var b={};return b[a]={},{text:function(c){return null==c?b[a].text:(b[a].text=c,this)},_type:function(){return"suggest"},toJSON:function(){return b}}},A.DateHistogramFacet=function(a){var b=A.FacetMixin(a),d=b.toJSON();return d[a].date_histogram={},c(b,{field:function(b){return null==b?d[a].date_histogram.field:(d[a].date_histogram.field=b,this)},keyField:function(b){return null==b?d[a].date_histogram.key_field:(d[a].date_histogram.key_field=b,this)},valueField:function(b){return null==b?d[a].date_histogram.value_field:(d[a].date_histogram.value_field=b,this)},interval:function(b){return null==b?d[a].date_histogram.interval:(d[a].date_histogram.interval=b,this)},timeZone:function(b){return null==b?d[a].date_histogram.time_zone:(d[a].date_histogram.time_zone=b,this)},preZone:function(b){return null==b?d[a].date_histogram.pre_zone:(d[a].date_histogram.pre_zone=b,this)},preZoneAdjustLargeInterval:function(b){return null==b?d[a].date_histogram.pre_zone_adjust_large_interval:(d[a].date_histogram.pre_zone_adjust_large_interval=b,this)},postZone:function(b){return null==b?d[a].date_histogram.post_zone:(d[a].date_histogram.post_zone=b,this)},preOffset:function(b){return null==b?d[a].date_histogram.pre_offset:(d[a].date_histogram.pre_offset=b,this)},postOffset:function(b){return null==b?d[a].date_histogram.post_offset:(d[a].date_histogram.post_offset=b,this)},factor:function(b){return null==b?d[a].date_histogram.factor:(d[a].date_histogram.factor=b,this)},valueScript:function(b){return null==b?d[a].date_histogram.value_script:(d[a].date_histogram.value_script=b,this)},order:function(b){return null==b?d[a].date_histogram.order:(b=b.toLowerCase(),("time"===b||"count"===b||"total"===b)&&(d[a].date_histogram.order=b),this)},lang:function(b){return null==b?d[a].date_histogram.lang:(d[a].date_histogram.lang=b,this)},params:function(b){return null==b?d[a].date_histogram.params:(d[a].date_histogram.params=b,this)}})},A.FilterFacet=function(a){var b=A.FacetMixin(a),d=b.toJSON();return c(b,{filter:function(b){if(null==b)return d[a].filter;if(!n(b))throw new TypeError("Argument must be a Filter");return d[a].filter=b.toJSON(),this}})},A.GeoDistanceFacet=function(a){var b=A.FacetMixin(a),d=b.toJSON(),e=A.GeoPoint([0,0]),f="location";return d[a].geo_distance={location:e.toJSON(),ranges:[]},c(b,{field:function(b){var c=d[a].geo_distance[f];return null==b?f:(delete d[a].geo_distance[f],f=b,d[a].geo_distance[b]=c,this)},point:function(b){if(null==b)return e;if(!r(b))throw new TypeError("Argument must be a GeoPoint");return e=b,d[a].geo_distance[f]=b.toJSON(),this},addRange:function(b,c){return 0===arguments.length?d[a].geo_distance.ranges:(d[a].geo_distance.ranges.push({from:b,to:c}),this)},addUnboundedFrom:function(b){return null==b?d[a].geo_distance.ranges:(d[a].geo_distance.ranges.push({from:b}),this)},addUnboundedTo:function(b){return null==b?d[a].geo_distance.ranges:(d[a].geo_distance.ranges.push({to:b}),this)},unit:function(b){return null==b?d[a].geo_distance.unit:(b=b.toLowerCase(),("mi"===b||"km"===b)&&(d[a].geo_distance.unit=b),this)},distanceType:function(b){return null==b?d[a].geo_distance.distance_type:(b=b.toLowerCase(),("arc"===b||"plane"===b)&&(d[a].geo_distance.distance_type=b),this)},normalize:function(b){return null==b?d[a].geo_distance.normalize:(d[a].geo_distance.normalize=b,this)},valueField:function(b){return null==b?d[a].geo_distance.value_field:(d[a].geo_distance.value_field=b,this)},valueScript:function(b){return null==b?d[a].geo_distance.value_script:(d[a].geo_distance.value_script=b,this)},lang:function(b){return null==b?d[a].geo_distance.lang:(d[a].geo_distance.lang=b,this)},params:function(b){return null==b?d[a].geo_distance.params:(d[a].geo_distance.params=b,this)}})},A.HistogramFacet=function(a){var b=A.FacetMixin(a),d=b.toJSON();return d[a].histogram={},c(b,{field:function(b){return null==b?d[a].histogram.field:(d[a].histogram.field=b,this)},interval:function(b){return null==b?d[a].histogram.interval:(d[a].histogram.interval=b,this)},timeInterval:function(b){return null==b?d[a].histogram.time_interval:(d[a].histogram.time_interval=b,this)},from:function(b){return null==b?d[a].histogram.from:(d[a].histogram.from=b,this)},to:function(b){return null==b?d[a].histogram.to:(d[a].histogram.to=b,this)},valueField:function(b){return null==b?d[a].histogram.value_field:(d[a].histogram.value_field=b,this)},keyField:function(b){return null==b?d[a].histogram.key_field:(d[a].histogram.key_field=b,this)},valueScript:function(b){return null==b?d[a].histogram.value_script:(d[a].histogram.value_script=b,this)},keyScript:function(b){return null==b?d[a].histogram.key_script:(d[a].histogram.key_script=b,this)},lang:function(b){return null==b?d[a].histogram.lang:(d[a].histogram.lang=b,this)},params:function(b){return null==b?d[a].histogram.params:(d[a].histogram.params=b,this)},order:function(b){return null==b?d[a].histogram.order:(b=b.toLowerCase(),("key"===b||"count"===b||"total"===b)&&(d[a].histogram.order=b),this)}})},A.QueryFacet=function(a){var b=A.FacetMixin(a),d=b.toJSON();return c(b,{query:function(b){if(null==b)return d[a].query;if(!l(b))throw new TypeError("Argument must be a Query");return d[a].query=b.toJSON(),this}})},A.RangeFacet=function(a){var b=A.FacetMixin(a),d=b.toJSON();return d[a].range={ranges:[]},c(b,{field:function(b){return null==b?d[a].range.field:(d[a].range.field=b,this)},keyField:function(b){return null==b?d[a].range.key_field:(d[a].range.key_field=b,this)},valueField:function(b){return null==b?d[a].range.value_field:(d[a].range.value_field=b,this)},valueScript:function(b){return null==b?d[a].range.value_script:(d[a].range.value_script=b,this)},keyScript:function(b){return null==b?d[a].range.key_script:(d[a].range.key_script=b,this)},lang:function(b){return null==b?d[a].range.lang:(d[a].range.lang=b,this)},params:function(b){return null==b?d[a].range.params:(d[a].range.params=b,this)},addRange:function(b,c){return 0===arguments.length?d[a].range.ranges:(d[a].range.ranges.push({from:b,to:c}),this)},addUnboundedFrom:function(b){return null==b?d[a].range.ranges:(d[a].range.ranges.push({from:b}),this)},addUnboundedTo:function(b){return null==b?d[a].range.ranges:(d[a].range.ranges.push({to:b}),this)}})},A.StatisticalFacet=function(a){var b=A.FacetMixin(a),d=b.toJSON();return d[a].statistical={},c(b,{field:function(b){return null==b?d[a].statistical.field:(d[a].statistical.field=b,this)},fields:function(b){if(null==b)return d[a].statistical.fields;if(!e(b))throw new TypeError("Argument must be an array");return d[a].statistical.fields=b,this},script:function(b){return null==b?d[a].statistical.script:(d[a].statistical.script=b,this)},lang:function(b){return null==b?d[a].statistical.lang:(d[a].statistical.lang=b,this)},params:function(b){return null==b?d[a].statistical.params:(d[a].statistical.params=b,this)}})},A.TermStatsFacet=function(a){var b=A.FacetMixin(a),d=b.toJSON();return d[a].terms_stats={},c(b,{valueField:function(b){return null==b?d[a].terms_stats.value_field:(d[a].terms_stats.value_field=b,this)},keyField:function(b){return null==b?d[a].terms_stats.key_field:(d[a].terms_stats.key_field=b,this)},scriptField:function(b){return null==b?d[a].terms_stats.script_field:(d[a].terms_stats.script_field=b,this)},valueScript:function(b){return null==b?d[a].terms_stats.value_script:(d[a].terms_stats.value_script=b,this)},allTerms:function(b){return null==b?d[a].terms_stats.all_terms:(d[a].terms_stats.all_terms=b,this)},lang:function(b){return null==b?d[a].terms_stats.lang:(d[a].terms_stats.lang=b,this)},params:function(b){return null==b?d[a].terms_stats.params:(d[a].terms_stats.params=b,this)},size:function(b){return null==b?d[a].terms_stats.size:(d[a].terms_stats.size=b,this)},order:function(b){return null==b?d[a].terms_stats.order:(b=b.toLowerCase(),("count"===b||"term"===b||"reverse_count"===b||"reverse_term"===b||"total"===b||"reverse_total"===b||"min"===b||"reverse_min"===b||"max"===b||"reverse_max"===b||"mean"===b||"reverse_mean"===b)&&(d[a].terms_stats.order=b),this)}})},A.TermsFacet=function(a){var b=A.FacetMixin(a),d=b.toJSON();return d[a].terms={},c(b,{field:function(b){return null==b?d[a].terms.field:(d[a].terms.field=b,this)},fields:function(b){if(null==b)return d[a].terms.fields;if(!e(b))throw new TypeError("Argument must be an array");return d[a].terms.fields=b,this},scriptField:function(b){return null==b?d[a].terms.script_field:(d[a].terms.script_field=b,this)},size:function(b){return null==b?d[a].terms.size:(d[a].terms.size=b,this)},shardSize:function(b){return null==b?d[a].terms.shard_size:(d[a].terms.shard_size=b,this)},order:function(b){return null==b?d[a].terms.order:(b=b.toLowerCase(),("count"===b||"term"===b||"reverse_count"===b||"reverse_term"===b)&&(d[a].terms.order=b),this)},allTerms:function(b){return null==b?d[a].terms.all_terms:(d[a].terms.all_terms=b,this)},exclude:function(b){if(null==d[a].terms.exclude&&(d[a].terms.exclude=[]),null==b)return d[a].terms.exclude;if(g(b))d[a].terms.exclude.push(b);else{if(!e(b))throw new TypeError("Argument must be string or array");d[a].terms.exclude=b}return this},regex:function(b){return null==b?d[a].terms.regex:(d[a].terms.regex=b,this)},regexFlags:function(b){return null==b?d[a].terms.regex_flags:(d[a].terms.regex_flags=b,this)},script:function(b){return null==b?d[a].terms.script:(d[a].terms.script=b,this)},lang:function(b){return null==b?d[a].terms.lang:(d[a].terms.lang=b,this)},params:function(b){return null==b?d[a].terms.params:(d[a].terms.params=b,this)},executionHint:function(b){return null==b?d[a].terms.execution_hint:(d[a].terms.execution_hint=b,this)}})},A.AvgAggregation=function(a){var b=A.MetricsAggregationMixin(a,"avg");b.toJSON();return b},A.CardinalityAggregation=function(a){var b=A.MetricsAggregationMixin(a,"cardinality"),d=b.toJSON();return delete b.scriptValuesSorted,c(b,{rehash:function(b){return null==b?d[a].cardinality.rehash:(d[a].cardinality.rehash=b,this)},precisionThreshold:function(b){return null==b?d[a].cardinality.precision_threshold:(d[a].cardinality.precision_threshold=b,this)}})},A.DateHistogramAggregation=function(a){var b=A.AggregationMixin(a),d=b.toJSON();return d[a].date_histogram={},c(b,{field:function(b){return null==b?d[a].date_histogram.field:(d[a].date_histogram.field=b,this)},script:function(b){return null==b?d[a].date_histogram.script:(d[a].date_histogram.script=b,this)},lang:function(b){return null==b?d[a].date_histogram.lang:(d[a].date_histogram.lang=b,this)},timeZone:function(b){return null==b?d[a].date_histogram.time_zone:(d[a].date_histogram.time_zone=b,this)},preZone:function(b){return null==b?d[a].date_histogram.pre_zone:(d[a].date_histogram.pre_zone=b,this)},postZone:function(b){return null==b?d[a].date_histogram.post_zone:(d[a].date_histogram.post_zone=b,this)},preOffset:function(b){return null==b?d[a].date_histogram.pre_offset:(d[a].date_histogram.pre_offset=b,this)},postOffset:function(b){return null==b?d[a].date_histogram.post_offset:(d[a].date_histogram.post_offset=b,this)},extendedBounds:function(b,c){var e;return null==b&&null==c?d[a].date_histogram.extended_bounds:(e={},null!=b&&(e.min=b),null!=c&&(e.max=c),d[a].date_histogram.extended_bounds=e,this)},interval:function(b){return null==b?d[a].date_histogram.interval:(d[a].date_histogram.interval=b,this)},format:function(b){return null==b?d[a].date_histogram.format:(d[a].date_histogram.format=b,this)},keyed:function(b){return null==b?d[a].date_histogram.keyed:(d[a].date_histogram.keyed=b,this)},scriptValuesSorted:function(b){return null==b?d[a].date_histogram.script_values_sorted:(d[a].date_histogram.script_values_sorted=b,this)},preZoneAdjustLargeInterval:function(b){return null==b?d[a].date_histogram.pre_zone_adjust_large_interval:(d[a].date_histogram.pre_zone_adjust_large_interval=b,this)},minDocCount:function(b){return null==b?d[a].date_histogram.min_doc_count:(d[a].date_histogram.min_doc_count=b,this)},params:function(b){return null==b?d[a].date_histogram.params:(d[a].date_histogram.params=b,this)},order:function(b,c){return null==b?d[a].date_histogram.order:(null==c&&(c="desc"),c=c.toLowerCase(),"asc"!==c&&"desc"!==c&&(c="desc"),d[a].date_histogram.order={},d[a].date_histogram.order[b]=c,this)}})},A.DateRangeAggregation=function(a){var b=A.AggregationMixin(a),d=b.toJSON();return d[a].date_range={},c(b,{field:function(b){return null==b?d[a].date_range.field:(d[a].date_range.field=b,this)},script:function(b){return null==b?d[a].date_range.script:(d[a].date_range.script=b,this)},lang:function(b){return null==b?d[a].date_range.lang:(d[a].date_range.lang=b,this)},format:function(b){return null==b?d[a].date_range.format:(d[a].date_range.format=b,this)},range:function(b,c,e){var f={};return null==d[a].date_range.ranges&&(d[a].date_range.ranges=[]),null==b&&null==c?d[a].date_range.ranges:(null!=b&&(f.from=b),null!=c&&(f.to=c),null!=e&&(f.key=e),d[a].date_range.ranges.push(f),this)},keyed:function(b){return null==b?d[a].date_range.keyed:(d[a].date_range.keyed=b,this)},scriptValuesSorted:function(b){return null==b?d[a].date_range.script_values_sorted:(d[a].date_range.script_values_sorted=b,this)},params:function(b){return null==b?d[a].date_range.params:(d[a].date_range.params=b,this)}})},A.ExtendedStatsAggregation=function(a){var b=A.MetricsAggregationMixin(a,"extended_stats");b.toJSON();return b},A.FilterAggregation=function(a){var b=A.AggregationMixin(a),d=b.toJSON();return c(b,{filter:function(b){if(null==b)return d[a].filter;if(!n(b))throw new TypeError("Argument must be a Filter");return d[a].filter=b.toJSON(),this}})},A.FiltersAggregation=function(a){var b=A.AggregationMixin(a),d=b.toJSON();return c(b,{filters:function(b){if(null==b)return d[a].filters;var c,e,f={};d[a].filters={filters:f};for(c in b){if(e=b[c],!n(e))throw new TypeError("Argument must be a Filter");f[c]=e.toJSON()}return this}})},A.GeoDistanceAggregation=function(a){var b=A.AggregationMixin(a),d=A.GeoPoint([0,0]),e=b.toJSON();return e[a].geo_distance={},c(b,{field:function(b){return null==b?e[a].geo_distance.field:(e[a].geo_distance.field=b,this)},unit:function(b){return null==b?e[a].geo_distance.unit:(("in"===b||"yd"===b||"ft"===b||"km"===b||"NM"===b||"mm"===b||"cm"===b||"mi"===b||"m"===b)&&(e[a].geo_distance.unit=b),this)},distanceType:function(b){return null==b?e[a].geo_distance.distance_type:(b=b.toLowerCase(),("plane"===b||"arc"===b||"sloppy_arc"===b||"factor"===b)&&(e[a].geo_distance.distance_type=b),this)},origin:function(b){if(null==b)return d;if(!r(b))throw new TypeError("Argument must be a GeoPoint");return d=b,e[a].geo_distance.origin=b.toJSON(),this},point:function(b){if(null==b)return d;if(!r(b))throw new TypeError("Argument must be a GeoPoint");return d=b,e[a].geo_distance.point=b.toJSON(),this},center:function(b){if(null==b)return d;if(!r(b))throw new TypeError("Argument must be a GeoPoint");return d=b,e[a].geo_distance.center=b.toJSON(),this},range:function(b,c,d){var f={};return null==e[a].geo_distance.ranges&&(e[a].geo_distance.ranges=[]),null==b&&null==c?e[a].geo_distance.ranges:(null!=b&&(f.from=b),null!=c&&(f.to=c),null!=d&&(f.key=d),e[a].geo_distance.ranges.push(f),this)},keyed:function(b){return null==b?e[a].geo_distance.keyed:(e[a].geo_distance.keyed=b,this)}})},A.GeoHashGridAggregation=function(a){var b=A.AggregationMixin(a),d=b.toJSON();return d[a].geohash_grid={},c(b,{field:function(b){return null==b?d[a].geohash_grid.field:(d[a].geohash_grid.field=b,this)},precision:function(b){return null==b?d[a].geohash_grid.precision:(d[a].geohash_grid.precision=b,this)},size:function(b){return null==b?d[a].geohash_grid.size:(d[a].geohash_grid.size=b,this)},shardSize:function(b){return null==b?d[a].geohash_grid.shard_size:(d[a].geohash_grid.shard_size=b,this)}})},A.GlobalAggregation=function(a){var b=A.AggregationMixin(a),c=b.toJSON();return c[a].global={},b},A.HistogramAggregation=function(a){var b=A.AggregationMixin(a),d=b.toJSON();return d[a].histogram={},c(b,{field:function(b){return null==b?d[a].histogram.field:(d[a].histogram.field=b,this)},script:function(b){return null==b?d[a].histogram.script:(d[a].histogram.script=b,this)},lang:function(b){return null==b?d[a].histogram.lang:(d[a].histogram.lang=b,this)},format:function(b){return null==b?d[a].histogram.format:(d[a].histogram.format=b,this)},extendedBounds:function(b,c){var e;return null==b&&null==c?d[a].histogram.extended_bounds:(e={},null!=b&&(e.min=b),null!=c&&(e.max=c),d[a].histogram.extended_bounds=e,this)},interval:function(b){return null==b?d[a].histogram.interval:(d[a].histogram.interval=b,this)},minDocCount:function(b){return null==b?d[a].histogram.min_doc_count:(d[a].histogram.min_doc_count=b,this)},keyed:function(b){return null==b?d[a].histogram.keyed:(d[a].histogram.keyed=b,this)},scriptValuesSorted:function(b){return null==b?d[a].histogram.script_values_sorted:(d[a].histogram.script_values_sorted=b,this)},params:function(b){return null==b?d[a].histogram.params:(d[a].histogram.params=b,this)},order:function(b,c){return null==b?d[a].histogram.order:(null==c&&(c="desc"),c=c.toLowerCase(),"asc"!==c&&"desc"!==c&&(c="desc"),d[a].histogram.order={},d[a].histogram.order[b]=c,this)}})},A.IPv4RangeAggregation=function(a){var b=A.AggregationMixin(a),d=b.toJSON();return d[a].ip_range={},c(b,{field:function(b){return null==b?d[a].ip_range.field:(d[a].ip_range.field=b,this)},script:function(b){return null==b?d[a].ip_range.script:(d[a].ip_range.script=b,this)},lang:function(b){return null==b?d[a].ip_range.lang:(d[a].ip_range.lang=b,this)},range:function(b,c,e,f){var g={};return null==d[a].ip_range.ranges&&(d[a].ip_range.ranges=[]),null==b&&null==c&&null==e?d[a].ip_range.ranges:(null!=b&&(g.from=b),null!=c&&(g.to=c),null!=e&&(g.mask=e),null!=f&&(g.key=f),d[a].ip_range.ranges.push(g),this)},keyed:function(b){return null==b?d[a].ip_range.keyed:(d[a].ip_range.keyed=b,this)},scriptValuesSorted:function(b){return null==b?d[a].ip_range.script_values_sorted:(d[a].ip_range.script_values_sorted=b,this)},params:function(b){return null==b?d[a].ip_range.params:(d[a].ip_range.params=b,this)}})},A.MaxAggregation=function(a){var b=A.MetricsAggregationMixin(a,"max");b.toJSON();return b},A.MinAggregation=function(a){var b=A.MetricsAggregationMixin(a,"min");b.toJSON();return b},A.MissingAggregation=function(a){var b=A.AggregationMixin(a),d=b.toJSON();return d[a].missing={},c(b,{field:function(b){return null==b?d[a].missing.field:(d[a].missing.field=b,this)}})},A.NestedAggregation=function(a){var b=A.AggregationMixin(a),d=b.toJSON();return d[a].nested={},c(b,{path:function(b){return null==b?d[a].nested.path:(d[a].nested.path=b,this)}})},A.PercentilesAggregation=function(a){var b=A.MetricsAggregationMixin(a,"percentiles"),d=b.toJSON();return c(b,{keyed:function(b){return null==b?d[a].percentiles.keyed:(d[a].percentiles.keyed=b,this)},percents:function(b){if(null==b)return d[a].percentiles.percents;if(!e(b))throw new TypeError("Percents must be an array of doubles");return d[a].percentiles.percents=b,this},percent:function(b){return null==d[a].percentiles.percents&&(d[a].percentiles.percents=[]),null==b?d[a].percentiles.percents:(d[a].percentiles.percents.push(b),this)},compression:function(b){var c=d[a].percentiles.tdigest;return null==b?c&&c.compression:(c||(c=d[a].percentiles.tdigest={}),c.compression=b,this)}})},A.RangeAggregation=function(a){var b=A.AggregationMixin(a),d=b.toJSON();return d[a].range={},c(b,{field:function(b){return null==b?d[a].range.field:(d[a].range.field=b,this)},script:function(b){return null==b?d[a].range.script:(d[a].range.script=b,this)},lang:function(b){return null==b?d[a].range.lang:(d[a].range.lang=b,this)},range:function(b,c,e){var f={};return null==d[a].range.ranges&&(d[a].range.ranges=[]),null==b&&null==c?d[a].range.ranges:(null!=b&&(f.from=b),null!=c&&(f.to=c),null!=e&&(f.key=e),d[a].range.ranges.push(f),this)},keyed:function(b){return null==b?d[a].range.keyed:(d[a].range.keyed=b,this)},scriptValuesSorted:function(b){return null==b?d[a].range.script_values_sorted:(d[a].range.script_values_sorted=b,this)},params:function(b){return null==b?d[a].range.params:(d[a].range.params=b,this)}})},A.ReverseNestedAggregation=function(a){var b=A.AggregationMixin(a),d=b.toJSON();return d[a].reverse_nested={},c(b,{reversePath:function(b){return null==b?d[a].reverse_nested.path:(d[a].reverse_nested.path=b,this)}})},A.SignificantTermsAggregation=function(a){var b=A.AggregationMixin(a),d=b.toJSON();return d[a].significant_terms={},c(b,{field:function(b){return null==b?d[a].significant_terms.field:(d[a].significant_terms.field=b,this)},format:function(b){return null==b?d[a].significant_terms.format:(d[a].significant_terms.format=b,this)},include:function(b,c){return null==d[a].significant_terms.include&&(d[a].significant_terms.include={}),null==b?d[a].significant_terms.include:(d[a].significant_terms.include.pattern=b,null!=c&&(d[a].significant_terms.include.flags=c),this)},exclude:function(b,c){return null==d[a].significant_terms.exclude&&(d[a].significant_terms.exclude={}),null==b?d[a].significant_terms.exclude:(d[a].significant_terms.exclude.pattern=b,null!=c&&(d[a].significant_terms.exclude.flags=c),this)},executionHint:function(b){return null==b?d[a].significant_terms.execution_hint:(b=b.toLowerCase(),("map"===b||"ordinals"===b)&&(d[a].significant_terms.execution_hint=b),this)},size:function(b){return null==b?d[a].significant_terms.size:(d[a].significant_terms.size=b,this)},shardSize:function(b){return null==b?d[a].significant_terms.shard_size:(d[a].significant_terms.shard_size=b,this)},minDocCount:function(b){return null==b?d[a].significant_terms.min_doc_count:(d[a].significant_terms.min_doc_count=b,this)}})},A.StatsAggregation=function(a){var b=A.MetricsAggregationMixin(a,"stats");b.toJSON();return b},A.SumAggregation=function(a){var b=A.MetricsAggregationMixin(a,"sum");b.toJSON();return b},A.TermsAggregation=function(a){var b=A.AggregationMixin(a),d=b.toJSON();return d[a].terms={},c(b,{field:function(b){return null==b?d[a].terms.field:(d[a].terms.field=b,this)},script:function(b){return null==b?d[a].terms.script:(d[a].terms.script=b,this)},lang:function(b){return null==b?d[a].terms.lang:(d[a].terms.lang=b,this)},valueType:function(b){return null==b?d[a].terms.value_type:(b=b.toLowerCase(),("string"===b||"double"===b||"float"===b||"long"===b||"integer"===b||"short"===b||"byte"===b)&&(d[a].terms.value_type=b),this)},format:function(b){return null==b?d[a].terms.format:(d[a].terms.format=b,this)},include:function(b,c){return null==d[a].terms.include&&(d[a].terms.include={}),null==b?d[a].terms.include:(d[a].terms.include.pattern=b,null!=c&&(d[a].terms.include.flags=c),this)},exclude:function(b,c){return null==d[a].terms.exclude&&(d[a].terms.exclude={}),null==b?d[a].terms.exclude:(d[a].terms.exclude.pattern=b,null!=c&&(d[a].terms.exclude.flags=c),this)},executionHint:function(b){return null==b?d[a].terms.execution_hint:(b=b.toLowerCase(),("map"===b||"ordinals"===b)&&(d[a].terms.execution_hint=b),this)},scriptValuesUnique:function(b){return null==b?d[a].terms.script_values_unique:(d[a].terms.script_values_unique=b,this)},size:function(b){return null==b?d[a].terms.size:(d[a].terms.size=b,this)},shardSize:function(b){return null==b?d[a].terms.shard_size:(d[a].terms.shard_size=b,this)},minDocCount:function(b){return null==b?d[a].terms.min_doc_count:(d[a].terms.min_doc_count=b,this)},params:function(b){return null==b?d[a].terms.params:(d[a].terms.params=b,this)},order:function(b,c){return null==b?d[a].terms.order:(null==c&&(c="desc"),c=c.toLowerCase(),"asc"!==c&&"desc"!==c&&(c="desc"),d[a].terms.order={},d[a].terms.order[b]=c,this)}})},A.TopHitsAggregation=function(b){var d=A.MetricsAggregationMixin(b,"top_hits"),f=d.toJSON();return f[b].top_hits={size:0,from:0},c(d,{from:function(a){return null==a?f[b].top_hits.from:(f[b].top_hits.from=a,this)},size:function(a){return null==a?f[b].top_hits.size:(f[b].top_hits.size=a,this)},sort:function(){var c,d,h=f[b].top_hits;if(a(h,"sort")||(h.sort=[]),0===arguments.length)return h.sort;if(1===arguments.length){var i=arguments[0];if(g(i))h.sort.push(i);else if(u(i))h.sort.push(i.toJSON());else{if(!e(i))throw new TypeError("Argument must be string, Sort, or array");for(h.sort=[],c=0,d=i.length;d>c;c++)if(g(i[c]))h.sort.push(i[c]);else{if(!u(i[c]))throw new TypeError("Invalid object in array");h.sort.push(i[c].toJSON())}}}else if(2===arguments.length){var j=arguments[0],k=arguments[1];if(g(j)&&g(k)&&(k=k.toLowerCase(),"asc"===k||"desc"===k)){var l={};l[j]={order:k},h.sort.push(l)}}return this},trackScores:function(a){return null==a?f[b].top_hits.track_scores:(f[b].top_hits.track_scores=a,this)},version:function(a){return null==a?f[b].top_hits.version:(f[b].top_hits.version=a,this)},explain:function(a){return null==a?f[b].top_hits.explain:(f[b].top_hits.explain=a,this)},highlight:function(a){if(null==a)return f[b].top_hits.highlight;if(!v(a))throw new TypeError("Argument must be a Highlight object");return f[b].top_hits.highlight=a.toJSON(),this},scriptField:function(a){if(null==a)return f[b].top_hits.script_fields;if(null==f[b].top_hits.script_fields&&(f[b].top_hits.script_fields={}),!q(a))throw new TypeError("Argument must be a ScriptField");return c(f[b].top_hits.script_fields,a.toJSON()),this},docValueFields:function(a){var c=f[b].top_hits;if(null==a)return c.docvalue_fields;if(null==c.docvalue_fields&&(c.docvalue_fields=[]),g(a))c.docvalue_fields.push(a);else{if(!e(a))throw new TypeError("Argument must be a string or an array");c.docvalue_fields=a}return this},source:function(a,c){var d=f[b].top_hits;if(null==a&&null==c)return d._source;if(!e(a)&&!g(a)&&!i(a))throw new TypeError("Argument includes must be a string, an array, or a boolean");if(null!=c&&!e(c)&&!g(c))throw new TypeError("Argument excludes must be a string or an array");return i(a)?d._source=a:(d._source={includes:a},null!=c&&(d._source.excludes=c)),this}})},A.ValueCountAggregation=function(a){var b=A.MetricsAggregationMixin(a,"value_count"),d=b.toJSON();return delete b.scriptValuesSorted,c(b,{scriptValuesUnique:function(b){return null==b?d[a].value_count.script_values_unique:(d[a].value_count.script_values_unique=b,this)}})},A.AndFilter=function(a){var b,d,f=A.FilterMixin("and"),g=f.toJSON();if(g.and.filters=[],n(a))g.and.filters.push(a.toJSON());else{if(!e(a))throw new TypeError("Argument must be a Filter or Array of Filters");for(b=0,d=a.length;d>b;b++){if(!n(a[b]))throw new TypeError("Array must contain only Filter objects"); +g.and.filters.push(a[b].toJSON())}}return c(f,{filters:function(a){var b,c;if(null==a)return g.and.filters;if(n(a))g.and.filters.push(a.toJSON());else{if(!e(a))throw new TypeError("Argument must be a Filter or an Array of Filters");for(g.and.filters=[],b=0,c=a.length;c>b;b++){if(!n(a[b]))throw new TypeError("Array must contain only Filter objects");g.and.filters.push(a[b].toJSON())}}return this}})},A.BoolFilter=function(){var a=A.FilterMixin("bool"),b=a.toJSON();return c(a,{must:function(a){var c,d;if(null==b.bool.must&&(b.bool.must=[]),null==a)return b.bool.must;if(n(a))b.bool.must.push(a.toJSON());else{if(!e(a))throw new TypeError("Argument must be a Filter or array of Filters");for(b.bool.must=[],c=0,d=a.length;d>c;c++){if(!n(a[c]))throw new TypeError("Argument must be an array of Filters");b.bool.must.push(a[c].toJSON())}}return this},mustNot:function(a){var c,d;if(null==b.bool.must_not&&(b.bool.must_not=[]),null==a)return b.bool.must_not;if(n(a))b.bool.must_not.push(a.toJSON());else{if(!e(a))throw new TypeError("Argument must be a Filter or array of Filters");for(b.bool.must_not=[],c=0,d=a.length;d>c;c++){if(!n(a[c]))throw new TypeError("Argument must be an array of Filters");b.bool.must_not.push(a[c].toJSON())}}return this},should:function(a){var c,d;if(null==b.bool.should&&(b.bool.should=[]),null==a)return b.bool.should;if(n(a))b.bool.should.push(a.toJSON());else{if(!e(a))throw new TypeError("Argument must be a Filter or array of Filters");for(b.bool.should=[],c=0,d=a.length;d>c;c++){if(!n(a[c]))throw new TypeError("Argument must be an array of Filters");b.bool.should.push(a[c].toJSON())}}return this}})},A.ExistsFilter=function(a){var b=A.FilterMixin("exists"),d=b.toJSON();return d.exists.field=a,c(b,{field:function(a){return null==a?d.exists.field:(d.exists.field=a,this)}})},A.GeoBboxFilter=function(a){var b=A.FilterMixin("geo_bounding_box"),d=b.toJSON();return d.geo_bounding_box[a]={},c(b,{field:function(b){var c=d.geo_bounding_box[a];return null==b?a:(delete d.geo_bounding_box[a],a=b,d.geo_bounding_box[b]=c,this)},topLeft:function(b){if(null==b)return d.geo_bounding_box[a].top_left;if(!r(b))throw new TypeError("Argument must be a GeoPoint");return d.geo_bounding_box[a].top_left=b.toJSON(),this},bottomRight:function(b){if(null==b)return d.geo_bounding_box[a].bottom_right;if(!r(b))throw new TypeError("Argument must be a GeoPoint");return d.geo_bounding_box[a].bottom_right=b.toJSON(),this},type:function(a){return null==a?d.geo_bounding_box.type:(a=a.toLowerCase(),("memory"===a||"indexed"===a)&&(d.geo_bounding_box.type=a),this)},normalize:function(a){return null==a?d.geo_bounding_box.normalize:(d.geo_bounding_box.normalize=a,this)}})},A.GeoDistanceFilter=function(a){var b=A.FilterMixin("geo_distance"),d=b.toJSON();return d.geo_distance[a]=[0,0],c(b,{field:function(b){var c=d.geo_distance[a];return null==b?a:(delete d.geo_distance[a],a=b,d.geo_distance[b]=c,this)},distance:function(a){if(null==a)return d.geo_distance.distance;if(!h(a)&&!g(a))throw new TypeError("Argument must be a numeric or string value");return d.geo_distance.distance=a+"",this},unit:function(a){return null==a?d.geo_distance.unit:(a=a.toLowerCase(),("mi"===a||"km"===a)&&(d.geo_distance.unit=a),this)},point:function(b){if(null==b)return d.geo_distance[a];if(!r(b))throw new TypeError("Argument must be a GeoPoint");return d.geo_distance[a]=b.toJSON(),this},distanceType:function(a){return null==a?d.geo_distance.distance_type:(a=a.toLowerCase(),("arc"===a||"plane"===a)&&(d.geo_distance.distance_type=a),this)},normalize:function(a){return null==a?d.geo_distance.normalize:(d.geo_distance.normalize=a,this)},optimizeBbox:function(a){return null==a?d.geo_distance.optimize_bbox:(a=a.toLowerCase(),("memory"===a||"indexed"===a||"none"===a)&&(d.geo_distance.optimize_bbox=a),this)}})},A.GeoDistanceRangeFilter=function(a){var b=A.FilterMixin("geo_distance_range"),d=b.toJSON();return d.geo_distance_range[a]=[0,0],c(b,{field:function(b){var c=d.geo_distance_range[a];return null==b?a:(delete d.geo_distance_range[a],a=b,d.geo_distance_range[b]=c,this)},from:function(a){if(null==a)return d.geo_distance_range.from;if(!h(a))throw new TypeError("Argument must be a numeric value");return d.geo_distance_range.from=a,this},to:function(a){if(null==a)return d.geo_distance_range.to;if(!h(a))throw new TypeError("Argument must be a numeric value");return d.geo_distance_range.to=a,this},includeLower:function(a){return null==a?d.geo_distance_range.include_lower:(d.geo_distance_range.include_lower=a,this)},includeUpper:function(a){return null==a?d.geo_distance_range.include_upper:(d.geo_distance_range.include_upper=a,this)},gt:function(a){if(null==a)return d.geo_distance_range.gt;if(!h(a))throw new TypeError("Argument must be a numeric value");return d.geo_distance_range.gt=a,this},gte:function(a){if(null==a)return d.geo_distance_range.gte;if(!h(a))throw new TypeError("Argument must be a numeric value");return d.geo_distance_range.gte=a,this},lt:function(a){if(null==a)return d.geo_distance_range.lt;if(!h(a))throw new TypeError("Argument must be a numeric value");return d.geo_distance_range.lt=a,this},lte:function(a){if(null==a)return d.geo_distance_range.lte;if(!h(a))throw new TypeError("Argument must be a numeric value");return d.geo_distance_range.lte=a,this},unit:function(a){return null==a?d.geo_distance_range.unit:(a=a.toLowerCase(),("mi"===a||"km"===a)&&(d.geo_distance_range.unit=a),this)},point:function(b){if(null==b)return d.geo_distance_range[a];if(!r(b))throw new TypeError("Argument must be a GeoPoint");return d.geo_distance_range[a]=b.toJSON(),this},distanceType:function(a){return null==a?d.geo_distance_range.distance_type:(a=a.toLowerCase(),("arc"===a||"plane"===a)&&(d.geo_distance_range.distance_type=a),this)},normalize:function(a){return null==a?d.geo_distance_range.normalize:(d.geo_distance_range.normalize=a,this)},optimizeBbox:function(a){return null==a?d.geo_distance_range.optimize_bbox:(a=a.toLowerCase(),("memory"===a||"indexed"===a||"none"===a)&&(d.geo_distance_range.optimize_bbox=a),this)}})},A.GeoPolygonFilter=function(a){var b=A.FilterMixin("geo_polygon"),d=b.toJSON();return d.geo_polygon[a]={points:[]},c(b,{field:function(b){var c=d.geo_polygon[a];return null==b?a:(delete d.geo_polygon[a],a=b,d.geo_polygon[b]=c,this)},points:function(b){var c,f;if(null==b)return d.geo_polygon[a].points;if(r(b))d.geo_polygon[a].points.push(b.toJSON());else{if(!e(b))throw new TypeError("Argument must be a GeoPoint or Array of GeoPoints");for(d.geo_polygon[a].points=[],c=0,f=b.length;f>c;c++){if(!r(b[c]))throw new TypeError("Argument must be Array of GeoPoints");d.geo_polygon[a].points.push(b[c].toJSON())}}return this},normalize:function(a){return null==a?d.geo_polygon.normalize:(d.geo_polygon.normalize=a,this)}})},A.GeoShapeFilter=function(a){var b=A.FilterMixin("geo_shape"),d=b.toJSON();return d.geo_shape[a]={},c(b,{field:function(b){var c=d.geo_shape[a];return null==b?a:(delete d.geo_shape[a],a=b,d.geo_shape[b]=c,this)},shape:function(b){return null==b?d.geo_shape[a].shape:(null!=d.geo_shape[a].indexed_shape&&delete d.geo_shape[a].indexed_shape,d.geo_shape[a].shape=b.toJSON(),this)},indexedShape:function(b){return null==b?d.geo_shape[a].indexed_shape:(null!=d.geo_shape[a].shape&&delete d.geo_shape[a].shape,d.geo_shape[a].indexed_shape=b.toJSON(),this)},relation:function(b){return null==b?d.geo_shape[a].relation:(b=b.toLowerCase(),("intersects"===b||"disjoint"===b||"within"===b)&&(d.geo_shape[a].relation=b),this)},strategy:function(b){return null==b?d.geo_shape[a].strategy:(b=b.toLowerCase(),("recursive"===b||"term"===b)&&(d.geo_shape[a].strategy=b),this)}})},A.HasChildFilter=function(a,b){var d=A.FilterMixin("has_child"),e=d.toJSON();if(l(a))e.has_child.query=a.toJSON();else if(n(a))e.has_child.filter=a.toJSON();else if(null!=a)throw new TypeError("Argument must be query or filter");return e.has_child.type=b,c(d,{query:function(a){if(null==a)return e.has_child.query;if(!l(a))throw new TypeError("Argument must be a Query object");return e.has_child.query=a.toJSON(),this},filter:function(a){if(null==a)return e.has_child.filter;if(!n(a))throw new TypeError("Argument must be a Filter object");return e.has_child.filter=a.toJSON(),this},type:function(a){return null==a?e.has_child.type:(e.has_child.type=a,this)},shortCircuitCutoff:function(a){return null==a?e.has_child.short_circuit_cutoff:(e.has_child.short_circuit_cutoff=a,this)},scope:function(a){return this}})},A.HasParentFilter=function(a,b){var d=A.FilterMixin("has_parent"),e=d.toJSON();if(l(a))e.has_parent.query=a.toJSON();else if(n(a))e.has_parent.filter=a.toJSON();else if(null!=a)throw new TypeError("Argument must be query or filter");return e.has_parent.parent_type=b,c(d,{query:function(a){if(null==a)return e.has_parent.query;if(!l(a))throw new TypeError("Argument must be a Query object");return e.has_parent.query=a.toJSON(),this},filter:function(a){if(null==a)return e.has_parent.filter;if(!n(a))throw new TypeError("Argument must be a Filter object");return e.has_parent.filter=a.toJSON(),this},parentType:function(a){return null==a?e.has_parent.parent_type:(e.has_parent.parent_type=a,this)},scope:function(a){return this}})},A.IdsFilter=function(a){var b=A.FilterMixin("ids"),d=b.toJSON();if(g(a))d.ids.values=[a];else{if(!e(a))throw new TypeError("Argument must be a string or an array");d.ids.values=a}return c(b,{values:function(a){if(null==a)return d.ids.values;if(g(a))d.ids.values.push(a);else{if(!e(a))throw new TypeError("Argument must be a string or an array");d.ids.values=a}return this},type:function(a){if(null==d.ids.type&&(d.ids.type=[]),null==a)return d.ids.type;if(g(a))d.ids.type.push(a);else{if(!e(a))throw new TypeError("Argument must be a string or an array");d.ids.type=a}return this}})},A.IndicesFilter=function(a,b){if(!n(a))throw new TypeError("Argument must be a Filter");var d=A.FilterMixin("indices"),f=d.toJSON();if(f.indices.filter=a.toJSON(),g(b))f.indices.indices=[b];else{if(!e(b))throw new TypeError("Argument must be a string or array");f.indices.indices=b}return c(d,{indices:function(a){if(null==a)return f.indices.indices;if(g(a))f.indices.indices.push(a);else{if(!e(a))throw new TypeError("Argument must be a string or array");f.indices.indices=a}return this},filter:function(a){if(null==a)return f.indices.filter;if(!n(a))throw new TypeError("Argument must be a Filter");return f.indices.filter=a.toJSON(),this},noMatchFilter:function(a){if(null==a)return f.indices.no_match_filter;if(g(a))a=a.toLowerCase(),("none"===a||"all"===a)&&(f.indices.no_match_filter=a);else{if(!n(a))throw new TypeError("Argument must be string or Filter");f.indices.no_match_filter=a.toJSON()}return this}})},A.LimitFilter=function(a){var b=A.FilterMixin("limit"),d=b.toJSON();return d.limit.value=a,c(b,{value:function(a){if(null==a)return d.limit.value;if(!h(a))throw new TypeError("Argument must be a numeric value");return d.limit.value=a,this}})},A.MatchAllFilter=function(){return A.FilterMixin("match_all")},A.MissingFilter=function(a){var b=A.FilterMixin("missing"),d=b.toJSON();return d.missing.field=a,c(b,{field:function(a){return null==a?d.missing.field:(d.missing.field=a,this)},existence:function(a){return null==a?d.missing.existence:(d.missing.existence=a,this)},nullValue:function(a){return null==a?d.missing.null_value:(d.missing.null_value=a,this)}})},A.NestedFilter=function(a){var b=A.FilterMixin("nested"),d=b.toJSON();return d.nested.path=a,c(b,{path:function(a){return null==a?d.nested.path:(d.nested.path=a,this)},query:function(a){if(null==a)return d.nested.query;if(!l(a))throw new TypeError("Argument must be a Query object");return d.nested.query=a.toJSON(),this},filter:function(a){if(null==a)return d.nested.filter;if(!n(a))throw new TypeError("Argument must be a Filter object");return d.nested.filter=a.toJSON(),this},boost:function(a){return null==a?d.nested.boost:(d.nested.boost=a,this)},join:function(a){return null==a?d.nested.join:(d.nested.join=a,this)},scope:function(a){return this}})},A.NotFilter=function(a){if(!n(a))throw new TypeError("Argument must be a Filter");var b=A.FilterMixin("not"),d=b.toJSON();return d.not=a.toJSON(),c(b,{filter:function(a){if(null==a)return d.not;if(!n(a))throw new TypeError("Argument must be a Filter");return d.not=a.toJSON(),this}})},A.NumericRangeFilter=function(a){var b=A.FilterMixin("numeric_range"),d=b.toJSON();return d.numeric_range[a]={},c(b,{field:function(b){var c=d.numeric_range[a];return null==b?a:(delete d.numeric_range[a],a=b,d.numeric_range[a]=c,this)},from:function(b){if(null==b)return d.numeric_range[a].from;if(!h(b))throw new TypeError("Argument must be a numeric value");return d.numeric_range[a].from=b,this},to:function(b){if(null==b)return d.numeric_range[a].to;if(!h(b))throw new TypeError("Argument must be a numeric value");return d.numeric_range[a].to=b,this},includeLower:function(b){return null==b?d.numeric_range[a].include_lower:(d.numeric_range[a].include_lower=b,this)},includeUpper:function(b){return null==b?d.numeric_range[a].include_upper:(d.numeric_range[a].include_upper=b,this)},gt:function(b){if(null==b)return d.numeric_range[a].gt;if(!h(b))throw new TypeError("Argument must be a numeric value");return d.numeric_range[a].gt=b,this},gte:function(b){if(null==b)return d.numeric_range[a].gte;if(!h(b))throw new TypeError("Argument must be a numeric value");return d.numeric_range[a].gte=b,this},lt:function(b){if(null==b)return d.numeric_range[a].lt;if(!h(b))throw new TypeError("Argument must be a numeric value");return d.numeric_range[a].lt=b,this},lte:function(b){if(null==b)return d.numeric_range[a].lte;if(!h(b))throw new TypeError("Argument must be a numeric value");return d.numeric_range[a].lte=b,this}})},A.OrFilter=function(a){var b,d,f=A.FilterMixin("or"),g=f.toJSON();if(g.or.filters=[],n(a))g.or.filters.push(a.toJSON());else{if(!e(a))throw new TypeError("Argument must be a Filter or array of Filters");for(b=0,d=a.length;d>b;b++){if(!n(a[b]))throw new TypeError("Argument must be array of Filters");g.or.filters.push(a[b].toJSON())}}return c(f,{filters:function(a){var b,c;if(null==a)return g.or.filters;if(n(a))g.or.filters.push(a.toJSON());else{if(!e(a))throw new TypeError("Argument must be a Filter or array of Filters");for(g.or.filters=[],b=0,c=a.length;c>b;b++){if(!n(a[b]))throw new TypeError("Argument must be an array of Filters");g.or.filters.push(a[b].toJSON())}}return this}})},A.PrefixFilter=function(a,b){var d=A.FilterMixin("prefix"),e=d.toJSON();return e.prefix[a]=b,c(d,{field:function(b){var c=e.prefix[a];return null==b?a:(delete e.prefix[a],a=b,e.prefix[a]=c,this)},prefix:function(b){return null==b?e.prefix[a]:(e.prefix[a]=b,this)}})},A.QueryFilter=function(a){if(!l(a))throw new TypeError("Argument must be a Query");var b=A.FilterMixin("fquery"),d=b.toJSON();return d.fquery.query=a.toJSON(),c(b,{query:function(a){if(null==a)return d.fquery.query;if(!l(a))throw new TypeError("Argument must be a Query");return d.fquery.query=a.toJSON(),this}})},A.RangeFilter=function(a){var b=A.FilterMixin("range"),d=b.toJSON();return d.range[a]={},c(b,{field:function(b){var c=d.range[a];return null==b?a:(delete d.range[a],a=b,d.range[b]=c,this)},from:function(b){return null==b?d.range[a].from:(d.range[a].from=b,this)},to:function(b){return null==b?d.range[a].to:(d.range[a].to=b,this)},includeLower:function(b){return null==b?d.range[a].include_lower:(d.range[a].include_lower=b,this)},includeUpper:function(b){return null==b?d.range[a].include_upper:(d.range[a].include_upper=b,this)},gt:function(b){return null==b?d.range[a].gt:(d.range[a].gt=b,this)},gte:function(b){return null==b?d.range[a].gte:(d.range[a].gte=b,this)},lt:function(b){return null==b?d.range[a].lt:(d.range[a].lt=b,this)},lte:function(b){return null==b?d.range[a].lte:(d.range[a].lte=b,this)}})},A.RegexpFilter=function(a,b){var d=A.FilterMixin("regexp"),e=d.toJSON();return e.regexp[a]={value:b},c(d,{field:function(b){var c=e.regexp[a];return null==b?a:(delete e.regexp[a],a=b,e.regexp[b]=c,this)},value:function(b){return null==b?e.regexp[a].value:(e.regexp[a].value=b,this)},flags:function(b){return null==b?e.regexp[a].flags:(e.regexp[a].flags=b,this)},flagsValue:function(b){return null==b?e.regexp[a].flags_value:(e.regexp[a].flags_value=b,this)}})},A.ScriptFilter=function(a){var b=A.FilterMixin("script"),d=b.toJSON();return d.script.script=a,c(b,{script:function(a){return null==a?d.script.script:(d.script.script=a,this)},params:function(a){return null==a?d.script.params:(d.script.params=a,this)},lang:function(a){return null==a?d.script.lang:(d.script.lang=a,this)}})},A.TermFilter=function(a,b){var d=A.FilterMixin("term"),e=d.toJSON();return e.term[a]=b,c(d,{field:function(b){var c=e.term[a];return null==b?a:(delete e.term[a],a=b,e.term[a]=c,this)},term:function(b){return null==b?e.term[a]:(e.term[a]=b,this)}})},A.TermsFilter=function(a,b){var d=A.FilterMixin("terms"),f=d.toJSON(),g=function(){e(f.terms[a])||(f.terms[a]=[])},h=function(){e(f.terms[a])&&(f.terms[a]={})};return e(b)?f.terms[a]=b:f.terms[a]=[b],c(d,{field:function(b){var c=f.terms[a];return null==b?a:(delete f.terms[a],a=b,f.terms[b]=c,this)},terms:function(b){return g(),null==b?f.terms[a]:(e(b)?f.terms[a]=b:f.terms[a].push(b),this)},index:function(b){return h(),null==b?f.terms[a].index:(f.terms[a].index=b,this)},type:function(b){return h(),null==b?f.terms[a].type:(f.terms[a].type=b,this)},id:function(b){return h(),null==b?f.terms[a].id:(f.terms[a].id=b,this)},path:function(b){return h(),null==b?f.terms[a].path:(f.terms[a].path=b,this)},routing:function(b){return h(),null==b?f.terms[a].routing:(f.terms[a].routing=b,this)},cacheLookup:function(b){return h(),null==b?f.terms[a].cache:(f.terms[a].cache=b,this)},execution:function(a){return null==a?f.terms.execution:(a=a.toLowerCase(),("plain"===a||"bool"===a||"bool_nocache"===a||"and"===a||"and_nocache"===a||"or"===a||"or_nocache"===a)&&(f.terms.execution=a),this)}})},A.TypeFilter=function(a){var b=A.FilterMixin("type"),d=b.toJSON();return d.type.value=a,c(b,{type:function(a){return null==a?d.type.value:(d.type.value=a,this)}})},A.BoolQuery=function(){var a=A.QueryMixin("bool"),b=a.toJSON();return c(a,{must:function(a){var c,d;if(null==b.bool.must&&(b.bool.must=[]),null==a)return b.bool.must;if(l(a))b.bool.must.push(a.toJSON());else{if(!e(a))throw new TypeError("Argument must be a Query or array of Queries");for(b.bool.must=[],c=0,d=a.length;d>c;c++){if(!l(a[c]))throw new TypeError("Argument must be an array of Queries");b.bool.must.push(a[c].toJSON())}}return this},mustNot:function(a){var c,d;if(null==b.bool.must_not&&(b.bool.must_not=[]),null==a)return b.bool.must_not;if(l(a))b.bool.must_not.push(a.toJSON());else{if(!e(a))throw new TypeError("Argument must be a Query or array of Queries");for(b.bool.must_not=[],c=0,d=a.length;d>c;c++){if(!l(a[c]))throw new TypeError("Argument must be an array of Queries");b.bool.must_not.push(a[c].toJSON())}}return this},should:function(a){var c,d;if(null==b.bool.should&&(b.bool.should=[]),null==a)return b.bool.should;if(l(a))b.bool.should.push(a.toJSON());else{if(!e(a))throw new TypeError("Argument must be a Query or array of Queries");for(b.bool.should=[],c=0,d=a.length;d>c;c++){if(!l(a[c]))throw new TypeError("Argument must be an array of Queries");b.bool.should.push(a[c].toJSON())}}return this},adjustPureNegative:function(a){return null==a?b.bool.adjust_pure_negative:(b.bool.adjust_pure_negative=a,this)},disableCoord:function(a){return null==a?b.bool.disable_coord:(b.bool.disable_coord=a,this)},minimumNumberShouldMatch:function(a){return null==a?b.bool.minimum_number_should_match:(b.bool.minimum_number_should_match=a,this)},filter:function(a){if(null==a)return b.bool.filter;if(!n(a))throw new TypeError("Argument must be a Filter");return b.bool.filter=a.toJSON(),this}})},A.BoostingQuery=function(a,b,d){if(!l(a)||!l(b))throw new TypeError("Arguments must be Queries");var e=A.QueryMixin("boosting"),f=e.toJSON();return f.boosting.positive=a.toJSON(),f.boosting.negative=b.toJSON(),f.boosting.negative_boost=d,c(e,{positive:function(a){if(null==a)return f.boosting.positive;if(!l(a))throw new TypeError("Argument must be a Query");return f.boosting.positive=a.toJSON(),this},negative:function(a){if(null==a)return f.boosting.negative;if(!l(a))throw new TypeError("Argument must be a Query");return f.boosting.negative=a.toJSON(),this},negativeBoost:function(a){return null==a?f.boosting.negative_boost:(f.boosting.negative_boost=a,this)}})},A.CommonTermsQuery=function(a,b){var d=A.QueryMixin("common"),e=d.toJSON();return null==a&&(a="no_field_set"),e.common[a]={},null!=b&&(e.common[a].query=b),c(d,{field:function(b){var c=e.common[a];return null==b?a:(delete e.common[a],a=b,e.common[b]=c,this)},query:function(b){return null==b?e.common[a].query:(e.common[a].query=b,this)},analyzer:function(b){return null==b?e.common[a].analyzer:(e.common[a].analyzer=b,this)},disableCoord:function(b){return null==b?e.common[a].disable_coord:(e.common[a].disable_coord=b,this)},cutoffFrequency:function(b){return null==b?e.common[a].cutoff_frequency:(e.common[a].cutoff_frequency=b,this)},highFreqOperator:function(b){return null==b?e.common[a].high_freq_operator:(b=b.toLowerCase(),("and"===b||"or"===b)&&(e.common[a].high_freq_operator=b),this)},lowFreqOperator:function(b){return null==b?e.common[a].low_freq_operator:(b=b.toLowerCase(),("and"===b||"or"===b)&&(e.common[a].low_freq_operator=b),this)},minimumShouldMatch:function(b){return null==b?e.common[a].minimum_should_match.low_freq:(null==e.common[a].minimum_should_match&&(e.common[a].minimum_should_match={}),e.common[a].minimum_should_match.low_freq=b,this)},minimumShouldMatchLowFreq:function(a){return this.minimumShouldMatch(a)},minimumShouldMatchHighFreq:function(b){return null==b?e.common[a].minimum_should_match.high_freq:(null==e.common[a].minimum_should_match&&(e.common[a].minimum_should_match={}),e.common[a].minimum_should_match.high_freq=b,this)},boost:function(b){return null==b?e.common[a].boost:(e.common[a].boost=b,this)}})},A.ConstantScoreQuery=function(){var a=A.QueryMixin("constant_score"),b=a.toJSON();return c(a,{query:function(a){if(null==a)return b.constant_score.query;if(!l(a))throw new TypeError("Argument must be a Query");return b.constant_score.query=a.toJSON(),this},filter:function(a){if(null==a)return b.constant_score.filter;if(!n(a))throw new TypeError("Argument must be a Filter");return b.constant_score.filter=a.toJSON(),this},cache:function(a){return null==a?b.constant_score._cache:(b.constant_score._cache=a,this)},cacheKey:function(a){return null==a?b.constant_score._cache_key:(b.constant_score._cache_key=a,this)}})},A.DisMaxQuery=function(){var a=A.QueryMixin("dis_max"),b=a.toJSON();return c(a,{queries:function(a){var c,d;if(null==a)return b.dis_max.queries;if(null==b.dis_max.queries&&(b.dis_max.queries=[]),l(a))b.dis_max.queries.push(a.toJSON());else{if(!e(a))throw new TypeError("Argument must be a Query or array of Queries");for(b.dis_max.queries=[],c=0,d=a.length;d>c;c++){if(!l(a[c]))throw new TypeError("Argument must be array of Queries");b.dis_max.queries.push(a[c].toJSON())}}return this},tieBreaker:function(a){return null==a?b.dis_max.tie_breaker:(b.dis_max.tie_breaker=a,this)}})},A.FieldMaskingSpanQuery=function(a,b){if(!l(a))throw new TypeError("Argument must be a SpanQuery");var d=A.QueryMixin("field_masking_span"),e=d.toJSON();return e.field_masking_span.query=a.toJSON(),e.field_masking_span.field=b,c(d,{query:function(a){if(null==a)return e.field_masking_span.query;if(!l(a))throw new TypeError("Argument must be a SpanQuery");return e.field_masking_span.query=a.toJSON(),this},field:function(a){return null==a?e.field_masking_span.field:(e.field_masking_span.field=a,this)}})},A.FilteredQuery=function(a,b){if(!l(a))throw new TypeError("Argument must be a Query");if(null!=b&&!n(b))throw new TypeError("Argument must be a Filter");var d=A.QueryMixin("filtered"),e=d.toJSON();return e.filtered.query=a.toJSON(),null!=b&&(e.filtered.filter=b.toJSON()),c(d,{query:function(a){if(null==a)return e.filtered.query;if(!l(a))throw new TypeError("Argument must be a Query");return e.filtered.query=a.toJSON(),this},filter:function(a){if(null==a)return e.filtered.filter;if(!n(a))throw new TypeError("Argument must be a Filter");return e.filtered.filter=a.toJSON(),this},strategy:function(a){return null==a?e.filtered.strategy:(a=a.toLowerCase(),("query_first"===a||"random_access_always"===a||"leap_frog"===a||"leap_frog_filter_first"===a||0===a.indexOf("random_access_"))&&(e.filtered.strategy=a),this)},cache:function(a){return null==a?e.filtered._cache:(e.filtered._cache=a,this)},cacheKey:function(a){return null==a?e.filtered._cache_key:(e.filtered._cache_key=a,this)}})},A.FunctionScoreQuery=function(){var a=A.QueryMixin("function_score"),b=a.toJSON();return c(a,{query:function(a){if(null==a)return b.function_score.query;if(!l(a))throw new TypeError("Argument must be a Query");return b.function_score.query=a.toJSON(),this},filter:function(a){if(null==a)return b.function_score.filter;if(!n(a))throw new TypeError("Argument must be a Filter");return b.function_score.filter=a.toJSON(),this},scoreMode:function(a){return null==a?b.function_score.score_mode:(a=a.toLowerCase(),("avg"===a||"max"===a||"min"===a||"sum"===a||"multiply"===a||"first"===a)&&(b.function_score.score_mode=a),this)},boostMode:function(a){return null==a?b.function_score.boost_mode:(a=a.toLowerCase(),("multiply"===a||"replace"===a||"sum"===a||"avg"===a||"max"===a||"min"===a)&&(b.function_score.boost_mode=a),this)},boost:function(a){return null==a?b.function_score.boost:(b.function_score.boost=a,this)},"function":function(a){if(null==b.function_score.functions&&(b.function_score.functions=[]),null==a)return b.function_score.functions;if(!y(a))throw new TypeError("Argument must be a ScoreFunction");return b.function_score.functions.push(a.toJSON()),this},functions:function(a){var c,d;if(null==a)return b.function_score.functions;if(!e(a))throw new TypeError("Argument must be an array of ScoreFunctions");for(b.function_score.functions=[],c=0,d=a.length;d>c;c++){if(!y(a[c]))throw new TypeError("Argument must be an array of ScoreFunctions");b.function_score.functions.push(a[c].toJSON())}return this}})},A.FuzzyLikeThisFieldQuery=function(a,b){var d=A.QueryMixin("flt_field"),e=d.toJSON();return e.flt_field[a]={like_text:b},c(d,{field:function(b){var c=e.flt_field[a];return null==b?a:(delete e.flt_field[a],a=b,e.flt_field[b]=c,this)},likeText:function(b){return null==b?e.flt_field[a].like_text:(e.flt_field[a].like_text=b,this)},ignoreTf:function(b){return null==b?e.flt_field[a].ignore_tf:(e.flt_field[a].ignore_tf=b,this)},maxQueryTerms:function(b){return null==b?e.flt_field[a].max_query_terms:(e.flt_field[a].max_query_terms=b,this)},minSimilarity:function(b){return null==b?e.flt_field[a].min_similarity:(e.flt_field[a].min_similarity=b,this)},prefixLength:function(b){return null==b?e.flt_field[a].prefix_length:(e.flt_field[a].prefix_length=b,this)},analyzer:function(b){return null==b?e.flt_field[a].analyzer:(e.flt_field[a].analyzer=b,this)},failOnUnsupportedField:function(b){return null==b?e.flt_field[a].fail_on_unsupported_field:(e.flt_field[a].fail_on_unsupported_field=b,this)},boost:function(b){return null==b?e.flt_field[a].boost:(e.flt_field[a].boost=b,this)}})},A.FuzzyLikeThisQuery=function(a){var b=A.QueryMixin("flt"),d=b.toJSON();return d.flt.like_text=a,c(b,{fields:function(a){if(null==d.flt.fields&&(d.flt.fields=[]),null==a)return d.flt.fields;if(g(a))d.flt.fields.push(a);else{if(!e(a))throw new TypeError("Argument must be a string or array");d.flt.fields=a}return this},likeText:function(a){return null==a?d.flt.like_text:(d.flt.like_text=a,this)},ignoreTf:function(a){return null==a?d.flt.ignore_tf:(d.flt.ignore_tf=a,this)},maxQueryTerms:function(a){return null==a?d.flt.max_query_terms:(d.flt.max_query_terms=a,this)},minSimilarity:function(a){return null==a?d.flt.min_similarity:(d.flt.min_similarity=a,this)},prefixLength:function(a){return null==a?d.flt.prefix_length:(d.flt.prefix_length=a,this)},analyzer:function(a){return null==a?d.flt.analyzer:(d.flt.analyzer=a,this)},failOnUnsupportedField:function(a){return null==a?d.flt.fail_on_unsupported_field:(d.flt.fail_on_unsupported_field=a,this)}})},A.FuzzyQuery=function(a,b){var d=A.QueryMixin("fuzzy"),e=d.toJSON();return e.fuzzy[a]={value:b},c(d,{field:function(b){var c=e.fuzzy[a];return null==b?a:(delete e.fuzzy[a],a=b,e.fuzzy[b]=c,this)},value:function(b){return null==b?e.fuzzy[a].value:(e.fuzzy[a].value=b,this)},transpositions:function(b){return null==b?e.fuzzy[a].transpositions:(e.fuzzy[a].transpositions=b,this)},maxExpansions:function(b){return null==b?e.fuzzy[a].max_expansions:(e.fuzzy[a].max_expansions=b,this)},minSimilarity:function(b){return null==b?e.fuzzy[a].min_similarity:(e.fuzzy[a].min_similarity=b,this)},prefixLength:function(b){return null==b?e.fuzzy[a].prefix_length:(e.fuzzy[a].prefix_length=b,this)},rewrite:function(b){return null==b?e.fuzzy[a].rewrite:(b=b.toLowerCase(),("constant_score_auto"===b||"scoring_boolean"===b||"constant_score_boolean"===b||"constant_score_filter"===b||0===b.indexOf("top_terms_boost_")||0===b.indexOf("top_terms_"))&&(e.fuzzy[a].rewrite=b),this)},boost:function(b){return null==b?e.fuzzy[a].boost:(e.fuzzy[a].boost=b,this)}})},A.GeoShapeQuery=function(a){var b=A.QueryMixin("geo_shape"),d=b.toJSON();return d.geo_shape[a]={},c(b,{field:function(b){var c=d.geo_shape[a];return null==b?a:(delete d.geo_shape[a],a=b,d.geo_shape[b]=c,this)},shape:function(b){return null==b?d.geo_shape[a].shape:(null!=d.geo_shape[a].indexed_shape&&delete d.geo_shape[a].indexed_shape,d.geo_shape[a].shape=b.toJSON(),this)},indexedShape:function(b){return null==b?d.geo_shape[a].indexed_shape:(null!=d.geo_shape[a].shape&&delete d.geo_shape[a].shape,d.geo_shape[a].indexed_shape=b.toJSON(),this)},relation:function(b){return null==b?d.geo_shape[a].relation:(b=b.toLowerCase(),("intersects"===b||"disjoint"===b||"within"===b)&&(d.geo_shape[a].relation=b),this)},strategy:function(b){return null==b?d.geo_shape[a].strategy:(b=b.toLowerCase(),("recursive"===b||"term"===b)&&(d.geo_shape[a].strategy=b),this)},boost:function(b){return null==b?d.geo_shape[a].boost:(d.geo_shape[a].boost=b,this)}})},A.HasChildQuery=function(a,b){if(!l(a))throw new TypeError("Argument must be a valid Query");var d=A.QueryMixin("has_child"),e=d.toJSON();return e.has_child.query=a.toJSON(),e.has_child.type=b,c(d,{query:function(a){if(null==a)return e.has_child.query;if(!l(a))throw new TypeError("Argument must be a valid Query");return e.has_child.query=a.toJSON(),this},type:function(a){return null==a?e.has_child.type:(e.has_child.type=a,this)},scope:function(a){return this},scoreType:function(a){return null==a?e.has_child.score_type:(a=a.toLowerCase(),("none"===a||"max"===a||"sum"===a||"avg"===a)&&(e.has_child.score_type=a),this)},scoreMode:function(a){return null==a?e.has_child.score_mode:(a=a.toLowerCase(),("none"===a||"max"===a||"sum"===a||"avg"===a)&&(e.has_child.score_mode=a),this)},shortCircuitCutoff:function(a){return null==a?e.has_child.short_circuit_cutoff:(e.has_child.short_circuit_cutoff=a,this)}})},A.HasParentQuery=function(a,b){if(!l(a))throw new TypeError("Argument must be a Query");var d=A.QueryMixin("has_parent"),e=d.toJSON();return e.has_parent.query=a.toJSON(),e.has_parent.parent_type=b,c(d,{query:function(a){if(null==a)return e.has_parent.query;if(!l(a))throw new TypeError("Argument must be a Query");return e.has_parent.query=a.toJSON(),this},parentType:function(a){return null==a?e.has_parent.parent_type:(e.has_parent.parent_type=a,this)},scope:function(a){return this},scoreType:function(a){return null==a?e.has_parent.score_type:(a=a.toLowerCase(),("none"===a||"score"===a)&&(e.has_parent.score_type=a),this)},scoreMode:function(a){return null==a?e.has_parent.score_mode:(a=a.toLowerCase(),("none"===a||"score"===a)&&(e.has_parent.score_mode=a),this)}})},A.IdsQuery=function(a){var b=A.QueryMixin("ids"),d=b.toJSON(); +if(g(a))d.ids.values=[a];else{if(!e(a))throw new TypeError("Argument must be string or array");d.ids.values=a}return c(b,{values:function(a){if(null==a)return d.ids.values;if(g(a))d.ids.values.push(a);else{if(!e(a))throw new TypeError("Argument must be string or array");d.ids.values=a}return this},type:function(a){if(null==d.ids.type&&(d.ids.type=[]),null==a)return d.ids.type;if(g(a))d.ids.type.push(a);else{if(!e(a))throw new TypeError("Argument must be string or array");d.ids.type=a}return this}})},A.IndicesQuery=function(a,b){if(!l(a))throw new TypeError("Argument must be a Query");var d=A.QueryMixin("indices"),f=d.toJSON();if(f.indices.query=a.toJSON(),g(b))f.indices.indices=[b];else{if(!e(b))throw new TypeError("Argument must be a string or array");f.indices.indices=b}return c(d,{indices:function(a){if(null==a)return f.indices.indices;if(g(a))f.indices.indices.push(a);else{if(!e(a))throw new TypeError("Argument must be a string or array");f.indices.indices=a}return this},query:function(a){if(null==a)return f.indices.query;if(!l(a))throw new TypeError("Argument must be a Query");return f.indices.query=a.toJSON(),this},noMatchQuery:function(a){if(null==a)return f.indices.no_match_query;if(g(a))a=a.toLowerCase(),("none"===a||"all"===a)&&(f.indices.no_match_query=a);else{if(!l(a))throw new TypeError("Argument must be string or Query");f.indices.no_match_query=a.toJSON()}return this}})},A.MatchAllQuery=function(){return A.QueryMixin("match_all")},A.MatchQuery=function(a,b){var d=A.QueryMixin("match"),e=d.toJSON();return e.match[a]={query:b},c(d,{query:function(b){return null==b?e.match[a].query:(e.match[a].query=b,this)},type:function(b){return null==b?e.match[a].type:(b=b.toLowerCase(),("boolean"===b||"phrase"===b||"phrase_prefix"===b)&&(e.match[a].type=b),this)},fuzziness:function(b){return null==b?e.match[a].fuzziness:(e.match[a].fuzziness=b,this)},cutoffFrequency:function(b){return null==b?e.match[a].cutoff_frequency:(e.match[a].cutoff_frequency=b,this)},prefixLength:function(b){return null==b?e.match[a].prefix_length:(e.match[a].prefix_length=b,this)},maxExpansions:function(b){return null==b?e.match[a].max_expansions:(e.match[a].max_expansions=b,this)},operator:function(b){return null==b?e.match[a].operator:(b=b.toLowerCase(),("and"===b||"or"===b)&&(e.match[a].operator=b),this)},slop:function(b){return null==b?e.match[a].slop:(e.match[a].slop=b,this)},analyzer:function(b){return null==b?e.match[a].analyzer:(e.match[a].analyzer=b,this)},minimumShouldMatch:function(b){return null==b?e.match[a].minimum_should_match:(e.match[a].minimum_should_match=b,this)},rewrite:function(b){return null==b?e.match[a].rewrite:(b=b.toLowerCase(),("constant_score_auto"===b||"scoring_boolean"===b||"constant_score_boolean"===b||"constant_score_filter"===b||0===b.indexOf("top_terms_boost_")||0===b.indexOf("top_terms_"))&&(e.match[a].rewrite=b),this)},fuzzyRewrite:function(b){return null==b?e.match[a].fuzzy_rewrite:(b=b.toLowerCase(),("constant_score_auto"===b||"scoring_boolean"===b||"constant_score_boolean"===b||"constant_score_filter"===b||0===b.indexOf("top_terms_boost_")||0===b.indexOf("top_terms_"))&&(e.match[a].fuzzy_rewrite=b),this)},fuzzyTranspositions:function(b){return null==b?e.match[a].fuzzy_transpositions:(e.match[a].fuzzy_transpositions=b,this)},lenient:function(b){return null==b?e.match[a].lenient:(e.match[a].lenient=b,this)},zeroTermsQuery:function(b){return null==b?e.match[a].zero_terms_query:(b=b.toLowerCase(),("all"===b||"none"===b)&&(e.match[a].zero_terms_query=b),this)},boost:function(b){return null==b?e.match[a].boost:(e.match[a].boost=b,this)}})},A.MoreLikeThisFieldQuery=function(a,b){var d=A.QueryMixin("mlt_field"),e=d.toJSON();return e.mlt_field[a]={like_text:b},c(d,{field:function(b){var c=e.mlt_field[a];return null==b?a:(delete e.mlt_field[a],a=b,e.mlt_field[b]=c,this)},likeText:function(b){return null==b?e.mlt_field[a].like_text:(e.mlt_field[a].like_text=b,this)},percentTermsToMatch:function(b){return null==b?e.mlt_field[a].percent_terms_to_match:(e.mlt_field[a].percent_terms_to_match=b,this)},minTermFreq:function(b){return null==b?e.mlt_field[a].min_term_freq:(e.mlt_field[a].min_term_freq=b,this)},maxQueryTerms:function(b){return null==b?e.mlt_field[a].max_query_terms:(e.mlt_field[a].max_query_terms=b,this)},stopWords:function(b){return null==b?e.mlt_field[a].stop_words:(e.mlt_field[a].stop_words=b,this)},minDocFreq:function(b){return null==b?e.mlt_field[a].min_doc_freq:(e.mlt_field[a].min_doc_freq=b,this)},maxDocFreq:function(b){return null==b?e.mlt_field[a].max_doc_freq:(e.mlt_field[a].max_doc_freq=b,this)},minWordLen:function(b){return null==b?e.mlt_field[a].min_word_len:(e.mlt_field[a].min_word_len=b,this)},maxWordLen:function(b){return null==b?e.mlt_field[a].max_word_len:(e.mlt_field[a].max_word_len=b,this)},analyzer:function(b){return null==b?e.mlt_field[a].analyzer:(e.mlt_field[a].analyzer=b,this)},boostTerms:function(b){return null==b?e.mlt_field[a].boost_terms:(e.mlt_field[a].boost_terms=b,this)},failOnUnsupportedField:function(b){return null==b?e.mlt_field[a].fail_on_unsupported_field:(e.mlt_field[a].fail_on_unsupported_field=b,this)},boost:function(b){return null==b?e.mlt_field[a].boost:(e.mlt_field[a].boost=b,this)}})},A.MoreLikeThisQuery=function(a,b){var d=A.QueryMixin("mlt"),f=d.toJSON();if(f.mlt.like_text=b,f.mlt.fields=[],g(a))f.mlt.fields.push(a);else{if(!e(a))throw new TypeError("Argument must be string or array");f.mlt.fields=a}return c(d,{fields:function(a){if(null==a)return f.mlt.fields;if(g(a))f.mlt.fields.push(a);else{if(!e(a))throw new TypeError("Argument must be a string or array");f.mlt.fields=a}return this},likeText:function(a){return null==a?f.mlt.like_text:(f.mlt.like_text=a,this)},percentTermsToMatch:function(a){return null==a?f.mlt.percent_terms_to_match:(f.mlt.percent_terms_to_match=a,this)},minTermFreq:function(a){return null==a?f.mlt.min_term_freq:(f.mlt.min_term_freq=a,this)},maxQueryTerms:function(a){return null==a?f.mlt.max_query_terms:(f.mlt.max_query_terms=a,this)},stopWords:function(a){return null==a?f.mlt.stop_words:(f.mlt.stop_words=a,this)},minDocFreq:function(a){return null==a?f.mlt.min_doc_freq:(f.mlt.min_doc_freq=a,this)},maxDocFreq:function(a){return null==a?f.mlt.max_doc_freq:(f.mlt.max_doc_freq=a,this)},minWordLen:function(a){return null==a?f.mlt.min_word_len:(f.mlt.min_word_len=a,this)},maxWordLen:function(a){return null==a?f.mlt.max_word_len:(f.mlt.max_word_len=a,this)},analyzer:function(a){return null==a?f.mlt.analyzer:(f.mlt.analyzer=a,this)},boostTerms:function(a){return null==a?f.mlt.boost_terms:(f.mlt.boost_terms=a,this)},failOnUnsupportedField:function(a){return null==a?f.mlt.fail_on_unsupported_field:(f.mlt.fail_on_unsupported_field=a,this)}})},A.MultiMatchQuery=function(a,b){var d=A.QueryMixin("multi_match"),f=d.toJSON();if(f.multi_match.query=b,f.multi_match.fields=[],g(a))f.multi_match.fields.push(a);else{if(!e(a))throw new TypeError("Argument must be string or array");f.multi_match.fields=a}return c(d,{fields:function(a){if(null==a)return f.multi_match.fields;if(g(a))f.multi_match.fields.push(a);else{if(!e(a))throw new TypeError("Argument must be string or array");f.multi_match.fields=a}return this},useDisMax:function(a){return null==a?f.multi_match.use_dis_max:(f.multi_match.use_dis_max=a,this)},tieBreaker:function(a){return null==a?f.multi_match.tie_breaker:(f.multi_match.tie_breaker=a,this)},cutoffFrequency:function(a){return null==a?f.multi_match.cutoff_frequency:(f.multi_match.cutoff_frequency=a,this)},minimumShouldMatch:function(a){return null==a?f.multi_match.minimum_should_match:(f.multi_match.minimum_should_match=a,this)},rewrite:function(a){return null==a?f.multi_match.rewrite:(a=a.toLowerCase(),("constant_score_auto"===a||"scoring_boolean"===a||"constant_score_boolean"===a||"constant_score_filter"===a||0===a.indexOf("top_terms_boost_")||0===a.indexOf("top_terms_"))&&(f.multi_match.rewrite=a),this)},fuzzyRewrite:function(a){return null==a?f.multi_match.fuzzy_rewrite:(a=a.toLowerCase(),("constant_score_auto"===a||"scoring_boolean"===a||"constant_score_boolean"===a||"constant_score_filter"===a||0===a.indexOf("top_terms_boost_")||0===a.indexOf("top_terms_"))&&(f.multi_match.fuzzy_rewrite=a),this)},lenient:function(a){return null==a?f.multi_match.lenient:(f.multi_match.lenient=a,this)},query:function(a){return null==a?f.multi_match.query:(f.multi_match.query=a,this)},type:function(a){return null==a?f.multi_match.type:(a=a.toLowerCase(),("boolean"===a||"phrase"===a||"phrase_prefix"===a)&&(f.multi_match.type=a),this)},fuzziness:function(a){return null==a?f.multi_match.fuzziness:(f.multi_match.fuzziness=a,this)},prefixLength:function(a){return null==a?f.multi_match.prefix_length:(f.multi_match.prefix_length=a,this)},maxExpansions:function(a){return null==a?f.multi_match.max_expansions:(f.multi_match.max_expansions=a,this)},operator:function(a){return null==a?f.multi_match.operator:(a=a.toLowerCase(),("and"===a||"or"===a)&&(f.multi_match.operator=a),this)},slop:function(a){return null==a?f.multi_match.slop:(f.multi_match.slop=a,this)},analyzer:function(a){return null==a?f.multi_match.analyzer:(f.multi_match.analyzer=a,this)},zeroTermsQuery:function(a){return null==a?f.multi_match.zero_terms_query:(a=a.toLowerCase(),("all"===a||"none"===a)&&(f.multi_match.zero_terms_query=a),this)}})},A.NestedQuery=function(a){var b=A.QueryMixin("nested"),d=b.toJSON();return d.nested.path=a,c(b,{path:function(a){return null==a?d.nested.path:(d.nested.path=a,this)},query:function(a){if(null==a)return d.nested.query;if(!l(a))throw new TypeError("Argument must be a Query");return d.nested.query=a.toJSON(),this},filter:function(a){if(null==a)return d.nested.filter;if(!n(a))throw new TypeError("Argument must be a Filter");return d.nested.filter=a.toJSON(),this},scoreMode:function(a){return null==a?d.nested.score_mode:(a=a.toLowerCase(),("avg"===a||"total"===a||"max"===a||"none"===a||"sum"===a)&&(d.nested.score_mode=a),this)},scope:function(a){return this}})},A.PrefixQuery=function(a,b){var d=A.QueryMixin("prefix"),e=d.toJSON();return e.prefix[a]={value:b},c(d,{field:function(b){var c=e.prefix[a];return null==b?a:(delete e.prefix[a],a=b,e.prefix[b]=c,this)},value:function(b){return null==b?e.prefix[a].value:(e.prefix[a].value=b,this)},rewrite:function(b){return null==b?e.prefix[a].rewrite:(b=b.toLowerCase(),("constant_score_auto"===b||"scoring_boolean"===b||"constant_score_boolean"===b||"constant_score_filter"===b||0===b.indexOf("top_terms_boost_")||0===b.indexOf("top_terms_"))&&(e.prefix[a].rewrite=b),this)},boost:function(b){return null==b?e.prefix[a].boost:(e.prefix[a].boost=b,this)}})},A.QueryStringQuery=function(a){var b=A.QueryMixin("query_string"),d=b.toJSON();return d.query_string.query=a,c(b,{query:function(a){return null==a?d.query_string.query:(d.query_string.query=a,this)},defaultField:function(a){return null==a?d.query_string.default_field:(d.query_string.default_field=a,this)},fields:function(a){if(null==d.query_string.fields&&(d.query_string.fields=[]),null==a)return d.query_string.fields;if(g(a))d.query_string.fields.push(a);else{if(!e(a))throw new TypeError("Argument must be a string or array");d.query_string.fields=a}return this},useDisMax:function(a){return null==a?d.query_string.use_dis_max:(d.query_string.use_dis_max=a,this)},defaultOperator:function(a){return null==a?d.query_string.default_operator:(a=a.toUpperCase(),("AND"===a||"OR"===a)&&(d.query_string.default_operator=a),this)},analyzer:function(a){return null==a?d.query_string.analyzer:(d.query_string.analyzer=a,this)},quoteAnalyzer:function(a){return null==a?d.query_string.quote_analyzer:(d.query_string.quote_analyzer=a,this)},allowLeadingWildcard:function(a){return null==a?d.query_string.allow_leading_wildcard:(d.query_string.allow_leading_wildcard=a,this)},lowercaseExpandedTerms:function(a){return null==a?d.query_string.lowercase_expanded_terms:(d.query_string.lowercase_expanded_terms=a,this)},enablePositionIncrements:function(a){return null==a?d.query_string.enable_position_increments:(d.query_string.enable_position_increments=a,this)},fuzzyPrefixLength:function(a){return null==a?d.query_string.fuzzy_prefix_length:(d.query_string.fuzzy_prefix_length=a,this)},fuzzyMinSim:function(a){return null==a?d.query_string.fuzzy_min_sim:(d.query_string.fuzzy_min_sim=a,this)},phraseSlop:function(a){return null==a?d.query_string.phrase_slop:(d.query_string.phrase_slop=a,this)},analyzeWildcard:function(a){return null==a?d.query_string.analyze_wildcard:(d.query_string.analyze_wildcard=a,this)},autoGeneratePhraseQueries:function(a){return null==a?d.query_string.auto_generate_phrase_queries:(d.query_string.auto_generate_phrase_queries=a,this)},minimumShouldMatch:function(a){return null==a?d.query_string.minimum_should_match:(d.query_string.minimum_should_match=a,this)},tieBreaker:function(a){return null==a?d.query_string.tie_breaker:(d.query_string.tie_breaker=a,this)},escape:function(a){return null==a?d.query_string.escape:(d.query_string.escape=a,this)},fuzzyMaxExpansions:function(a){return null==a?d.query_string.fuzzy_max_expansions:(d.query_string.fuzzy_max_expansions=a,this)},fuzzyRewrite:function(a){return null==a?d.query_string.fuzzy_rewrite:(a=a.toLowerCase(),("constant_score_auto"===a||"scoring_boolean"===a||"constant_score_boolean"===a||"constant_score_filter"===a||0===a.indexOf("top_terms_boost_")||0===a.indexOf("top_terms_"))&&(d.query_string.fuzzy_rewrite=a),this)},rewrite:function(a){return null==a?d.query_string.rewrite:(a=a.toLowerCase(),("constant_score_auto"===a||"scoring_boolean"===a||"constant_score_boolean"===a||"constant_score_filter"===a||0===a.indexOf("top_terms_boost_")||0===a.indexOf("top_terms_"))&&(d.query_string.rewrite=a),this)},quoteFieldSuffix:function(a){return null==a?d.query_string.quote_field_suffix:(d.query_string.quote_field_suffix=a,this)},lenient:function(a){return null==a?d.query_string.lenient:(d.query_string.lenient=a,this)}})},A.RangeQuery=function(a){var b=A.QueryMixin("range"),d=b.toJSON();return d.range[a]={},c(b,{field:function(b){var c=d.range[a];return null==b?a:(delete d.range[a],a=b,d.range[b]=c,this)},from:function(b){return null==b?d.range[a].from:(d.range[a].from=b,this)},to:function(b){return null==b?d.range[a].to:(d.range[a].to=b,this)},includeLower:function(b){return null==b?d.range[a].include_lower:(d.range[a].include_lower=b,this)},includeUpper:function(b){return null==b?d.range[a].include_upper:(d.range[a].include_upper=b,this)},gt:function(b){return null==b?d.range[a].gt:(d.range[a].gt=b,this)},gte:function(b){return null==b?d.range[a].gte:(d.range[a].gte=b,this)},lt:function(b){return null==b?d.range[a].lt:(d.range[a].lt=b,this)},lte:function(b){return null==b?d.range[a].lte:(d.range[a].lte=b,this)},boost:function(b){return null==b?d.range[a].boost:(d.range[a].boost=b,this)}})},A.RegexpQuery=function(a,b){var d=A.QueryMixin("regexp"),e=d.toJSON();return e.regexp[a]={value:b},c(d,{field:function(b){var c=e.regexp[a];return null==b?a:(delete e.regexp[a],a=b,e.regexp[b]=c,this)},value:function(b){return null==b?e.regexp[a].value:(e.regexp[a].value=b,this)},flags:function(b){return null==b?e.regexp[a].flags:(e.regexp[a].flags=b,this)},flagsValue:function(b){return null==b?e.regexp[a].flags_value:(e.regexp[a].flags_value=b,this)},rewrite:function(b){return null==b?e.regexp[a].rewrite:(b=b.toLowerCase(),("constant_score_auto"===b||"scoring_boolean"===b||"constant_score_boolean"===b||"constant_score_filter"===b||0===b.indexOf("top_terms_boost_")||0===b.indexOf("top_terms_"))&&(e.regexp[a].rewrite=b),this)},boost:function(b){return null==b?e.regexp[a].boost:(e.regexp[a].boost=b,this)}})},A.SpanFirstQuery=function(a,b){if(!l(a))throw new TypeError("Argument must be a SpanQuery");var d=A.QueryMixin("span_first"),e=d.toJSON();return e.span_first.match=a.toJSON(),e.span_first.end=b,c(d,{match:function(a){if(null==a)return e.span_first.match;if(!l(a))throw new TypeError("Argument must be a SpanQuery");return e.span_first.match=a.toJSON(),this},end:function(a){return null==a?e.span_first.end:(e.span_first.end=a,this)}})},A.SpanMultiTermQuery=function(a){if(null!=a&&!l(a))throw new TypeError("Argument must be a MultiTermQuery");var b=A.QueryMixin("span_multi"),d=b.toJSON();return d.span_multi.match={},null!=a&&(d.span_multi.match=a.toJSON()),c(b,{match:function(a){if(null==a)return d.span_multi.match;if(!l(a))throw new TypeError("Argument must be a MultiTermQuery");return d.span_multi.match=a.toJSON(),this}})},A.SpanNearQuery=function(a,b){var d,f,g=A.QueryMixin("span_near"),h=g.toJSON();if(h.span_near.clauses=[],h.span_near.slop=b,l(a))h.span_near.clauses.push(a.toJSON());else{if(!e(a))throw new TypeError("Argument must be SpanQuery or array of SpanQueries");for(d=0,f=a.length;f>d;d++){if(!l(a[d]))throw new TypeError("Argument must be array of SpanQueries");h.span_near.clauses.push(a[d].toJSON())}}return c(g,{clauses:function(a){var b,c;if(null==a)return h.span_near.clauses;if(l(a))h.span_near.clauses.push(a.toJSON());else{if(!e(a))throw new TypeError("Argument must be SpanQuery or array of SpanQueries");for(h.span_near.clauses=[],b=0,c=a.length;c>b;b++){if(!l(a[b]))throw new TypeError("Argument must be array of SpanQueries");h.span_near.clauses.push(a[b].toJSON())}}return this},slop:function(a){return null==a?h.span_near.slop:(h.span_near.slop=a,this)},inOrder:function(a){return null==a?h.span_near.in_order:(h.span_near.in_order=a,this)},collectPayloads:function(a){return null==a?h.span_near.collect_payloads:(h.span_near.collect_payloads=a,this)}})},A.SpanNotQuery=function(a,b){if(!l(a)||!l(b))throw new TypeError("Argument must be a SpanQuery");var d=A.QueryMixin("span_not"),e=d.toJSON();return e.span_not.include=a.toJSON(),e.span_not.exclude=b.toJSON(),c(d,{include:function(a){if(null==a)return e.span_not.include;if(!l(a))throw new TypeError("Argument must be a SpanQuery");return e.span_not.include=a.toJSON(),this},exclude:function(a){if(null==a)return e.span_not.exclude;if(!l(a))throw new TypeError("Argument must be a SpanQuery");return e.span_not.exclude=a.toJSON(),this}})},A.SpanOrQuery=function(a){var b,d,f=A.QueryMixin("span_or"),g=f.toJSON();if(g.span_or.clauses=[],l(a))g.span_or.clauses.push(a.toJSON());else{if(!e(a))throw new TypeError("Argument must be SpanQuery or array of SpanQueries");for(b=0,d=a.length;d>b;b++){if(!l(a[b]))throw new TypeError("Argument must be array of SpanQueries");g.span_or.clauses.push(a[b].toJSON())}}return c(f,{clauses:function(a){var b,c;if(null==a)return g.span_or.clauses;if(l(a))g.span_or.clauses.push(a.toJSON());else{if(!e(a))throw new TypeError("Argument must be SpanQuery or array of SpanQueries");for(g.span_or.clauses=[],b=0,c=a.length;c>b;b++){if(!l(a[b]))throw new TypeError("Argument must be array of SpanQueries");g.span_or.clauses.push(a[b].toJSON())}}return this}})},A.SpanTermQuery=function(a,b){var d=A.QueryMixin("span_term"),e=d.toJSON();return e.span_term[a]={term:b},c(d,{field:function(b){var c=e.span_term[a];return null==b?a:(delete e.span_term[a],a=b,e.span_term[b]=c,this)},term:function(b){return null==b?e.span_term[a].term:(e.span_term[a].term=b,this)},boost:function(b){return null==b?e.span_term[a].boost:(e.span_term[a].boost=b,this)}})},A.TermQuery=function(a,b){var d=A.QueryMixin("term"),e=d.toJSON();return e.term[a]={term:b},c(d,{field:function(b){var c=e.term[a];return null==b?a:(delete e.term[a],a=b,e.term[b]=c,this)},term:function(b){return null==b?e.term[a].term:(e.term[a].term=b,this)},boost:function(b){return null==b?e.term[a].boost:(e.term[a].boost=b,this)}})},A.TermsQuery=function(a,b){var d=A.QueryMixin("terms"),f=d.toJSON();if(g(b))f.terms[a]=[b];else{if(!e(b))throw new TypeError("Argument must be string or array");f.terms[a]=b}return c(d,{field:function(b){var c=f.terms[a];return null==b?a:(delete f.terms[a],a=b,f.terms[b]=c,this)},terms:function(b){if(null==b)return f.terms[a];if(g(b))f.terms[a].push(b);else{if(!e(b))throw new TypeError("Argument must be string or array");f.terms[a]=b}return this},minimumShouldMatch:function(a){return null==a?f.terms.minimum_should_match:(f.terms.minimum_should_match=a,this)},disableCoord:function(a){return null==a?f.terms.disable_coord:(f.terms.disable_coord=a,this)}})},A.TopChildrenQuery=function(a,b){if(!l(a))throw new TypeError("Argument must be a Query");var d=A.QueryMixin("top_children"),e=d.toJSON();return e.top_children.query=a.toJSON(),e.top_children.type=b,c(d,{query:function(a){if(null==a)return e.top_children.query;if(!l(a))throw new TypeError("Argument must be a Query");return e.top_children.query=a.toJSON(),this},type:function(a){return null==a?e.top_children.type:(e.top_children.type=a,this)},scope:function(a){return this},score:function(a){return null==a?e.top_children.score:(a=a.toLowerCase(),("max"===a||"sum"===a||"avg"===a||"total"===a)&&(e.top_children.score=a),this)},scoreMode:function(a){return null==a?e.top_children.score_mode:(a=a.toLowerCase(),("max"===a||"sum"===a||"avg"===a||"total"===a)&&(e.top_children.score_mode=a),this)},factor:function(a){return null==a?e.top_children.factor:(e.top_children.factor=a,this)},incrementalFactor:function(a){return null==a?e.top_children.incremental_factor:(e.top_children.incremental_factor=a,this)}})},A.WildcardQuery=function(a,b){var d=A.QueryMixin("wildcard"),e=d.toJSON();return e.wildcard[a]={value:b},c(d,{field:function(b){var c=e.wildcard[a];return null==b?a:(delete e.wildcard[a],a=b,e.wildcard[b]=c,this)},value:function(b){return null==b?e.wildcard[a].value:(e.wildcard[a].value=b,this)},rewrite:function(b){return null==b?e.wildcard[a].rewrite:(b=b.toLowerCase(),("constant_score_auto"===b||"scoring_boolean"===b||"constant_score_boolean"===b||"constant_score_filter"===b||0===b.indexOf("top_terms_boost_")||0===b.indexOf("top_terms_"))&&(e.wildcard[a].rewrite=b),this)},boost:function(b){return null==b?e.wildcard[a].boost:(e.wildcard[a].boost=b,this)}})},A.BoostFactorScoreFunction=function(a){var b=A.ScoreFunctionMixin("boost_factor"),d=b.toJSON();return d.boost_factor=a,c(b,{boost:function(a){return null==a?d.boost_factor:(d.boost_factor=a,this)}})},A.DecayScoreFunction=function(a){var b="gauss",d=A.ScoreFunctionMixin(b),e=d.toJSON(),f=function(a){var c;b!==a&&(c=e[b],delete e[b],b=a,e[b]=c)};return e[b][a]={},c(d,{linear:function(){f("linear")},exp:function(){f("exp")},gauss:function(){f("gauss")},field:function(c){var d=e[b][a];return null==c?a:(delete e[b][a],a=c,e[b][a]=d,this)},scale:function(c){return null==c?e[b][a].scale:(e[b][a].scale=c,this)},origin:function(c){if(null==c)return e[b][a].origin;if(r(c))e[b][a].origin=c.toJSON();else{if(k(c))throw new TypeError("origin must be a GeoPoint or native type");e[b][a].origin=c}return this},decay:function(c){return null==c?e[b][a].decay:(e[b][a].decay=c,this)},offset:function(c){return null==c?e[b][a].offset:(e[b][a].offset=c,this)}})},A.FieldValueScoreFunction=function(){var a=A.ScoreFunctionMixin("field_value_factor"),b=a.toJSON();return c(a,{field:function(a){return null==a?b.field_value_factor.field:(b.field_value_factor.field=a,this)},factor:function(a){return null==a?b.field_value_factor.factor:(b.field_value_factor.factor=a,this)},modifier:function(a){return null==a?b.field_value_factor.modifier:(b.field_value_factor.modifier=a,this)}})},A.RandomScoreFunction=function(){var a=A.ScoreFunctionMixin("random_score"),b=a.toJSON();return c(a,{seed:function(a){return null==a?b.random_score.seed:(b.random_score.seed=a,this)}})},A.ScriptScoreFunction=function(){var a=A.ScoreFunctionMixin("script_score"),b=a.toJSON();return c(a,{script:function(a){if(null==a)return b.script_score.script;if(!z(a))throw new TypeError("Argument must be a Script");return b.script_score.script=a.toJSON(),this}})},A.Script=function(a){var b={};return{lang:function(a){return null==a?b.lang:(b.lang=a,this)},inline:function(a){return null==a?b.inline:(b.inline=a,this)},file:function(a){return null==a?b.file:(b.file=a,this)},params:function(a){return null==a?b.params:(b.params=a,this)},scriptId:function(a){return null==a?b.id:(b.id=a,this)},_type:function(){return"script"},toJSON:function(){return b}}},A.GeoPoint=function(b){var c=[0,0];return null!=b&&e(b)&&2===b.length&&(c=[b[1],b[0]]),{properties:function(b){return null==b?c:(f(b)&&a(b,"lat")&&a(b,"lon")?c={lat:b.lat,lon:b.lon}:f(b)&&a(b,"geohash")&&(c={geohash:b.geohash}),this)},string:function(a){return null==a?c:(g(a)&&-1!==a.indexOf(",")&&(c=a),this)},geohash:function(a,b){return b=null!=b&&h(b)?b:12,null==a?c:(g(a)&&a.length===b&&(c=a),this)},array:function(a){return null==a?c:(e(a)&&2===a.length&&(c=[a[1],a[0]]),this)},_type:function(){return"geo point"},toJSON:function(){return c}}},A.Highlight=function(c){var d={fields:{}},h=function(b,c,e){null==b?d[c]=e:(a(d.fields,b)||(d.fields[b]={}),d.fields[b][c]=e)};return null!=c&&(g(c)?d.fields[c]={}:e(c)&&b(c,function(a){d.fields[a]={}})),{fields:function(c){return null==c?d.fields:void(g(c)?a(d.fields,c)||(d.fields[c]={}):e(c)&&b(c,function(b){a(d.fields,b)||(d.fields[b]={})}))},preTags:function(a,b){return null===a&&null!=b?d.fields[b].pre_tags:null==a?d.pre_tags:(g(a)?h(b,"pre_tags",[a]):e(a)&&h(b,"pre_tags",a),this)},postTags:function(a,b){return null===a&&null!=b?d.fields[b].post_tags:null==a?d.post_tags:(g(a)?h(b,"post_tags",[a]):e(a)&&h(b,"post_tags",a),this)},order:function(a,b){return null===a&&null!=b?d.fields[b].order:null==a?d.order:(a=a.toLowerCase(),"score"===a&&h(b,"order",a),this)},tagsSchema:function(a){return null==a?d.tags_schema:(a=a.toLowerCase(),"styled"===a&&(d.tags_schema=a),this)},highlightFilter:function(a,b){return null===a&&null!=b?d.fields[b].highlight_filter:null==a?d.highlight_filter:(h(b,"highlight_filter",a),this)},fragmentSize:function(a,b){return null===a&&null!=b?d.fields[b].fragment_size:null==a?d.fragment_size:(h(b,"fragment_size",a),this)},numberOfFragments:function(a,b){return null===a&&null!=b?d.fields[b].number_of_fragments:null==a?d.number_of_fragments:(h(b,"number_of_fragments",a),this)},encoder:function(a){return null==a?d.encoder:(a=a.toLowerCase(),("default"===a||"html"===a)&&(d.encoder=a),this)},requireFieldMatch:function(a,b){return null===a&&null!=b?d.fields[b].require_field_match:null==a?d.require_field_match:(h(b,"require_field_match",a),this)},boundaryMaxScan:function(a,b){return null===a&&null!=b?d.fields[b].boundary_max_scan:null==a?d.boundary_max_scan:(h(b,"boundary_max_scan",a),this)},boundaryChars:function(a,b){return null===a&&null!=b?d.fields[b].boundary_chars:null==a?d.boundary_chars:(h(b,"boundary_chars",a),this)},type:function(a,b){return null===a&&null!=b?d.fields[b].type:null==a?d.type:(a=a.toLowerCase(),("fvh"===a||"plain"===a||"postings"===a)&&h(b,"type",a),this)},fragmenter:function(a,b){return null===a&&null!=b?d.fields[b].fragmenter:null==a?d.fragmenter:(a=a.toLowerCase(),("simple"===a||"span"===a)&&h(b,"fragmenter",a),this)},options:function(a,b){if(null===a&&null!=b)return d.fields[b].options;if(null==a)return d.options;if(!f(a)||e(a)||k(a))throw new TypeError("Parameter must be an object");return h(b,"options",a),this},_type:function(){return"highlight"},toJSON:function(){return d}}},A.IndexedShape=function(a,b){var c={type:a,id:b};return{type:function(a){return null==a?c.type:(c.type=a,this)},id:function(a){return null==a?c.id:(c.id=a,this)},index:function(a){return null==a?c.index:(c.index=a,this)},shapeFieldName:function(a){return null==a?c.shape_field_name:(c.shape_field_name=a,this)},_type:function(){return"indexed shape"},toJSON:function(){return c}}},A.Request=function(){var b={};return{sort:function(){var c,d;if(a(b,"sort")||(b.sort=[]),0===arguments.length)return b.sort;if(1===arguments.length){var f=arguments[0];if(g(f))b.sort.push(f);else if(u(f))b.sort.push(f.toJSON());else{if(!e(f))throw new TypeError("Argument must be string, Sort, or array");for(b.sort=[],c=0,d=f.length;d>c;c++)if(g(f[c]))b.sort.push(f[c]);else{if(!u(f[c]))throw new TypeError("Invalid object in array");b.sort.push(f[c].toJSON())}}}else if(2===arguments.length){var h=arguments[0],i=arguments[1];if(g(h)&&g(i)&&(i=i.toLowerCase(),"asc"===i||"desc"===i)){var j={};j[h]={order:i},b.sort.push(j)}}return this},trackScores:function(a){return null==a?b.track_scores:(b.track_scores=a,this)},from:function(a){return null==a?b.from:(b.from=a,this)},size:function(a){return null==a?b.size:(b.size=a,this)},timeout:function(a){return null==a?b.timeout:(b.timeout=a,this)},fields:function(a){if(null==a)return b.fields;if(null==b.fields&&(b.fields=[]),g(a))b.fields.push(a);else{if(!e(a))throw new TypeError("Argument must be a string or an array");b.fields=a}return this},docValueFields:function(a){if(null==a)return b.docvalue_fields;if(null==b.docvalue_fields&&(b.docvalue_fields=[]),g(a))b.docvalue_fields.push(a);else{if(!e(a))throw new TypeError("Argument must be a string or an array");b.docvalue_fields=a}return this},source:function(a,c){if(null==a&&null==c)return b._source;if(!e(a)&&!g(a)&&!i(a))throw new TypeError("Argument includes must be a string, an array, or a boolean");if(null!=c&&!e(c)&&!g(c))throw new TypeError("Argument excludes must be a string or an array");return i(a)?b._source=a:(b._source={includes:a},null!=c&&(b._source.excludes=c)),this},rescore:function(a){if(null==a)return b.rescore;if(!m(a))throw new TypeError("Argument must be a Rescore");return b.rescore=a.toJSON(),this},query:function(a){if(null==a)return b.query;if(!l(a))throw new TypeError("Argument must be a Query");return b.query=a.toJSON(),this},facet:function(a){if(null==a)return b.facets;if(null==b.facets&&(b.facets={}),!o(a))throw new TypeError("Argument must be a Facet");return c(b.facets,a.toJSON()),this},aggregation:function(a){if(null==a)return b.aggs;if(null==b.aggs&&(b.aggs={}),!p(a))throw new TypeError("Argument must be an Aggregation");return c(b.aggs,a.toJSON()),this},agg:function(a){return this.aggregation(a)},filter:function(a){if(null==a)return b.post_filter;if(!n(a))throw new TypeError("Argument must be a Filter");return b.post_filter=a.toJSON(),this},highlight:function(a){if(null==a)return b.highlight;if(!v(a))throw new TypeError("Argument must be a Highlight object");return b.highlight=a.toJSON(),this},suggest:function(a){if(null==a)return b.suggest;if(null==b.suggest&&(b.suggest={}),g(a))b.suggest.text=a;else{if(!w(a))throw new TypeError("Argument must be a string or Suggest object");c(b.suggest,a.toJSON())}return this},scriptField:function(a){if(null==a)return b.script_fields;if(null==b.script_fields&&(b.script_fields={}),!q(a))throw new TypeError("Argument must be a ScriptField");return c(b.script_fields,a.toJSON()),this},indexBoost:function(a,c){return null==b.indices_boost&&(b.indices_boost={}),0===arguments.length?b.indices_boost:(b.indices_boost[a]=c,this)},explain:function(a){return null==a?b.explain:(b.explain=a,this)},version:function(a){return null==a?b.version:(b.version=a,this)},minScore:function(a){return null==a?b.min_score:(b.min_score=a,this)},_type:function(){return"request"},toJSON:function(){return b}}},A.Rescore=function(a,b){if(null!=a&&!h(a))throw new TypeError("Argument must be a Number");if(null!=b&&!l(b))throw new TypeError("Argument must be a Query");var c={query:{}};return null!=a&&(c.window_size=a),null!=b&&(c.query.rescore_query=b.toJSON()),{rescoreQuery:function(a){if(null==a)return c.query.rescore_query;if(!l(a))throw new TypeError("Argument must be a Query");return c.query.rescore_query=a.toJSON(),this},queryWeight:function(a){if(null==a)return c.query.query_weight;if(!h(a))throw new TypeError("Argument must be a Number");return c.query.query_weight=a,this},rescoreQueryWeight:function(a){if(null==a)return c.query.rescore_query_weight;if(!h(a))throw new TypeError("Argument must be a Number");return c.query.rescore_query_weight=a,this},windowSize:function(a){if(null==a)return c.window_size;if(!h(a))throw new TypeError("Argument must be a Number");return c.window_size=a,this},scoreMode:function(a){return null==a?c.query.score_mode:(a=a.toLowerCase(),("total"===a||"min"===a||"max"===a||"multiply"===a||"avg"===a)&&(c.query.score_mode=a), +this)},_type:function(){return"rescore"},toJSON:function(){return c}}},A.ScriptField=function(a){var b={};return b[a]={},{lang:function(c){return null==c?b[a].lang:(b[a].lang=c,this)},script:function(c){return null==c?b[a].script:(b[a].script=c,this)},params:function(c){return null==c?b[a].params:(b[a].params=c,this)},ignoreFailure:function(c){return null==c?b[a].ignore_failure:(b[a].ignore_failure=c,this)},_type:function(){return"script field"},toJSON:function(){return b}}},A.Shape=function(a,b){var c={},d=function(a){var b=!1;return("point"===a||"linestring"===a||"polygon"===a||"multipoint"===a||"envelope"===a||"multipolygon"===a||"circle"===a||"multilinestring"===a)&&(b=!0),b};return a=a.toLowerCase(),d(a)&&(c.type=a,c.coordinates=b),{type:function(a){return null==a?c.type:(a=a.toLowerCase(),d(a)&&(c.type=a),this)},coordinates:function(a){return null==a?c.coordinates:(c.coordinates=a,this)},radius:function(a){return null==a?c.radius:(c.radius=a,this)},_type:function(){return"shape"},toJSON:function(){return c}}},A.Sort=function(a){null==a&&(a="_score");var b={},c=a,d="_geo_distance",e="_script";return b[c]={},{field:function(d){var e=b[c];return null==d?a:(delete b[c],a=d,c=d,b[c]=e,this)},geoDistance:function(e){var f=b[c];if(null==e)return b[c][a];if(!r(e))throw new TypeError("Argument must be a GeoPoint");return delete b[c],c=d,b[c]=f,b[c][a]=e.toJSON(),this},script:function(a){var d=b[c];return null==a?b[c].script:(delete b[c],c=e,b[c]=d,b[c].script=a,this)},order:function(a){return null==a?b[c].order:(a=a.toLowerCase(),("asc"===a||"desc"===a)&&(b[c].order=a),this)},asc:function(){return b[c].order="asc",this},desc:function(){return b[c].order="desc",this},reverse:function(a){return null==a?b[c].reverse:(b[c].reverse=a,this)},missing:function(a){return null==a?b[c].missing:(b[c].missing=a,this)},ignoreUnmapped:function(a){return null==a?b[c].ignore_unmapped:(b[c].ignore_unmapped=a,this)},unit:function(a){return null==a?b[c].unit:(a=a.toLowerCase(),("mi"===a||"km"===a)&&(b[c].unit=a),this)},normalize:function(a){return null==a?b[c].normalize:(b[c].normalize=a,this)},distanceType:function(a){return null==a?b[c].distance_type:(a=a.toLowerCase(),("arc"===a||"plane"===a)&&(b[c].distance_type=a),this)},params:function(a){return null==a?b[c].params:(b[c].params=a,this)},lang:function(a){return null==a?b[c].lang:(b[c].lang=a,this)},type:function(a){return null==a?b[c].type:(a=a.toLowerCase(),("string"===a||"number"===a)&&(b[c].type=a),this)},mode:function(a){return null==a?b[c].mode:(a=a.toLowerCase(),("min"===a||"max"===a||"sum"===a||"avg"===a)&&(b[c].mode=a),this)},nestedPath:function(a){return null==a?b[c].nested_path:(b[c].nested_path=a,this)},nestedFilter:function(a){if(null==a)return b[c].nested_filter;if(!n(a))throw new TypeError("Argument must be a Filter");return b[c].nested_filter=a.toJSON(),this},_type:function(){return"sort"},toJSON:function(){return b}}},A.CompletionSuggester=function(a){var b,d=A.SuggesterMixin(a),e=d.toJSON();return e[a].completion={},b=A.SuggestContextMixin(e[a].completion),c(d,b,{fuzzy:function(b){return null==b?e[a].completion.fuzzy:(b&&null==e[a].completion.fuzzy?e[a].completion.fuzzy={}:b||null==e[a].completion.fuzzy||delete e[a].completion.fuzzy,this)},transpositions:function(b){return null==e[a].completion.fuzzy&&(e[a].completion.fuzzy={}),null==b?e[a].completion.fuzzy.transpositions:(e[a].completion.fuzzy.transpositions=b,this)},unicodeAware:function(b){return null==e[a].completion.fuzzy&&(e[a].completion.fuzzy={}),null==b?e[a].completion.fuzzy.unicode_aware:(e[a].completion.fuzzy.unicode_aware=b,this)},editDistance:function(b){return null==e[a].completion.fuzzy&&(e[a].completion.fuzzy={}),null==b?e[a].completion.fuzzy.edit_distance:(e[a].completion.fuzzy.edit_distance=b,this)},minLength:function(b){return null==e[a].completion.fuzzy&&(e[a].completion.fuzzy={}),null==b?e[a].completion.fuzzy.min_length:(e[a].completion.fuzzy.min_length=b,this)},prefixLength:function(b){return null==e[a].completion.fuzzy&&(e[a].completion.fuzzy={}),null==b?e[a].completion.fuzzy.prefix_length:(e[a].completion.fuzzy.prefix_length=b,this)}})},A.DirectGenerator=function(){var a={},b=A.DirectSettingsMixin(a);return c(b,{preFilter:function(b){return null==b?a.pre_filter:(a.pre_filter=b,this)},postFilter:function(b){return null==b?a.post_filter:(a.post_filter=b,this)},field:function(b){return null==b?a.field:(a.field=b,this)},size:function(b){return null==b?a.size:(a.size=b,this)},_type:function(){return"generator"},toJSON:function(){return a}})},A.PhraseSuggester=function(a){var b,d=A.SuggesterMixin(a),f=d.toJSON();return f[a].phrase={},b=A.SuggestContextMixin(f[a].phrase),c(d,b,{realWordErrorLikelihood:function(b){return null==b?f[a].phrase.real_word_error_likelihood:(f[a].phrase.real_word_error_likelihood=b,this)},confidence:function(b){return null==b?f[a].phrase.confidence:(f[a].phrase.confidence=b,this)},separator:function(b){return null==b?f[a].phrase.separator:(f[a].phrase.separator=b,this)},maxErrors:function(b){return null==b?f[a].phrase.max_errors:(f[a].phrase.max_errors=b,this)},gramSize:function(b){return null==b?f[a].phrase.gram_size:(f[a].phrase.gram_size=b,this)},forceUnigrams:function(b){return null==b?f[a].phrase.force_unigrams:(f[a].phrase.force_unigrams=b,this)},tokenLimit:function(b){return null==b?f[a].phrase.token_limit:(f[a].phrase.token_limit=b,this)},linearSmoothing:function(b,c,d){return 0===arguments.length?f[a].phrase.smoothing:(f[a].phrase.smoothing={linear:{trigram_lambda:b,bigram_lambda:c,unigram_lambda:d}},this)},laplaceSmoothing:function(b){return null==b?f[a].phrase.smoothing:(f[a].phrase.smoothing={laplace:{alpha:b}},this)},stupidBackoffSmoothing:function(b){return null==b?f[a].phrase.smoothing:(f[a].phrase.smoothing={stupid_backoff:{discount:b}},this)},highlight:function(b,c){return 0===arguments.length?f[a].phrase.highlight:(f[a].phrase.highlight={pre_tag:b,post_tag:c},this)},directGenerator:function(b){var c,d;if(null==f[a].phrase.direct_generator&&(f[a].phrase.direct_generator=[]),null==b)return f[a].phrase.direct_generator;if(x(b))f[a].phrase.direct_generator.push(b.toJSON());else{if(!e(b))throw new TypeError("Argument must be a Generator or array of Generators");for(f[a].phrase.direct_generator=[],c=0,d=b.length;d>c;c++){if(!x(b[c]))throw new TypeError("Argument must be an array of Generators");f[a].phrase.direct_generator.push(b[c].toJSON())}}return this}})},A.TermSuggester=function(a){var b,d,e=A.SuggesterMixin(a),f=e.toJSON();return f[a].term={},b=A.DirectSettingsMixin(f[a].term),d=A.SuggestContextMixin(f[a].term),c(e,b,d)},A.noConflict=function(){return B.ejs=C,this}}).call(this); \ No newline at end of file diff --git a/src/aggregations/FiltersAggregation.js b/src/aggregations/FiltersAggregation.js new file mode 100644 index 0000000..580311a --- /dev/null +++ b/src/aggregations/FiltersAggregation.js @@ -0,0 +1,54 @@ + /** + @class +

Defines a single bucket of all the documents in the current document set + context that match a specified filter. Often this will be used to narrow down + the current aggregation context to a specific set of documents.

+ + @name ejs.FilterAggregation + @ejs aggregation + @borrows ejs.AggregationMixin.aggregation as aggregation + @borrows ejs.AggregationMixin.agg as agg + @borrows ejs.AggregationMixin._type as _type + @borrows ejs.AggregationMixin.toJSON as toJSON + + @desc +

Defines a single bucket of all the documents that match a given filter.

+ + @param {String} name The name which be used to refer to this aggregation. + + */ + ejs.FiltersAggregation = function (name) { + + var + _common = ejs.AggregationMixin(name), + agg = _common.toJSON(); + + return extend(_common, { + + /** +

Sets the filters to be used for this aggregation.

+ + @member ejs.FilterAggregation + @param {Filter} oFilter A valid Filter object. + @returns {Object} returns this so that calls can be chained. + */ + filters: function (oFilters) { + if (oFilters == null) { + return agg[name].filters; + } + var filters = {}, key, oFilter; + agg[name].filters = { + filters: filters + }; + for (key in oFilters) { + oFilter = oFilters[key]; + if (!isFilter(oFilter)) { + throw new TypeError('Argument must be a Filter'); + } + filters[key] = oFilter.toJSON(); + } + return this; + } + + }); + }; diff --git a/src/aggregations/PercentilesAggregation.js b/src/aggregations/PercentilesAggregation.js index 13f61f0..c7edb5d 100644 --- a/src/aggregations/PercentilesAggregation.js +++ b/src/aggregations/PercentilesAggregation.js @@ -101,11 +101,15 @@ @returns {Object} returns this so that calls can be chained. */ compression: function (c) { + var tdigest = agg[name].percentiles.tdigest; if (c == null) { - return agg[name].percentiles.compression; + return tdigest && tdigest.compression; + } + if (!tdigest) { + tdigest = agg[name].percentiles.tdigest = {}; } - agg[name].percentiles.compression = c; + tdigest.compression = c; return this; } diff --git a/src/aggregations/ReverseNestedAggregation.js b/src/aggregations/ReverseNestedAggregation.js new file mode 100644 index 0000000..5928304 --- /dev/null +++ b/src/aggregations/ReverseNestedAggregation.js @@ -0,0 +1,47 @@ + /** + @class +

A special single bucket aggregation that enables aggregating nested + documents.

+ + @name ejs.ReverseNestedAggregation + @ejs aggregation + @borrows ejs.AggregationMixin.aggregation as aggregation + @borrows ejs.AggregationMixin.agg as agg + @borrows ejs.AggregationMixin._type as _type + @borrows ejs.AggregationMixin.toJSON as toJSON + + @desc +

A special single bucket aggregation that enables aggregating nested + documents.

+ + @param {String} name The name which be used to refer to this aggregation. + + */ + ejs.ReverseNestedAggregation = function (name) { + + var + _common = ejs.AggregationMixin(name), + agg = _common.toJSON(); + + agg[name].reverse_nested = {}; + + return extend(_common, { + + /** +

Sets the nested path.

+ + @member ejs.ReverseNestedAggregation + @param {String} path The nested path value. + @returns {Object} returns this so that calls can be chained. + */ + reversePath: function (path) { + if (path == null) { + return agg[name].reverse_nested.path; + } + + agg[name].reverse_nested.path = path; + return this; + } + + }); + }; diff --git a/src/aggregations/TopHitsAggregation.js b/src/aggregations/TopHitsAggregation.js index 309bbeb..447f4f0 100644 --- a/src/aggregations/TopHitsAggregation.js +++ b/src/aggregations/TopHitsAggregation.js @@ -24,6 +24,11 @@ _common = ejs.MetricsAggregationMixin(name, 'top_hits'), agg = _common.toJSON(); + agg[name].top_hits = { + size: 0, + from: 0 + }; + return extend(_common, { /**

The offset from the first result you want to fetch.

@@ -33,7 +38,7 @@ @returns {Object} returns this so that calls can be chained. */ from: function (from) { - if (from === null) { + if (from == null) { return agg[name].top_hits.from; } @@ -49,7 +54,7 @@ @returns {Object} returns this so that calls can be chained. */ size: function (size) { - if (size === null) { + if (size == null) { return agg[name].top_hits.size; } @@ -60,16 +65,80 @@ /**

The maximum number of top matching hits to return per bucket.

+
+
sort() - The current sorting values are returned.
+
sort(fieldName) - Adds the field to the current list of sorting values.
+
sort(fieldName, order) - Adds the field to the current list of + sorting with the specified order. Order must be asc or desc.
+
sort(ejs.Sort) - Adds the Sort value to the current list of sorting values.
+
sort(array) - Replaces all current sorting values with values + from the array. The array must contain only strings and Sort objects.
+
+ +

Multi-level sorting is supported so the order in which sort fields + are added to the query requests is relevant.

+ +

It is recommended to use Sort objects when possible.

+ @member ejs.TopHitsAggregation @param {Array} sort How to sort the the top matching hits @returns {Object} returns this so that calls can be chained. */ - sort: function (sort) { - if (sort === null) { - return agg[name].top_hits.sort; + sort: function () { + var i, len; + var query = agg[name].top_hits; + + if (!has(query, "sort")) { + query.sort = []; + } + + if (arguments.length === 0) { + return query.sort; + } + + // if passed a single argument + if (arguments.length === 1) { + var sortVal = arguments[0]; + + if (isString(sortVal)) { + // add a single field name + query.sort.push(sortVal); + } else if (isSort(sortVal)) { + // add the Sort object + query.sort.push(sortVal.toJSON()); + } else if (isArray(sortVal)) { + // replace with all values in the array + // the values must be a fieldName (string) or a + // Sort object. Any other type throws an Error. + query.sort = []; + for (i = 0, len = sortVal.length; i < len; i++) { + if (isString(sortVal[i])) { + query.sort.push(sortVal[i]); + } else if (isSort(sortVal[i])) { + query.sort.push(sortVal[i].toJSON()); + } else { + throw new TypeError('Invalid object in array'); + } + } + } else { + // Invalid object type as argument. + throw new TypeError('Argument must be string, Sort, or array'); + } + } else if (arguments.length === 2) { + // handle the case where a single field name and order are passed + var field = arguments[0], + order = arguments[1]; + + if (isString(field) && isString(order)) { + order = order.toLowerCase(); + if (order === 'asc' || order === 'desc') { + var sortObj = {}; + sortObj[field] = {order: order}; + query.sort.push(sortObj); + } + } } - agg[name].top_hits.sort = sort; return this; }, @@ -82,7 +151,7 @@ @returns {Object} returns this so that calls can be chained. */ trackScores: function (trueFalse) { - if (trueFalse === null) { + if (trueFalse == null) { return agg[name].top_hits.track_scores; } @@ -98,7 +167,7 @@ @returns {Object} returns this so that calls can be chained. */ version: function (trueFalse) { - if (trueFalse === null) { + if (trueFalse == null) { return agg[name].top_hits.version; } @@ -114,7 +183,7 @@ @returns {Object} returns this so that calls can be chained. */ explain: function (trueFalse) { - if (trueFalse === null) { + if (trueFalse == null) { return agg[name].top_hits.explain; } @@ -130,7 +199,7 @@ @returns {Object} returns this so that calls can be chained. */ highlight: function (h) { - if (h === null) { + if (h == null) { return agg[name].top_hits.highlight; } @@ -150,11 +219,11 @@ @returns {Object} returns this so that calls can be chained. */ scriptField: function (oScriptField) { - if (oScriptField === null) { + if (oScriptField == null) { return agg[name].top_hits.script_fields; } - if (agg[name].top_hits.script_fields === undefined) { + if (agg[name].top_hits.script_fields == null) { agg[name].top_hits.script_fields = {}; } @@ -173,12 +242,24 @@ @param {Array} Fields to return field data representation for. @returns {Object} returns this so that calls can be chained. */ - fieldDataFields: function (fielddata_fields) { - if (fielddata_fields === null) { - return agg[name].top_hits.fielddata_fields; + docValueFields: function (fieldList) { + var query = agg[name].top_hits; + if (fieldList == null) { + return query.docvalue_fields; + } + + if (query.docvalue_fields == null) { + query.docvalue_fields = []; + } + + if (isString(fieldList)) { + query.docvalue_fields.push(fieldList); + } else if (isArray(fieldList)) { + query.docvalue_fields = fieldList; + } else { + throw new TypeError('Argument must be a string or an array'); } - agg[name].top_hits.fielddata_fields = fielddata_fields; return this; }, @@ -196,27 +277,28 @@ @returns {Object} returns this so that calls can be chained. */ source: function (includes, excludes) { - if (includes === undefined && excludes === undefined) { - return agg[name].top_hits._source; + var query = agg[name].top_hits; + if (includes == null && excludes == null) { + return query._source; } if (!isArray(includes) && !isString(includes) && !isBoolean(includes)) { throw new TypeError('Argument includes must be a string, an array, or a boolean'); } - if (excludes !== undefined && !isArray(excludes) && !isString(excludes)) { + if (excludes != null && !isArray(excludes) && !isString(excludes)) { throw new TypeError('Argument excludes must be a string or an array'); } if (isBoolean(includes)) { - agg[name].top_hits._source = includes; + query._source = includes; } else { - agg[name].top_hits._source = { + query._source = { includes: includes }; - if (excludes !== undefined) { - agg[name].top_hits._source = excludes; + if (excludes != null) { + query._source.excludes = excludes; } } diff --git a/src/filter/GeoDistanceFilter.js b/src/filter/GeoDistanceFilter.js index 6a075ff..97abb83 100644 --- a/src/filter/GeoDistanceFilter.js +++ b/src/filter/GeoDistanceFilter.js @@ -62,11 +62,11 @@ return filter.geo_distance.distance; } - if (!isNumber(numericDistance)) { - throw new TypeError('Argument must be a numeric value'); + if (!isNumber(numericDistance) && !isString(numericDistance)) { + throw new TypeError('Argument must be a numeric or string value'); } - filter.geo_distance.distance = numericDistance; + filter.geo_distance.distance = numericDistance + ""; return this; }, diff --git a/src/pre.js b/src/pre.js index 17081dc..9e41dbc 100644 --- a/src/pre.js +++ b/src/pre.js @@ -51,6 +51,7 @@ isSuggest, // checks valid ejs Suggest object isGenerator, // checks valid ejs Generator object isScoreFunction, // checks valid ejs ScoreFunction object + isScript, // checks valid ejs Script object // create ejs object ejs; diff --git a/src/query/BoolQuery.js b/src/query/BoolQuery.js index fd8b331..eedb74b 100644 --- a/src/query/BoolQuery.js +++ b/src/query/BoolQuery.js @@ -188,7 +188,27 @@ query.bool.minimum_number_should_match = minMatch; return this; + }, + + /** + Adds the filter to apply a constant score to. + + @member ejs.BoolQuery + @param {Object} oFilter A valid Filter object + @returns {Object} returns this so that calls can be chained. + */ + filter: function (oFilter) { + if (oFilter == null) { + return query.bool.filter; + } + + if (!isFilter(oFilter)) { + throw new TypeError('Argument must be a Filter'); + } + + query.bool.filter = oFilter.toJSON(); + return this; } - + }); }; diff --git a/src/query/functions/FieldValueScoreFunction.js b/src/query/functions/FieldValueScoreFunction.js new file mode 100644 index 0000000..6c14133 --- /dev/null +++ b/src/query/functions/FieldValueScoreFunction.js @@ -0,0 +1,74 @@ + /** + @class +

The script_score function allows you to wrap another query and customize + the scoring of it optionally with a computation derived from other numeric + field values in the doc using a script expression.

+ + @name ejs.FieldValueScoreFunction + @ejs scorefunction + @borrows ejs.ScoreFunctionMixin.filter as filter + @borrows ejs.ScoreFunctionMixin._type as _type + @borrows ejs.ScoreFunctionMixin.toJSON as toJSON + + @desc +

Modify a documents score using a script.

+ + */ + ejs.FieldValueScoreFunction = function () { + + var + _common = ejs.ScoreFunctionMixin('field_value_factor'), + func = _common.toJSON(); + + return extend(_common, { + + /** + Set the field that will modify the score. + + @member ejs.FieldValueScoreFunction + @param {String} field A valid field string. + @returns {Object} returns this so that calls can be chained. + */ + field: function (field) { + if (field == null) { + return func.field_value_factor.field; + } + + func.field_value_factor.field = field; + return this; + }, + + /** + The factor being used. + + @member ejs.FieldValueScoreFunction + @param {String} factor The factor. + @returns {Object} returns this so that calls can be chained. + */ + factor: function (factor) { + if (factor == null) { + return func.field_value_factor.factor; + } + + func.field_value_factor.factor = factor; + return this; + }, + + /** + The modifier being used. + + @member ejs.FieldValueScoreFunction + @param {String} factor The modifier. + @returns {Object} returns this so that calls can be chained. + */ + modifier: function (modifier) { + if (modifier == null) { + return func.field_value_factor.modifier; + } + + func.field_value_factor.modifier = modifier; + return this; + } + + }); + }; diff --git a/src/query/functions/ScriptScoreFunction.js b/src/query/functions/ScriptScoreFunction.js index a128cc0..401f63d 100644 --- a/src/query/functions/ScriptScoreFunction.js +++ b/src/query/functions/ScriptScoreFunction.js @@ -29,49 +29,17 @@ @param {String} scriptCode A valid script string to execute. @returns {Object} returns this so that calls can be chained. */ - script: function (scriptCode) { - if (scriptCode == null) { + script: function (oScript) { + if (oScript == null) { return func.script_score.script; } - func.script_score.script = scriptCode; - return this; - }, - - /** - The script language being used. - - @member ejs.ScriptScoreFunction - @param {String} language The language of the script. - @returns {Object} returns this so that calls can be chained. - */ - lang: function (language) { - if (language == null) { - return func.script_score.lang; + if (!isScript(oScript)) { + throw new TypeError('Argument must be a Script'); } - func.script_score.lang = language; + func.script_score.script = oScript.toJSON(); return this; }, - - /** - Sets parameters that will be applied to the script. Overwrites - any existing params. - - @member ejs.ScriptScoreFunction - @param {Object} p An object where the keys are the parameter name and - values are the parameter value. - @returns {Object} returns this so that calls can be chained. - */ - params: function (p) { - if (p == null) { - return func.script_score.params; - } - - func.script_score.params = p; - return this; - } - - }); }; diff --git a/src/query/functions/script/Script.js b/src/query/functions/script/Script.js new file mode 100644 index 0000000..ee6415b --- /dev/null +++ b/src/query/functions/script/Script.js @@ -0,0 +1,121 @@ + /** + @class +

Script's allow you create srcipt to call it at script score + + @name ejs.Script + @ejs request + + @desc +

Computes dynamic document properties based on information from other fields.

+ + @param {String} fieldName A name of the script field to create. + + */ + ejs.Script = function (fieldName) { + var script = {}; + + return { + + /** + The script language being used. Currently supported values are + javascript and mvel. + + @member ejs.Script + @param {String} language The language of the script. + @returns {Object} returns this so that calls can be chained. + */ + lang: function (language) { + if (language == null) { + return script.lang; + } + + script.lang = language; + return this; + }, + + /** + Sets the script/code that will be used to perform the calculation. + + @member ejs.Script + @param {String} expression The script/code to use. + @returns {Object} returns this so that calls can be chained. + */ + inline: function (expression) { + if (expression == null) { + return script.inline; + } + + script.inline = expression; + return this; + }, + + /** + Sets the script/code file that will be used to perform the calculation. + + @member ejs.Script + @param {String} file The script/code to use. + @returns {Object} returns this so that calls can be chained. + */ + file: function (file) { + if (file == null) { + return script.file; + } + + script.file = file; + return this; + }, + + /** + Allows you to set script parameters to be used during the execution of the script. + + @member ejs.Script + @param {Object} oParams An object containing key/value pairs representing param name/value. + @returns {Object} returns this so that calls can be chained. + */ + params: function (oParams) { + if (oParams == null) { + return script.params; + } + + script.params = oParams; + return this; + }, + + /** + Set the script id that will modify the score. + + @member ejs.Script + @param {Boolean} string + @returns {Object} returns this so that calls can be chained. + */ + scriptId: function (scriptId) { + if (scriptId == null) { + return script.id; + } + + script.id = scriptId; + return this; + }, + + /** + The type of ejs object. For internal use only. + + @member ejs.Script + @returns {String} the type of object + */ + _type: function () { + return 'script'; + }, + + /** + Retrieves the internal script object. This is typically used by + internal API functions so use with caution. + + @member ejs.Script + @returns {String} returns this object's internal facet property. + */ + toJSON: function () { + return script; + } + }; + }; diff --git a/src/search/Request.js b/src/search/Request.js index e51026f..e2ad90a 100644 --- a/src/search/Request.js +++ b/src/search/Request.js @@ -209,6 +209,26 @@ return this; }, + docValueFields: function (fieldList) { + if (fieldList == null) { + return query.docvalue_fields; + } + + if (query.docvalue_fields == null) { + query.docvalue_fields = []; + } + + if (isString(fieldList)) { + query.docvalue_fields.push(fieldList); + } else if (isArray(fieldList)) { + query.docvalue_fields = fieldList; + } else { + throw new TypeError('Argument must be a string or an array'); + } + + return this; + }, + /** Allows to control how the _source field is returned with every hit. By default operations return the contents of the _source field @@ -368,14 +388,14 @@ */ filter: function (filter) { if (filter == null) { - return query.filter; + return query.post_filter; } if (!isFilter(filter)) { throw new TypeError('Argument must be a Filter'); } - query.filter = filter.toJSON(); + query.post_filter = filter.toJSON(); return this; }, diff --git a/src/util.js b/src/util.js index 624b613..08a97f1 100644 --- a/src/util.js +++ b/src/util.js @@ -164,3 +164,8 @@ isScoreFunction = function (obj) { return (isEJSObject(obj) && obj._type() === 'score function'); }; + + isScript = function (obj) { + return (isEJSObject(obj) && obj._type() === 'script'); + }; + diff --git a/tests/aggregation_test.js b/tests/aggregation_test.js index 45e09de..2c3bb22 100644 --- a/tests/aggregation_test.js +++ b/tests/aggregation_test.js @@ -280,7 +280,7 @@ exports.aggregations = { doTest(); agg.compression(200); - expected.myagg.percentiles.compression = 200; + expected.myagg.percentiles.tdigest = { compression: 200 }; doTest(); test.strictEqual(agg._type(), 'aggregation'); @@ -1419,7 +1419,7 @@ exports.aggregations = { expected = { myagg: { - top_hits: {} + top_hits: { from: 0 } } }; @@ -1431,7 +1431,7 @@ exports.aggregations = { doTest(); agg.sort('foo'); - expected.myagg.top_hits.sort = 'foo'; + expected.myagg.top_hits.sort = ['foo']; doTest(); agg.trackScores(true); @@ -1458,12 +1458,12 @@ exports.aggregations = { expected.myagg.top_hits.script_fields = { f: {} }; doTest(); - agg.fieldDataFields(['foo', 'bar']); - expected.myagg.top_hits.fielddata_fields = ['foo', 'bar']; + agg.docValueFields(['foo', 'bar']); + expected.myagg.top_hits.docvalue_fields = ['foo', 'bar']; doTest(); - agg.fieldDataFields(['foo', 'bar']); - expected.myagg.top_hits.fielddata_fields = ['foo', 'bar']; + agg.docValueFields(['foo', 'bar']); + expected.myagg.top_hits.docvalue_fields = ['foo', 'bar']; doTest(); agg.source(true); @@ -1475,7 +1475,7 @@ exports.aggregations = { doTest(); agg.source(['foo'], 'bar'); - expected.myagg.top_hits._source = 'bar'; + expected.myagg.top_hits._source = {includes: ['foo'], excludes: 'bar'}; doTest(); diff --git a/tests/filter_test.js b/tests/filter_test.js index 3617be0..e14365a 100644 --- a/tests/filter_test.js +++ b/tests/filter_test.js @@ -1286,7 +1286,7 @@ exports.filters = { doTest(); geoDistanceFilter.distance(10); - expected.geo_distance.distance = 10; + expected.geo_distance.distance = "10"; doTest(); geoDistanceFilter.point(point1); @@ -1363,7 +1363,7 @@ exports.filters = { }, TypeError); test.throws(function () { - geoDistanceFilter.distance('invalid'); + geoDistanceFilter.distance(true); }, TypeError); test.done(); diff --git a/tests/query_test.js b/tests/query_test.js index 02efc16..7e1ab18 100644 --- a/tests/query_test.js +++ b/tests/query_test.js @@ -152,6 +152,7 @@ exports.queries = { ScriptScoreFunction: function (test) { test.expect(9); + var script = new ejs.Script().scriptId('s1'); var scoreFunc = ejs.ScriptScoreFunction(), termFilter1 = ejs.TermFilter('tf1', 'fv1'), expected, @@ -167,16 +168,19 @@ exports.queries = { test.ok(scoreFunc.toJSON(), 'toJSON() works'); doTest(); - scoreFunc.script('s1'); - expected.script_score.script = 's1'; + expected.script_score.script = {}; + scoreFunc.script(script); + expected.script_score.script.id = 's1'; doTest(); - scoreFunc.lang('mvel'); - expected.script_score.lang = 'mvel'; + script.lang('mvel'); + scoreFunc.script(script); + expected.script_score.script.lang = 'mvel'; doTest(); - scoreFunc.params({p1: 'v1'}); - expected.script_score.params = {p1: 'v1'}; + script.params({p1: 'v1'}); + scoreFunc.script(script); + expected.script_score.script.params = {p1: 'v1'}; doTest(); scoreFunc.filter(termFilter1); diff --git a/tests/search_test.js b/tests/search_test.js index 6133097..ca4193e 100644 --- a/tests/search_test.js +++ b/tests/search_test.js @@ -1284,7 +1284,7 @@ exports.search = { doTest(); req.filter(termFilter); - expected.filter = termFilter.toJSON(); + expected.post_filter = termFilter.toJSON(); doTest(); req.suggest("global suggest text");