From e9d1fc7b1a4f72f156ef5cf80f13caa66417a5ce Mon Sep 17 00:00:00 2001 From: Rashid Khan Date: Fri, 5 Apr 2013 12:11:47 -0700 Subject: [PATCH] Updated elastic.js, improved error text on table --- common/lib/elastic-angular-client.js | 7 +- common/lib/elastic-angular-client.min.js | 4 +- common/lib/elastic.js | 3643 +++++++++++++++++----- common/lib/elastic.min.js | 4 +- js/app.js | 2 +- js/controllers.js | 5 + panels/table/module.js | 6 +- 7 files changed, 2840 insertions(+), 831 deletions(-) diff --git a/common/lib/elastic-angular-client.js b/common/lib/elastic-angular-client.js index a3811909ec2..8b917b9010f 100644 --- a/common/lib/elastic-angular-client.js +++ b/common/lib/elastic-angular-client.js @@ -1,9 +1,10 @@ -/*! elastic.js - v1.0.0 - 2013-01-15 +/*! elastic.js - v1.0.0 - 2013-03-05 * https://github.com/fullscale/elastic.js * Copyright (c) 2013 FullScale Labs, LLC; Licensed MIT */ /*jshint browser:true */ /*global angular:true */ +/*jshint es5:true */ 'use strict'; /* @@ -26,8 +27,8 @@ angular.module('elasticjs.service', []) (successcb || angular.noop)(response.data); return response.data; }, function (response) { - (errorcb || angular.noop)(undefined); - return undefined; + (errorcb || angular.noop)(response.data); + return response.data; }); }; diff --git a/common/lib/elastic-angular-client.min.js b/common/lib/elastic-angular-client.min.js index a88c594c820..b211728794c 100644 --- a/common/lib/elastic-angular-client.min.js +++ b/common/lib/elastic-angular-client.min.js @@ -1,4 +1,4 @@ -/*! elastic.js - v1.0.0 - 2013-01-15 +/*! elastic.js - v1.0.0 - 2013-03-05 * https://github.com/fullscale/elastic.js * Copyright (c) 2013 FullScale Labs, LLC; Licensed MIT */ -"use strict";angular.module("elasticjs.service",[]).factory("ejsResource",["$http",function(e){return function(t){var n=window.ejs||{},r=function(e,t,n){return e.then(function(e){return(t||angular.noop)(e.data),e.data},function(e){return(n||angular.noop)(undefined),undefined})};return t==null&&(t=""),n.client={server:function(e){return e==null?t:(t=e,this)},post:function(n,i,s,o){return n=t+n,r(e.post(n,i),s,o)},get:function(n,i,s,o){return n=t+n,r(e.get(n,i),s,o)},put:function(n,i,s,o){return n=t+n,r(e.put(n,i),s,o)},del:function(n,i,s,o){return n=t+n,r(e.delete(n,i),s,o)},head:function(n,r,i,s){return n=t+n,e.head(n,r).then(function(e){return(i||angular.noop)(e.headers()),e.headers()},function(e){return(s||angular.noop)(undefined),undefined})}},n}}]); +"use strict";angular.module("elasticjs.service",[]).factory("ejsResource",["$http",function(e){return function(t){var n=window.ejs||{},r=function(e,t,n){return e.then(function(e){return(t||angular.noop)(e.data),e.data},function(e){return(n||angular.noop)(undefined),undefined})};return t==null&&(t=""),n.client={server:function(e){return e==null?t:(t=e,this)},post:function(n,i,s,o){return n=t+n,r(e.post(n,i),s,o)},get:function(n,i,s,o){return n=t+n,r(e.get(n,i),s,o)},put:function(n,i,s,o){return n=t+n,r(e.put(n,i),s,o)},del:function(n,i,s,o){return n=t+n,r(e.delete(n,i),s,o)},head:function(n,r,i,s){return n=t+n,e.head(n,r).then(function(e){return(i||angular.noop)(e.headers()),e.headers()},function(e){return(s||angular.noop)(undefined),undefined})}},n}}]); \ No newline at end of file diff --git a/common/lib/elastic.js b/common/lib/elastic.js index 7c2b6385f09..33bf1f08e2d 100644 --- a/common/lib/elastic.js +++ b/common/lib/elastic.js @@ -1,4 +1,4 @@ -/*! elastic.js - v1.0.0 - 2013-01-15 +/*! elastic.js - v1.0.0 - 2013-04-04 * https://github.com/fullscale/elastic.js * Copyright (c) 2013 FullScale Labs, LLC; Licensed MIT */ @@ -47,6 +47,8 @@ isShape, // checks valid ejs Shape object isSort, // checks valid ejs Sort object isHighlight, // checks valid ejs Highlight object + isSuggest, // checks valid ejs Suggest object + isGenerator, // checks valid ejs Generator object // create ejs object ejs; @@ -179,6 +181,14 @@ return (isEJSObject(obj) && obj._type() === 'highlight'); }; + isSuggest = function (obj) { + return (isEJSObject(obj) && obj._type() === 'suggest'); + }; + + isGenerator = function (obj) { + return (isEJSObject(obj) && obj._type() === 'generator'); + }; + /** @class

The DateHistogram facet works with time-based values by building a histogram across time @@ -290,13 +300,14 @@ }, /** - By default, time values are stored in UTC format. This method allows users - to set a time zone value that is then used to compute intervals - before rounding on the interval value. Equalivent to - preZone. Use preZone if possible. The - value is an offset from UTC. +

By default, time values are stored in UTC format.

+ +

This method allows users to set a time zone value that is then used + to compute intervals before rounding on the interval value. Equalivent to + preZone. Use preZone if possible. The + value is an offset from UTC.

- For example, to use EST you would set the value to -5. +

For example, to use EST you would set the value to -5.

@member ejs.DateHistogramFacet @param {Integer} tz An offset value from UTC. @@ -312,12 +323,13 @@ }, /** - By default, time values are stored in UTC format. This method allows users - to set a time zone value that is then used to compute intervals - before rounding on the interval value. The value is an offset - from UTC. +

By default, time values are stored in UTC format.

+ +

This method allows users to set a time zone value that is then used to + compute intervals before rounding on the interval value. The value is an + offset from UTC.

- For example, to use EST you would set the value to -5. +

For example, to use EST you would set the value to -5.

@member ejs.DateHistogramFacet @param {Integer} tz An offset value from UTC. @@ -333,9 +345,10 @@ }, /** - Enables large date interval conversions (day and up). Set to - true to enable and then set the interval to an - interval greater than a day. +

Enables large date interval conversions (day and up).

+ +

Set to true to enable and then set the interval to an + interval greater than a day.

@member ejs.DateHistogramFacet @param {Boolean} trueFalse A valid boolean value. @@ -351,13 +364,13 @@ }, /** - By default, time values are stored in UTC format. This method allows users - to set a time zone value that is then used to compute intervals - after rounding on the interval value. The value is an offset - from UTC. The tz offset value is simply added to the resulting - bucket's date value. +

By default, time values are stored in UTC format.

+ +

This method allows users to set a time zone value that is then used to compute + intervals after rounding on the interval value. The value is an offset from UTC. + The tz offset value is simply added to the resulting bucket's date value.

- For example, to use EST you would set the value to -5. +

For example, to use EST you would set the value to -5.

@member ejs.DateHistogramFacet @param {Integer} tz An offset value from UTC. @@ -405,14 +418,16 @@ }, /** - The date histogram works on numeric values (since time is stored - in milliseconds since the epoch in UTC). But, sometimes, systems - will store a different resolution (like seconds since UTC) in a - numeric field. The factor parameter can be used to change the - value in the field to milliseconds to actual do the relevant - rounding, and then be applied again to get to the original unit. - For example, when storing in a numeric field seconds resolution, - the factor can be set to 1000. +

The date histogram works on numeric values (since time is stored + in milliseconds since the epoch in UTC).

+ +

But, sometimes, systems will store a different resolution (like seconds since UTC) + in a numeric field. The factor parameter can be used to change the value in the field + to milliseconds to actual do the relevant rounding, and then be applied again to get to + the original unit.

+ +

For example, when storing in a numeric field seconds resolution, + the factor can be set to 1000.

@member ejs.DateHistogramFacet @param {Integer} f The conversion factor. @@ -445,12 +460,14 @@ }, /** - Sets the type of ordering that will be performed on the date - buckets. Valid values are: +

Sets the type of ordering that will be performed on the date + buckets. Valid values are:

- time - the default, sort by the buckets start time in milliseconds. - count - sort by the number of items in the bucket - total - sort by the sum/total of the items in the bucket +

+
time - the default, sort by the buckets start time in milliseconds.
+
count - sort by the number of items in the bucket
+
total - sort by the sum/total of the items in the bucket
+
@member ejs.DateHistogramFacet @param {String} o The ordering method: time, count, or total. @@ -539,20 +556,41 @@ facet[name].global = trueFalse; return this; }, + + /** +

Sets the mode the facet will use.

+ +

+
collector
+
post
+
+ + @member ejs.DateHistogramFacet + @param {String} m The mode: collector or post. + @returns {Object} returns this so that calls can be chained. + */ + mode: function (m) { + if (m == null) { + return facet[name].mode; + } + m = m.toLowerCase(); + if (m === 'collector' || m === 'post') { + facet[name].mode = m; + } + + return this; + }, + /**

Computes values across the the specified scope

+ @deprecated since elasticsearch 0.90 @member ejs.DateHistogramFacet @param {String} scope The scope name to calculate facet counts with. @returns {Object} returns this so that calls can be chained. */ scope: function (scope) { - if (scope == null) { - return facet[name].scope; - } - - facet[name].scope = scope; return this; }, @@ -719,19 +757,40 @@ return this; }, + /** +

Sets the mode the facet will use.

+ +

+
collector
+
post
+
+ + @member ejs.FilterFacet + @param {String} m The mode: collector or post. + @returns {Object} returns this so that calls can be chained. + */ + mode: function (m) { + if (m == null) { + return facet[name].mode; + } + + m = m.toLowerCase(); + if (m === 'collector' || m === 'post') { + facet[name].mode = m; + } + + return this; + }, + /**

Computes values across the the specified scope

+ @deprecated since elasticsearch 0.90 @member ejs.FilterFacet @param {String} scope The scope name to calculate facet counts with. @returns {Object} returns this so that calls can be chained. */ scope: function (scope) { - if (scope == null) { - return facet[name].scope; - } - - facet[name].scope = scope; return this; }, @@ -1120,19 +1179,40 @@ return this; }, + /** +

Sets the mode the facet will use.

+ +

+
collector
+
post
+
+ + @member ejs.GeoDistanceFacet + @param {String} m The mode: collector or post. + @returns {Object} returns this so that calls can be chained. + */ + mode: function (m) { + if (m == null) { + return facet[name].mode; + } + + m = m.toLowerCase(); + if (m === 'collector' || m === 'post') { + facet[name].mode = m; + } + + return this; + }, + /**

Computes values across the the specified scope

+ @deprecated since elasticsearch 0.90 @member ejs.GeoDistanceFacet @param {String} scope The scope name to calculate facet counts with. @returns {Object} returns this so that calls can be chained. */ scope: function (scope) { - if (scope == null) { - return facet[name].scope; - } - - facet[name].scope = scope; return this; }, @@ -1497,19 +1577,40 @@ return this; }, + /** +

Sets the mode the facet will use.

+ +

+
collector
+
post
+
+ + @member ejs.HistogramFacet + @param {String} m The mode: collector or post. + @returns {Object} returns this so that calls can be chained. + */ + mode: function (m) { + if (m == null) { + return facet[name].mode; + } + + m = m.toLowerCase(); + if (m === 'collector' || m === 'post') { + facet[name].mode = m; + } + + return this; + }, + /**

Computes values across the the specified scope

+ @deprecated since elasticsearch 0.90 @member ejs.HistogramFacet @param {String} scope The scope name to calculate facet counts with. @returns {Object} returns this so that calls can be chained. */ scope: function (scope) { - if (scope == null) { - return facet[name].scope; - } - - facet[name].scope = scope; return this; }, @@ -1676,19 +1777,40 @@ return this; }, + /** +

Sets the mode the facet will use.

+ +

+
collector
+
post
+
+ + @member ejs.QueryFacet + @param {String} m The mode: collector or post. + @returns {Object} returns this so that calls can be chained. + */ + mode: function (m) { + if (m == null) { + return facet[name].mode; + } + + m = m.toLowerCase(); + if (m === 'collector' || m === 'post') { + facet[name].mode = m; + } + + return this; + }, + /**

Computes values across the the specified scope

+ @deprecated since elasticsearch 0.90 @member ejs.QueryFacet @param {String} scope The scope name to calculate facet counts with. @returns {Object} returns this so that calls can be chained. */ scope: function (scope) { - if (scope == null) { - return facet[name].scope; - } - - facet[name].scope = scope; return this; }, @@ -2016,19 +2138,40 @@ return this; }, + /** +

Sets the mode the facet will use.

+ +

+
collector
+
post
+
+ + @member ejs.RangeFacet + @param {String} m The mode: collector or post. + @returns {Object} returns this so that calls can be chained. + */ + mode: function (m) { + if (m == null) { + return facet[name].mode; + } + + m = m.toLowerCase(); + if (m === 'collector' || m === 'post') { + facet[name].mode = m; + } + + return this; + }, + /**

Computes values across the the specified scope

+ @deprecated since elasticsearch 0.90 @member ejs.RangeFacet @param {String} scope The scope name to calculate facet counts with. @returns {Object} returns this so that calls can be chained. */ scope: function (scope) { - if (scope == null) { - return facet[name].scope; - } - - facet[name].scope = scope; return this; }, @@ -2264,19 +2407,40 @@ return this; }, + /** +

Sets the mode the facet will use.

+ +

+
collector
+
post
+
+ + @member ejs.StatisticalFacet + @param {String} m The mode: collector or post. + @returns {Object} returns this so that calls can be chained. + */ + mode: function (m) { + if (m == null) { + return facet[name].mode; + } + + m = m.toLowerCase(); + if (m === 'collector' || m === 'post') { + facet[name].mode = m; + } + + return this; + }, + /**

Computes values across the the specified scope

+ @deprecated since elasticsearch 0.90 @member ejs.StatisticalFacet @param {String} scope The scope name to calculate facet counts with. @returns {Object} returns this so that calls can be chained. */ scope: function (scope) { - if (scope == null) { - return facet[name].scope; - } - - facet[name].scope = scope; return this; }, @@ -2348,23 +2512,26 @@ /** @class -

A facet which returns the N most frequent terms within a collection - or set of collections. Term facets are useful for building constructs - which allow users to refine search results by filtering on terms returned - by the facet.

+

A termsStatsFacet allows you to compute statistics over an aggregate key (term). Essentially this + facet provides the functionality of what is often refered to as a pivot table.

Facets are similar to SQL GROUP BY statements but perform much better. You can also construct several "groups" at once by simply specifying multiple facets.

-

For more information on faceted navigation, see this Wikipedia article on - Faceted Classification +

+ Tip: + For more information on faceted navigation, see + this + Wikipedia article on Faceted Classification. +

+ - @name ejs.TermsFacet + @name ejs.TermStatsFacet @desc -

A facet which returns the N most frequent terms within a collection - or set of collections.

+

A facet which computes statistical data based on an aggregate key.

@param {String} name The name which be used to refer to this facet. For instance, the facet itself might utilize a field named doc_authors. Setting @@ -2372,118 +2539,83 @@ facet by that name, possibly simplifying some of the display logic. */ - ejs.TermsFacet = function (name) { + ejs.TermStatsFacet = function (name) { /** The internal facet object. - @member ejs.TermsFacet + @member ejs.TermStatsFacet @property {Object} facet */ var facet = {}; facet[name] = { - terms: {} + terms_stats: {} }; return { /** - Sets the field to be used to construct the this facet. Set to - _index to return a facet count of hits per _index the search was - executed on. + Sets the field for which statistical information will be generated. - @member ejs.TermsFacet + @member ejs.TermStatsFacet @param {String} fieldName The field name whose data will be used to construct the facet. @returns {Object} returns this so that calls can be chained. */ - field: function (fieldName) { + valueField: function (fieldName) { if (fieldName == null) { - return facet[name].terms.field; + return facet[name].terms_stats.value_field; } - facet[name].terms.field = fieldName; + facet[name].terms_stats.value_field = fieldName; return this; }, /** - Aggregate statistical info across a set of fields. + Sets the field which will be used to pivot on (group-by). - @member ejs.TermsFacet - @param {Array} aFieldName An array of field names. + @member ejs.TermStatsFacet + @param {String} fieldName The field name whose data will be used to construct the facet. @returns {Object} returns this so that calls can be chained. */ - fields: function (fields) { - if (fields == null) { - return facet[name].terms.fields; + keyField: function (fieldName) { + if (fieldName == null) { + return facet[name].terms_stats.key_field; } - if (!isArray(fields)) { - throw new TypeError('Argument must be an array'); - } - - facet[name].terms.fields = fields; + facet[name].terms_stats.key_field = fieldName; return this; }, /** Sets a script that will provide the terms for a given document. - @member ejs.TermsFacet + @member ejs.TermStatsFacet @param {String} script The script code. @returns {Object} returns this so that calls can be chained. */ scriptField: function (script) { if (script == null) { - return facet[name].terms.script_field; + return facet[name].terms_stats.script_field; } - facet[name].terms.script_field = script; + facet[name].terms_stats.script_field = script; return this; }, - - /** - Sets the number of facet entries that will be returned for this facet. For instance, you - might ask for only the top 5 authors although there might be hundreds of - unique authors. - - @member ejs.TermsFacet - @param {Integer} facetSize The numer of facet entries to be returned. - @returns {Object} returns this so that calls can be chained. - */ - size: function (facetSize) { - if (facetSize == null) { - return facet[name].terms.size; - } - facet[name].terms.size = facetSize; - return this; - }, - /** - Sets the type of ordering that will be performed on the date - buckets. Valid values are: - - count - default, sort by the number of items in the bucket - term - sort by term value. - reverse_count - reverse sort of the number of items in the bucket - reverse_term - reverse sort of the term value. - - @member ejs.TermsFacet - @param {String} o The ordering method + Define a script to evaluate of which the result will be used to generate + the statistical information. + + @member ejs.TermStatsFacet + @param {String} code The script code to execute. @returns {Object} returns this so that calls can be chained. */ - order: function (o) { - if (o == null) { - return facet[name].terms.order; + valueScript: function (code) { + if (code == null) { + return facet[name].terms_stats.value_script; } - o = o.toLowerCase(); - if (o === 'count' || o === 'term' || - o === 'reverse_count' || o === 'reverse_term') { - - facet[name].terms.order = o; - } - + facet[name].terms_stats.value_script = code; return this; }, @@ -2492,155 +2624,112 @@ used on fields that contain a large number of unique terms because it could cause out-of-memory errors.

- @member ejs.TermsFacet + @member ejs.TermStatsFacet @param {String} trueFalse true or false @returns {Object} returns this so that calls can be chained. */ allTerms: function (trueFalse) { if (trueFalse == null) { - return facet[name].terms.all_terms; + return facet[name].terms_stats.all_terms; } - facet[name].terms.all_terms = trueFalse; + facet[name].terms_stats.all_terms = trueFalse; return this; }, - + /** -

Allows you to filter out unwanted facet entries. When passed - a single term, it is appended to the list of currently excluded - terms. If passed an array, it overwrites all existing values.

+ The script language being used. Currently supported values are + javascript, groovy, and mvel. - @member ejs.TermsFacet - @param {String || Array} exclude A single term to exclude or an - array of terms to exclude. - @returns {Object} returns this so that calls can be chained. - */ - exclude: function (exclude) { - if (facet[name].terms.exclude == null) { - facet[name].terms.exclude = []; - } - - if (exclude == null) { - return facet[name].terms.exclude; - } - - if (isString(exclude)) { - facet[name].terms.exclude.push(exclude); - } else if (isArray(exclude)) { - facet[name].terms.exclude = exclude; - } else { - throw new TypeError('Argument must be string or array'); - } - - return this; - }, - - /** -

Allows you to only include facet entries matching a specified regular expression.

- - @member ejs.TermsFacet - @param {String} exp A valid regular expression. + @member ejs.TermStatsFacet + @param {String} language The language of the script. @returns {Object} returns this so that calls can be chained. */ - regex: function (exp) { - if (exp == null) { - return facet[name].terms.regex; + lang: function (language) { + if (language == null) { + return facet[name].terms_stats.lang; } - facet[name].terms.regex = exp; + facet[name].terms_stats.lang = language; return this; }, /** -

Allows you to set the regular expression flags to be used - with the regex

+ Allows you to set script parameters to be used during the execution of the script. - @member ejs.TermsFacet - @param {String} flags A valid regex flag - see Java Pattern API + @member ejs.TermStatsFacet + @param {Object} oParams An object containing key/value pairs representing param name/value. @returns {Object} returns this so that calls can be chained. */ - regexFlags: function (flags) { - if (flags == null) { - return facet[name].terms.regex_flags; + params: function (oParams) { + if (oParams == null) { + return facet[name].terms_stats.params; } - facet[name].terms.regex_flags = flags; + facet[name].terms_stats.params = oParams; return this; }, /** - Allows you modify the term using a script. The modified value - is then used in the facet collection. + Sets the number of facet entries that will be returned for this facet. For instance, you + might ask for only the top 5 aggregate keys although there might be hundreds of + unique keys. Higher settings could cause memory strain. - @member ejs.TermsFacet - @param {String} scriptCode A valid script string to execute. + @member ejs.TermStatsFacet + @param {Integer} facetSize The numer of facet entries to be returned. @returns {Object} returns this so that calls can be chained. */ - script: function (scriptCode) { - if (scriptCode == null) { - return facet[name].terms.script; + size: function (facetSize) { + if (facetSize == null) { + return facet[name].terms_stats.size; } - facet[name].terms.script = scriptCode; + facet[name].terms_stats.size = facetSize; return this; }, /** - The script language being used. Currently supported values are - javascript, groovy, and mvel. - - @member ejs.TermsFacet - @param {String} language The language of the script. + Sets the type of ordering that will be performed on the date + buckets. Valid values are: + + count - default, sort by the number of items in the bucket + term - sort by term value. + reverse_count - reverse sort of the number of items in the bucket + reverse_term - reverse sort of the term value. + total - sorts by the total value of the bucket contents + reverse_total - reverse sort of the total value of bucket contents + min - the minimum value in the bucket + reverse_min - the reverse sort of the minimum value + max - the maximum value in the bucket + reverse_max - the reverse sort of the maximum value + mean - the mean value of the bucket contents + reverse_mean - the reverse sort of the mean value of bucket contents. + + @member ejs.TermStatsFacet + @param {String} o The ordering method @returns {Object} returns this so that calls can be chained. */ - lang: function (language) { - if (language == null) { - return facet[name].terms.lang; + order: function (o) { + if (o == null) { + return facet[name].terms_stats.order; } - facet[name].terms.lang = language; - return this; - }, - - /** - Sets parameters that will be applied to the script. Overwrites - any existing params. - - @member ejs.TermsFacet - @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 facet[name].terms.params; + o = o.toLowerCase(); + if (o === 'count' || o === 'term' || o === 'reverse_count' || + o === 'reverse_term' || o === 'total' || o === 'reverse_total' || + o === 'min' || o === 'reverse_min' || o === 'max' || + o === 'reverse_max' || o === 'mean' || o === 'reverse_mean') { + + facet[name].terms_stats.order = o; } - - facet[name].terms.params = p; + return this; }, - - /** - Sets the execution hint determines how the facet is computed. - Currently only supported value is "map". - @member ejs.TermsFacet - @param {Object} h The hint value as a string. - @returns {Object} returns this so that calls can be chained. - */ - executionHint: function (h) { - if (h == null) { - return facet[name].terms.execution_hint; - } - - facet[name].terms.execution_hint = h; - return this; - }, - /**

Allows you to reduce the documents used for computing facet results.

- @member ejs.TermsFacet + @member ejs.TermStatsFacet @param {Object} oFilter A valid Filter object. @returns {Object} returns this so that calls can be chained. */ @@ -2660,7 +2749,7 @@ /**

Computes values across the entire index

- @member ejs.TermsFacet + @member ejs.TermStatsFacet @param {Boolean} trueFalse Calculate facet counts globally or not. @returns {Object} returns this so that calls can be chained. */ @@ -2673,26 +2762,47 @@ return this; }, + /** +

Sets the mode the facet will use.

+ +

+
collector
+
post
+
+ + @member ejs.TermStatsFacet + @param {String} m The mode: collector or post. + @returns {Object} returns this so that calls can be chained. + */ + mode: function (m) { + if (m == null) { + return facet[name].mode; + } + + m = m.toLowerCase(); + if (m === 'collector' || m === 'post') { + facet[name].mode = m; + } + + return this; + }, + /**

Computes values across the the specified scope

- @member ejs.TermsFacet + @deprecated since elasticsearch 0.90 + @member ejs.TermStatsFacet @param {String} scope The scope name to calculate facet counts with. @returns {Object} returns this so that calls can be chained. */ scope: function (scope) { - if (scope == null) { - return facet[name].scope; - } - - facet[name].scope = scope; return this; }, /**

Enables caching of the facetFilter

- @member ejs.TermsFacet + @member ejs.TermStatsFacet @param {Boolean} trueFalse If the facetFilter should be cached or not @returns {Object} returns this so that calls can be chained. */ @@ -2709,7 +2819,7 @@

Sets the path to the nested document if faceting against a nested field.

- @member ejs.TermsFacet + @member ejs.TermStatsFacet @param {String} path The nested path @returns {Object} returns this so that calls can be chained. */ @@ -2725,7 +2835,7 @@ /**

Allows you to serialize this object into a JSON encoded string.

- @member ejs.TermsFacet + @member ejs.TermStatsFacet @returns {String} returns this object as a serialized JSON string. */ toString: function () { @@ -2735,7 +2845,7 @@ /** The type of ejs object. For internal use only. - @member ejs.TermsFacet + @member ejs.TermStatsFacet @returns {String} the type of object */ _type: function () { @@ -2743,10 +2853,10 @@ }, /** -

Retrieves the internal facet property. This is typically used by +

Retrieves the internal facet object. This is typically used by internal API functions so use with caution.

- @member ejs.TermsFacet + @member ejs.TermStatsFacet @returns {String} returns this object's internal facet property. */ _self: function () { @@ -2757,26 +2867,23 @@ /** @class -

A termsStatsFacet allows you to compute statistics over an aggregate key (term). Essentially this - facet provides the functionality of what is often refered to as a pivot table.

+

A facet which returns the N most frequent terms within a collection + or set of collections. Term facets are useful for building constructs + which allow users to refine search results by filtering on terms returned + by the facet.

Facets are similar to SQL GROUP BY statements but perform much better. You can also construct several "groups" at once by simply specifying multiple facets.

-
-

- Tip: - For more information on faceted navigation, see - this - Wikipedia article on Faceted Classification. -

-
+

For more information on faceted navigation, see this Wikipedia article on + Faceted ClassificationA facet which computes statistical data based on an aggregate key.

+

A facet which returns the N most frequent terms within a collection + or set of collections.

@param {String} name The name which be used to refer to this facet. For instance, the facet itself might utilize a field named doc_authors. Setting @@ -2784,83 +2891,118 @@ facet by that name, possibly simplifying some of the display logic. */ - ejs.TermStatsFacet = function (name) { + ejs.TermsFacet = function (name) { /** The internal facet object. - @member ejs.TermStatsFacet + @member ejs.TermsFacet @property {Object} facet */ var facet = {}; facet[name] = { - terms_stats: {} + terms: {} }; return { /** - Sets the field for which statistical information will be generated. + Sets the field to be used to construct the this facet. Set to + _index to return a facet count of hits per _index the search was + executed on. - @member ejs.TermStatsFacet + @member ejs.TermsFacet @param {String} fieldName The field name whose data will be used to construct the facet. @returns {Object} returns this so that calls can be chained. */ - valueField: function (fieldName) { + field: function (fieldName) { if (fieldName == null) { - return facet[name].terms_stats.value_field; + return facet[name].terms.field; } - facet[name].terms_stats.value_field = fieldName; + facet[name].terms.field = fieldName; return this; }, /** - Sets the field which will be used to pivot on (group-by). + Aggregate statistical info across a set of fields. - @member ejs.TermStatsFacet - @param {String} fieldName The field name whose data will be used to construct the facet. + @member ejs.TermsFacet + @param {Array} aFieldName An array of field names. @returns {Object} returns this so that calls can be chained. */ - keyField: function (fieldName) { - if (fieldName == null) { - return facet[name].terms_stats.key_field; + fields: function (fields) { + if (fields == null) { + return facet[name].terms.fields; } - facet[name].terms_stats.key_field = fieldName; + if (!isArray(fields)) { + throw new TypeError('Argument must be an array'); + } + + facet[name].terms.fields = fields; return this; }, /** Sets a script that will provide the terms for a given document. - @member ejs.TermStatsFacet + @member ejs.TermsFacet @param {String} script The script code. @returns {Object} returns this so that calls can be chained. */ scriptField: function (script) { if (script == null) { - return facet[name].terms_stats.script_field; + return facet[name].terms.script_field; } - facet[name].terms_stats.script_field = script; + facet[name].terms.script_field = script; return this; }, - + /** - Define a script to evaluate of which the result will be used to generate - the statistical information. + Sets the number of facet entries that will be returned for this facet. For instance, you + might ask for only the top 5 authors although there might be hundreds of + unique authors. - @member ejs.TermStatsFacet - @param {String} code The script code to execute. + @member ejs.TermsFacet + @param {Integer} facetSize The numer of facet entries to be returned. @returns {Object} returns this so that calls can be chained. */ - valueScript: function (code) { - if (code == null) { - return facet[name].terms_stats.value_script; + size: function (facetSize) { + if (facetSize == null) { + return facet[name].terms.size; } - facet[name].terms_stats.value_script = code; + facet[name].terms.size = facetSize; + return this; + }, + + /** + Sets the type of ordering that will be performed on the date + buckets. Valid values are: + + count - default, sort by the number of items in the bucket + term - sort by term value. + reverse_count - reverse sort of the number of items in the bucket + reverse_term - reverse sort of the term value. + + @member ejs.TermsFacet + @param {String} o The ordering method + @returns {Object} returns this so that calls can be chained. + */ + order: function (o) { + if (o == null) { + return facet[name].terms.order; + } + + o = o.toLowerCase(); + if (o === 'count' || o === 'term' || + o === 'reverse_count' || o === 'reverse_term') { + + facet[name].terms.order = o; + } + return this; }, @@ -2869,112 +3011,155 @@ used on fields that contain a large number of unique terms because it could cause out-of-memory errors.

- @member ejs.TermStatsFacet + @member ejs.TermsFacet @param {String} trueFalse true or false @returns {Object} returns this so that calls can be chained. */ allTerms: function (trueFalse) { if (trueFalse == null) { - return facet[name].terms_stats.all_terms; + return facet[name].terms.all_terms; } - facet[name].terms_stats.all_terms = trueFalse; + facet[name].terms.all_terms = trueFalse; return this; }, + + /** +

Allows you to filter out unwanted facet entries. When passed + a single term, it is appended to the list of currently excluded + terms. If passed an array, it overwrites all existing values.

+ + @member ejs.TermsFacet + @param {String || Array} exclude A single term to exclude or an + array of terms to exclude. + @returns {Object} returns this so that calls can be chained. + */ + exclude: function (exclude) { + if (facet[name].terms.exclude == null) { + facet[name].terms.exclude = []; + } + + if (exclude == null) { + return facet[name].terms.exclude; + } + if (isString(exclude)) { + facet[name].terms.exclude.push(exclude); + } else if (isArray(exclude)) { + facet[name].terms.exclude = exclude; + } else { + throw new TypeError('Argument must be string or array'); + } + + return this; + }, + /** - The script language being used. Currently supported values are - javascript, groovy, and mvel. +

Allows you to only include facet entries matching a specified regular expression.

- @member ejs.TermStatsFacet - @param {String} language The language of the script. + @member ejs.TermsFacet + @param {String} exp A valid regular expression. @returns {Object} returns this so that calls can be chained. */ - lang: function (language) { - if (language == null) { - return facet[name].terms_stats.lang; + regex: function (exp) { + if (exp == null) { + return facet[name].terms.regex; } - facet[name].terms_stats.lang = language; + facet[name].terms.regex = exp; return this; }, /** - Allows you to set script parameters to be used during the execution of the script. +

Allows you to set the regular expression flags to be used + with the regex

- @member ejs.TermStatsFacet - @param {Object} oParams An object containing key/value pairs representing param name/value. + @member ejs.TermsFacet + @param {String} flags A valid regex flag - see Java Pattern API @returns {Object} returns this so that calls can be chained. */ - params: function (oParams) { - if (oParams == null) { - return facet[name].terms_stats.params; + regexFlags: function (flags) { + if (flags == null) { + return facet[name].terms.regex_flags; } - facet[name].terms_stats.params = oParams; + facet[name].terms.regex_flags = flags; return this; }, /** - Sets the number of facet entries that will be returned for this facet. For instance, you - might ask for only the top 5 aggregate keys although there might be hundreds of - unique keys. Higher settings could cause memory strain. + Allows you modify the term using a script. The modified value + is then used in the facet collection. - @member ejs.TermStatsFacet - @param {Integer} facetSize The numer of facet entries to be returned. + @member ejs.TermsFacet + @param {String} scriptCode A valid script string to execute. @returns {Object} returns this so that calls can be chained. */ - size: function (facetSize) { - if (facetSize == null) { - return facet[name].terms_stats.size; + script: function (scriptCode) { + if (scriptCode == null) { + return facet[name].terms.script; } - facet[name].terms_stats.size = facetSize; + facet[name].terms.script = scriptCode; return this; }, /** - Sets the type of ordering that will be performed on the date - buckets. Valid values are: - - count - default, sort by the number of items in the bucket - term - sort by term value. - reverse_count - reverse sort of the number of items in the bucket - reverse_term - reverse sort of the term value. - total - sorts by the total value of the bucket contents - reverse_total - reverse sort of the total value of bucket contents - min - the minimum value in the bucket - reverse_min - the reverse sort of the minimum value - max - the maximum value in the bucket - reverse_max - the reverse sort of the maximum value - mean - the mean value of the bucket contents - reverse_mean - the reverse sort of the mean value of bucket contents. - - @member ejs.TermStatsFacet - @param {String} o The ordering method + The script language being used. Currently supported values are + javascript, groovy, and mvel. + + @member ejs.TermsFacet + @param {String} language The language of the script. @returns {Object} returns this so that calls can be chained. */ - order: function (o) { - if (o == null) { - return facet[name].terms_stats.order; + lang: function (language) { + if (language == null) { + return facet[name].terms.lang; } - o = o.toLowerCase(); - if (o === 'count' || o === 'term' || o === 'reverse_count' || - o === 'reverse_term' || o === 'total' || o === 'reverse_total' || - o === 'min' || o === 'reverse_min' || o === 'max' || - o === 'reverse_max' || o === 'mean' || o === 'reverse_mean') { - - facet[name].terms_stats.order = o; + facet[name].terms.lang = language; + return this; + }, + + /** + Sets parameters that will be applied to the script. Overwrites + any existing params. + + @member ejs.TermsFacet + @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 facet[name].terms.params; } - + + facet[name].terms.params = p; return this; }, + + /** + Sets the execution hint determines how the facet is computed. + Currently only supported value is "map". + @member ejs.TermsFacet + @param {Object} h The hint value as a string. + @returns {Object} returns this so that calls can be chained. + */ + executionHint: function (h) { + if (h == null) { + return facet[name].terms.execution_hint; + } + + facet[name].terms.execution_hint = h; + return this; + }, + /**

Allows you to reduce the documents used for computing facet results.

- @member ejs.TermStatsFacet + @member ejs.TermsFacet @param {Object} oFilter A valid Filter object. @returns {Object} returns this so that calls can be chained. */ @@ -2994,7 +3179,7 @@ /**

Computes values across the entire index

- @member ejs.TermStatsFacet + @member ejs.TermsFacet @param {Boolean} trueFalse Calculate facet counts globally or not. @returns {Object} returns this so that calls can be chained. */ @@ -3007,26 +3192,47 @@ return this; }, + /** +

Sets the mode the facet will use.

+ +

+
collector
+
post
+
+ + @member ejs.TermsFacet + @param {String} m The mode: collector or post. + @returns {Object} returns this so that calls can be chained. + */ + mode: function (m) { + if (m == null) { + return facet[name].mode; + } + + m = m.toLowerCase(); + if (m === 'collector' || m === 'post') { + facet[name].mode = m; + } + + return this; + }, + /**

Computes values across the the specified scope

- @member ejs.TermStatsFacet + @deprecated since elasticsearch 0.90 + @member ejs.TermsFacet @param {String} scope The scope name to calculate facet counts with. @returns {Object} returns this so that calls can be chained. */ scope: function (scope) { - if (scope == null) { - return facet[name].scope; - } - - facet[name].scope = scope; return this; }, /**

Enables caching of the facetFilter

- @member ejs.TermStatsFacet + @member ejs.TermsFacet @param {Boolean} trueFalse If the facetFilter should be cached or not @returns {Object} returns this so that calls can be chained. */ @@ -3043,7 +3249,7 @@

Sets the path to the nested document if faceting against a nested field.

- @member ejs.TermStatsFacet + @member ejs.TermsFacet @param {String} path The nested path @returns {Object} returns this so that calls can be chained. */ @@ -3059,7 +3265,7 @@ /**

Allows you to serialize this object into a JSON encoded string.

- @member ejs.TermStatsFacet + @member ejs.TermsFacet @returns {String} returns this object as a serialized JSON string. */ toString: function () { @@ -3069,7 +3275,7 @@ /** The type of ejs object. For internal use only. - @member ejs.TermStatsFacet + @member ejs.TermsFacet @returns {String} the type of object */ _type: function () { @@ -3077,10 +3283,10 @@ }, /** -

Retrieves the internal facet object. This is typically used by +

Retrieves the internal facet property. This is typically used by internal API functions so use with caution.

- @member ejs.TermStatsFacet + @member ejs.TermsFacet @returns {String} returns this object's internal facet property. */ _self: function () { @@ -4740,7 +4946,40 @@ return this; }, - + + /** +

Sets the spatial strategy.

+

Valid values are:

+ +
+
recursive - default, recursively traverse nodes in + the spatial prefix tree. This strategy has support for + searching non-point shapes.
+
term - uses a large TermsFilter on each node + in the spatial prefix tree. It only supports the search of + indexed Point shapes.
+
+ +

This is an advanced setting, use with care.

+ + @since elasticsearch 0.90 + @member ejs.GeoShapeFilter + @param {String} strategy The strategy as a string. + @returns {Object} returns this so that calls can be chained. + */ + strategy: function (strategy) { + if (strategy == null) { + return filter.geo_shape[field].strategy; + } + + strategy = strategy.toLowerCase(); + if (strategy === 'recursive' || strategy === 'term') { + filter.geo_shape[field].strategy = strategy; + } + + return this; + }, + /** Sets the filter name. @@ -4876,35 +5115,52 @@ }, /** - Sets the child document type to search against + Sets the filter + @since elasticsearch 0.90 @member ejs.HasChildFilter - @param {String} t A valid type name + @param {Query} f A valid Filter object @returns {Object} returns this so that calls can be chained. */ - type: function (t) { - if (t == null) { - return filter.has_child.type; + filter: function (f) { + if (f == null) { + return filter.has_child.filter; } - filter.has_child.type = t; + if (!isFilter(f)) { + throw new TypeError('Argument must be a Filter object'); + } + + filter.has_child.filter = f._self(); return this; }, /** - Sets the scope of the filter. A scope allows to run facets on the - same scope name that will work against the child documents. + Sets the child document type to search against @member ejs.HasChildFilter - @param {String} s The scope name as a string. + @param {String} t A valid type name @returns {Object} returns this so that calls can be chained. */ - scope: function (s) { - if (s == null) { - return filter.has_child._scope; + type: function (t) { + if (t == null) { + return filter.has_child.type; } - filter.has_child._scope = s; + filter.has_child.type = t; + return this; + }, + + /** + Sets the scope of the filter. A scope allows to run facets on the + same scope name that will work against the child documents. + + @deprecated since elasticsearch 0.90 + @member ejs.HasChildFilter + @param {String} s The scope name as a string. + @returns {Object} returns this so that calls can be chained. + */ + scope: function (s) { return this; }, @@ -5009,6 +5265,27 @@ filter.has_parent.query = q._self(); return this; }, + + /** + Sets the filter + + @since elasticsearch 0.90 + @member ejs.HasParentFilter + @param {Object} f A valid Filter object + @returns {Object} returns this so that calls can be chained. + */ + filter: function (f) { + if (f == null) { + return filter.has_parent.filter; + } + + if (!isFilter(f)) { + throw new TypeError('Argument must be a Filter object'); + } + + filter.has_parent.filter = f._self(); + return this; + }, /** Sets the child document type to search against @@ -5030,16 +5307,12 @@ Sets the scope of the filter. A scope allows to run facets on the same scope name that will work against the parent documents. + @deprecated since elasticsearch 0.90 @member ejs.HasParentFilter @param {String} s The scope name as a string. @returns {Object} returns this so that calls can be chained. */ scope: function (s) { - if (s == null) { - return filter.has_parent._scope; - } - - filter.has_parent._scope = s; return this; }, @@ -5742,23 +6015,36 @@ return this; }, + /** + If the nested query should be "joined" with the parent document. + Defaults to false. + + @member ejs.NestedFilter + @param {Boolean} trueFalse If the query should be joined or not. + @returns {Object} returns this so that calls can be chained. + */ + join: function (trueFalse) { + if (trueFalse == null) { + return filter.nested.join; + } + + filter.nested.join = trueFalse; + return this; + }, + /** Sets the scope of the filter. A scope allows to run facets on the same scope name that will work against the nested documents. + @deprecated since elasticsearch 0.90 @member ejs.NestedFilter @param {String} s The scope name as a string. @returns {Object} returns this so that calls can be chained. */ scope: function (s) { - if (s == null) { - return filter.nested._scope; - } - - filter.nested._scope = s; return this; }, - + /** Sets the filter name. @@ -7494,6 +7780,20 @@ */ var filter = { terms: {} + }, + + // make sure we are setup for a list of terms + setupTerms = function () { + if (!isArray(filter.terms[field])) { + filter.terms[field] = []; + } + }, + + // make sure we are setup for a terms lookup + setupLookup = function () { + if (isArray(filter.terms[field])) { + filter.terms[field] = {}; + } }; if (isArray(terms)) { @@ -7535,10 +7835,11 @@ @returns {Object} returns this so that calls can be chained. */ terms: function (t) { + setupTerms(); if (t == null) { return filter.terms[field]; } - + if (isArray(t)) { filter.terms[field] = t; } else { @@ -7548,6 +7849,84 @@ return this; }, + /** + Sets the index the document containing the terms is in when + performing a terms lookup. Defaults to the index currently + being searched. + + @since elasticsearch 0.90 + @member ejs.TermsFilter + @param {String} idx A valid index name. + @returns {Object} returns this so that calls can be chained. + */ + index: function (idx) { + setupLookup(); + if (idx == null) { + return filter.terms[field].index; + } + + filter.terms[field].index = idx; + return this; + }, + + /** + Sets the type the document containing the terms when performing a + terms lookup. + + @since elasticsearch 0.90 + @member ejs.TermsFilter + @param {String} type A valid type name. + @returns {Object} returns this so that calls can be chained. + */ + type: function (type) { + setupLookup(); + if (type == null) { + return filter.terms[field].type; + } + + filter.terms[field].type = type; + return this; + }, + + + /** + Sets the document id of the document containing the terms to use + when performing a terms lookup. + + @since elasticsearch 0.90 + @member ejs.TermsFilter + @param {String} id A valid index name. + @returns {Object} returns this so that calls can be chained. + */ + id: function (id) { + setupLookup(); + if (id == null) { + return filter.terms[field].id; + } + + filter.terms[field].id = id; + return this; + }, + + /** + Sets the path/field name where the terms in the source document + are located when performing a terms lookup. + + @since elasticsearch 0.90 + @member ejs.TermsFilter + @param {String} path A valid index name. + @returns {Object} returns this so that calls can be chained. + */ + path: function (path) { + setupLookup(); + if (path == null) { + return filter.terms[field].path; + } + + filter.terms[field].path = path; + return this; + }, + /** Sets the way terms filter executes is by iterating over the terms provided and finding matches docs (loading into a bitset) and @@ -7855,13 +8234,14 @@ }, /** - Sets the routing value. By default, the shard the document is - placed on is controlled by using a hash of the document’s id - value. For more explicit control, this routing value will be fed - into the hash function used by the router. +

Sets the routing value.

+ +

By default, the shard the document is placed on is controlled by using a + hash of the document’s id value. For more explicit control, this routing value + will be fed into the hash function used by the router.

- This option is valid during the following operations: - index, delete, get, and update. +

This option is valid during the following operations: + index, delete, get, and update

@member ejs.Document @param {String} route The routing value @@ -7877,13 +8257,14 @@ }, /** - Sets parent value for a child document. When indexing a child - document, the routing value is automatically set to be the same - as it’s parent, unless the routing value is explicitly specified - using the routing parameter. +

Sets parent value for a child document.

+ +

When indexing a child document, the routing value is automatically set to be + the same as it’s parent, unless the routing value is explicitly specified + using the routing parameter.

- This option is valid during the following operations: - index, delete, get, and update. +

This option is valid during the following operations: + index, delete, get, and update.

@member ejs.Document @param {String} parent The parent value @@ -7899,11 +8280,12 @@ }, /** - Sets timestamp of the document. By default the timestamp will - be set to the time the docuement was indexed. +

Sets timestamp of the document.

+ +

By default the timestamp will be set to the time the docuement was indexed.

- This option is valid during the following operations: - index and update +

This option is valid during the following operations: + index and update

@member ejs.Document @param {String} parent The parent value @@ -7919,15 +8301,17 @@ }, /** - Sets the documents time to live (ttl). The expiration date that - will be set for a document with a provided ttl is relative to the - timestamp of the document, meaning it can be based on the time of - indexing or on any time provided. The provided ttl must be - strictly positive and can be a number (in milliseconds) or any - valid time value such as "1d", "2h", "5m", etc. +

Sets the documents time to live (ttl).

+ + The expiration date that will be set for a document with a provided ttl is relative + to the timestamp of the document, meaning it can be based on the time of indexing or + on any time provided.

+ +

The provided ttl must be strictly positive and can be a number (in milliseconds) + or any valid time value such as "1d", "2h", "5m", etc.

- This option is valid during the following operations: - index and update +

This option is valid during the following operations: + index and update

@member ejs.Document @param {String} length The amount of time after which the document @@ -7944,14 +8328,15 @@ }, /** - Set's a timeout for the given operation. If the primary shard - has not completed the operation before this value, an error will - occur. The default timeout is 1 minute. The provided timeout - must be strictly positive and can be a number (in milliseconds) or - any valid time value such as "1d", "2h", "5m", etc. +

Set's a timeout for the given operation.

+ + If the primary shard has not completed the operation before this value, an error will + occur. The default timeout is 1 minute. The provided timeout must be strictly positive + and can be a number (in milliseconds) or any valid time value such as + "1d", "2h", "5m", etc.

- This option is valid during the following operations: - index, delete, and update +

This option is valid during the following operations: + index, delete, and update

@member ejs.Document @param {String} length The amount of time after which the operation @@ -7968,12 +8353,12 @@ }, /** - Enables the index to be refreshed immediately after the operation - occurs. This is an advanced setting and can lead to performance - issues. +

Enables the index to be refreshed immediately after the operation + occurs. This is an advanced setting and can lead to performance + issues.

- This option is valid during the following operations: - index, delete, get, and update +

This option is valid during the following operations: + index, delete, get, and update

@member ejs.Document @param {Boolean} trueFalse If the index should be refreshed or not. @@ -7989,15 +8374,17 @@ }, /** - Sets the document version. Used for optimistic concurrency - control when set. If the version of the currently indexed - document is less-than or equal to the version specified, an - error is produced, otherwise the operation is permitted. - By default, internal versioning is used that starts at 1 and - increments with each update. +

Sets the document version.

+ + Used for optimistic concurrency control when set. If the version of the currently + indexed document is less-than or equal to the version specified, an error is produced, + otherwise the operation is permitted.

+ +

By default, internal versioning is used that starts at 1 and + increments with each update.

- This option is valid during the following operations: - index, delete, and update +

This option is valid during the following operations: + index, delete, and update

@member ejs.Document @param {Long} version A positive long value @@ -8013,13 +8400,17 @@ }, /** - Sets the version type. Possible values are: +

Sets the version type.

+ +

Possible values are:

- internal - the default - external - to use your own version (ie. version number from a database) +
+
internal - the default
+
external - to use your own version (ie. version number from a database)
+
- This option is valid during the following operations: - index, delete, and update +

This option is valid during the following operations: + index, delete, and update

@member ejs.Document @param {String} vt A version type (internal or external) @@ -8040,12 +8431,13 @@ }, /** - Perform percolation at index time. Set to * to run document - against all registered queries. It is also possible to set this - value to a string in query string format, ie. "color:green". +

Perform percolation at index time.

+ +

Set to * to run document against all registered queries. It is also possible + to set this value to a string in query string format, ie. "color:green".

- This option is valid during the following operations: - index and update +

This option is valid during the following operations: + index and update

@member ejs.Document @param {String} qry A percolation query string @@ -8061,13 +8453,17 @@ }, /** - Sets the indexing operation type. Valid values are: +

Sets the indexing operation type.

+ +

Valid values are:

- index - the default, create or replace - create - create only +
+
index - the default, create or replace
+
create - create only
+
- This option is valid during the following operations: - index +

This option is valid during the following operations: + index

@member ejs.Document @param {String} op The operation type (index or create) @@ -8087,14 +8483,18 @@ }, /** - Sets the replication mode. Valid values are: +

Sets the replication mode.

+ +

Valid values are:

- async - asynchronous replication to slaves - sync - synchronous replication to the slaves - default - the currently configured system default. +
+
async - asynchronous replication to slaves
+
sync - synchronous replication to the slaves
+
default - the currently configured system default.
+
- This option is valid during the following operations: - index, delete, and update +

This option is valid during the following operations: + index, delete, and update

@member ejs.Document @param {String} r The replication mode (async, sync, or default) @@ -8114,15 +8514,19 @@ }, /** - Sets the write consistency. Valid values are: +

Sets the write consistency.

+ +

Valid values are:

- one - only requires write to one shard - quorum - requires writes to quorum (N/2 + 1) - all - requires write to succeed on all shards - default - the currently configured system default +
+
one - only requires write to one shard
+
quorum - requires writes to quorum (N/2 + 1)
+
all - requires write to succeed on all shards
+
default - the currently configured system default
+
- This option is valid during the following operations: - index, delete, and update +

This option is valid during the following operations: + index, delete, and update

@member ejs.Document @param {String} c The write consistency (one, quorum, all, or default) @@ -8142,16 +8546,20 @@ }, /** - Sets the preference of which shard replicas to execute the get - request on. By default, the operation is randomized between the - shard replicas. This value can be: +

Sets the preference of which shard replicas to execute the get + request on.

+ +

By default, the operation is randomized between the shard replicas. + This value can be:

- _primary - execute only on the primary shard - _local - the local shard if possible - any string value - to guarentee the same shards will always be used +
+
_primary - execute only on the primary shard
+
_local - the local shard if possible
+
any string value - to guarentee the same shards will always be used
+
- This option is valid during the following operations: - get +

This option is valid during the following operations: + get

@member ejs.Document @param {String} p The preference value as a string @@ -8167,11 +8575,11 @@ }, /** - Sets if the get request is performed in realtime or waits for - the indexing operations to complete. By default it is realtime. +

Sets if the get request is performed in realtime or waits for + the indexing operations to complete. By default it is realtime.

- This option is valid during the following operations: - get +

This option is valid during the following operations: + get

@member ejs.Document @param {Boolean} trueFalse If realtime get is used or not. @@ -8187,14 +8595,15 @@ }, /** - Sets the fields of the document to return. By default the - _source field is returned. Pass a single value to append to the - current list of fields, pass an array to overwrite the current - list of fields. The returned fields will either be loaded if - they are stored, or fetched from the _source +

Sets the fields of the document to return.

+ +

By default the _source field is returned. Pass a single value + to append to the current list of fields, pass an array to overwrite the current + list of fields. The returned fields will either be loaded if they are stored, + or fetched from the _source

- This option is valid during the following operations: - get and update +

This option is valid during the following operations: + get and update

@member ejs.Document @param {String || Array} fields a single field name or array of field names. @@ -8221,10 +8630,10 @@ }, /** - Sets the update script. +

Sets the update script.

- This option is valid during the following operations: - update +

This option is valid during the following operations: + update

@member ejs.Document @param {String} script a script to use for docuement updates @@ -8240,10 +8649,10 @@ }, /** - Sets the update script lanauge. Defaults to mvel. +

Sets the update script lanauge. Defaults to mvel

. - This option is valid during the following operations: - update +

This option is valid during the following operations: + update

@member ejs.Document @param {String} lang a valid script lanauge type such as mvel. @@ -8259,12 +8668,13 @@ }, /** - Sets the parameters sent to the update script. The params must - be an object where the key is the parameter name and the value is - the parameter value to use in the script. +

Sets the parameters sent to the update script.

+ +

The params must be an object where the key is the parameter name and + the value is the parameter value to use in the script.

- This option is valid during the following operations: - update +

This option is valid during the following operations: + update

@member ejs.Document @param {Object} p a object with script parameters. @@ -8285,12 +8695,13 @@ }, /** - Sets how many times to retry if there is a version conflict - between getting the document and indexing / deleting it. - Defaults to 0. +

Sets how many times to retry if there is a version conflict + between getting the document and indexing / deleting it.

- This option is valid during the following operations: - update +

Defaults to 0.

+ +

This option is valid during the following operations: + update

@member ejs.Document @param {Integer} num the number of times to retry operation. @@ -8306,12 +8717,13 @@ }, /** - Sets the upsert document. The upsert document is used during - updates when the specified document you are attempting to - update does not exist. +

Sets the upsert document.

+ +

The upsert document is used during updates when the specified document + you are attempting to update does not exist.

- This option is valid during the following operations: - update +

This option is valid during the following operations: + update

@member ejs.Document @param {Object} doc the upset document. @@ -8331,11 +8743,12 @@ }, /** - Sets the source document. When set during an update operation, - it is used as the partial update document. +

Sets the source document.

- This option is valid during the following operations: - index and update +

When set during an update operation, it is used as the partial update document.

+ +

This option is valid during the following operations: + index and update

@member ejs.Document @param {Object} doc the source document. @@ -8365,7 +8778,7 @@ }, /** - The type of ejs object. For internal use only. +

The type of ejs object. For internal use only.

@member ejs.Document @returns {String} the type of object @@ -8389,10 +8802,11 @@

Retrieves a document from the given index and type.

@member ejs.Document - @param {Function} fnCallBack A callback function that handles the response. + @param {Function} successcb A callback function that handles the response. + @param {Function} errorcb A callback function that handles errors. @returns {Object} The return value is dependent on client implementation. */ - doGet: function (fnCallBack) { + doGet: function (successcb, errorcb) { // make sure the user has set a client if (ejs.client == null) { throw new Error("No Client Set"); @@ -8407,7 +8821,7 @@ // params as the data var url = '/' + index + '/' + type + '/' + id; - return ejs.client.get(url, genClientParams(), fnCallBack); + return ejs.client.get(url, genClientParams(), successcb, errorcb); }, /** @@ -8415,10 +8829,11 @@ is set, one is created during indexing.

@member ejs.Document - @param {Function} fnCallBack A callback function that handles the response. + @param {Function} successcb A callback function that handles the response. + @param {Function} errorcb A callback function that handles errors. @returns {Object} The return value is dependent on client implementation. */ - doIndex: function (fnCallBack) { + doIndex: function (successcb, errorcb) { // make sure the user has set a client if (ejs.client == null) { throw new Error("No Client Set"); @@ -8447,27 +8862,30 @@ // do post if id not set so one is created if (id == null) { - response = ejs.client.post(url, data, fnCallBack); + response = ejs.client.post(url, data, successcb, errorcb); } else { // put when id is specified - response = ejs.client.put(url, data, fnCallBack); + response = ejs.client.put(url, data, successcb, errorcb); } return response; }, /** -

Updates a document in the given index and type. If the - document is not found in the index, the "upsert" value is used - if set. The document is updated via an update script or partial - document. To use a script, set the script option, to use a +

Updates a document in the given index and type.

+ +

If the document is not found in the index, the "upsert" value is used + if set. The document is updated via an update script or partial document.

+ +

To use a script, set the script option, to use a partial document, set the source with the partial document.

@member ejs.Document - @param {Function} fnCallBack A callback function that handles the response. + @param {Function} successcb A callback function that handles the response. + @param {Function} errorcb A callback function that handles errors. @returns {Object} The return value is dependent on client implementation. */ - doUpdate: function (fnCallBack) { + doUpdate: function (successcb, errorcb) { // make sure the user has set a client if (ejs.client == null) { throw new Error("No Client Set"); @@ -8509,7 +8927,7 @@ data.doc = params.source; } - return ejs.client.post(url, JSON.stringify(data), fnCallBack); + return ejs.client.post(url, JSON.stringify(data), successcb, errorcb); }, /** @@ -8517,10 +8935,11 @@ speciifed id.

@member ejs.Document - @param {Function} fnCallBack A callback function that handles the response. + @param {Function} successcb A callback function that handles the response. + @param {Function} errorcb A callback function that handles errors. @returns {void} Returns the value of the callback when executing on the server. */ - doDelete: function (fnCallBack) { + doDelete: function (successcb, errorcb) { // make sure the user has set a client if (ejs.client == null) { throw new Error("No Client Set"); @@ -8538,7 +8957,7 @@ url = url + '?' + paramStr; } - return ejs.client.del(url, data, fnCallBack); + return ejs.client.del(url, data, successcb, errorcb); } }; @@ -8713,15 +9132,15 @@ }, /** - Sets the number of optional clauses that must match. +

Sets the number of optional clauses that must match.

- By default no optional clauses are necessary for a match +

By default no optional clauses are necessary for a match (unless there are no required clauses). If this method is used, - then the specified number of clauses is required.. + then the specified number of clauses is required.

- Use of this method is totally independent of specifying that +

Use of this method is totally independent of specifying that any specific clauses are required (or prohibited). This number will - only be compared against the number of matching optional clauses. + only be compared against the number of matching optional clauses.

@member ejs.BoolQuery @param {Integer} minMatch A positive integer value. @@ -8918,130 +9337,375 @@ /** @class -

A constant score query wraps another Query or - Filter and returns a constant score for each - result that is equal to the query boost.

- -

Note that lucene's query normalization (queryNorm) attempts - to make scores between different queries comparable. It does not - change the relevance of your query, but it might confuse you when - you look at the score of your documents and they are not equal to - the query boost value as expected. The scores were normalized by - queryNorm, but maintain the same relevance.

- - @name ejs.ConstantScoreQuery - +

A query that executes high-frequency terms in a optional sub-query to + prevent slow queries due to "common" terms like stopwords.

+ +

This query basically builds two queries out of the terms in the query + string where low-frequency terms are added to a required boolean clause and + high-frequency terms are added to an optional boolean clause. The optional + clause is only executed if the required "low-frequency' clause matches.

+ +

CommonTermsQuery has several advantages over stopword + filtering at index or query time since a term can be "classified" based on + the actual document frequency in the index and can prevent slow queries even + across domains without specialized stopword files.

+ + @name ejs.CommonTermsQuery + @since elasticsearch 0.90 + @desc -

Constructs a query where each documents returned by the internal - query or filter have a constant score equal to the boost factor.

+ A query that executes high-frequency terms in a optional sub-query. - */ - ejs.ConstantScoreQuery = function () { + @param {String} field the document field/key to query against + @param {String} qstr the query string + */ + ejs.CommonTermsQuery = function (field, qstr) { /** - The internal Query object. Use _self(). - @member ejs.ConstantScoreQuery + The internal query object. Use get() + @member ejs.CommonTermsQuery @property {Object} query */ var query = { - constant_score: {} + common: {} }; - + + // support for full Builder functionality where no constructor is used + // use dummy field until one is set + if (field == null) { + field = 'no_field_set'; + } + + query.common[field] = {}; + + // only set the query is one is passed in + if (qstr != null) { + query.common[field].query = qstr; + } + return { + /** - Adds the query to apply a constant score to. + Sets the field to query against. - @member ejs.ConstantScoreQuery - @param {Object} oQuery A valid Query object - @returns {Object} returns this so that calls can be chained. - */ - query: function (oQuery) { - if (oQuery == null) { - return query.constant_score.query; - } - - if (!isQuery(oQuery)) { - throw new TypeError('Argument must be a Query'); + @member ejs.CommonTermsQuery + @param {String} f A valid field name. + @returns {Object} returns this so that calls can be chained. + */ + field: function (f) { + var oldValue = query.common[field]; + + if (f == null) { + return field; } - - query.constant_score.query = oQuery._self(); + + delete query.common[field]; + field = f; + query.common[f] = oldValue; + return this; }, - + /** - Adds the filter to apply a constant score to. + Sets the query string. - @member ejs.ConstantScoreQuery - @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.constant_score.filter; - } - - if (!isFilter(oFilter)) { - throw new TypeError('Argument must be a Filter'); + @member ejs.CommonTermsQuery + @param {String} qstr The query string. + @returns {Object} returns this so that calls can be chained. + */ + query: function (qstr) { + if (qstr == null) { + return query.common[field].query; } - - query.constant_score.filter = oFilter._self(); + + query.common[field].query = qstr; return this; }, /** - Enables caching of the filter. + Sets the analyzer name used to analyze the Query object. - @member ejs.ConstantScoreQuery - @param {Boolean} trueFalse A boolean value. + @member ejs.CommonTermsQuery + @param {String} analyzer A valid analyzer name. @returns {Object} returns this so that calls can be chained. */ - cache: function (trueFalse) { - if (trueFalse == null) { - return query.constant_score._cache; + analyzer: function (analyzer) { + if (analyzer == null) { + return query.common[field].analyzer; } - query.constant_score._cache = trueFalse; + query.common[field].analyzer = analyzer; return this; }, - + /** - Set the cache key. + Enables or disables similarity coordinate scoring of documents + commoning the Query. Default: false. - @member ejs.ConstantScoreQuery - @param {String} k A string cache key. + @member ejs.CommonTermsQuery + @param {String} trueFalse A true/falsethis
so that calls can be chained. */ - cacheKey: function (k) { - if (k == null) { - return query.constant_score._cache_key; + disableCoords: function (trueFalse) { + if (trueFalse == null) { + return query.common[field].disable_coords; } - query.constant_score._cache_key = k; + query.common[field].disable_coords = trueFalse; return this; }, - + /** - Sets the boost value of the Query. + Sets the maximum threshold/frequency to be considered a low + frequency term. Set to a value between 0 and 1. - @member ejs.ConstantScoreQuery - @param {Double} boost A positive double value. + @member ejs.CommonTermsQuery + @param {Number} freq A positive double value. @returns {Object} returns this so that calls can be chained. */ - boost: function (boost) { - if (boost == null) { - return query.constant_score.boost; + cutoffFrequency: function (freq) { + if (freq == null) { + return query.common[field].cutoff_frequency; } - query.constant_score.boost = boost; + query.common[field].cutoff_frequency = freq; return this; }, /** - Serializes the internal query object as a JSON string. - @member ejs.ConstantScoreQuery - @returns {String} Returns a JSON representation of the Query object. - */ - toString: function () { + Sets the boolean operator to be used for high frequency terms. + Default: AND + + @member ejs.CommonTermsQuery + @param {String} op Any of "and" or "or", no quote characters. + @returns {Object} returns this so that calls can be chained. + */ + highFreqOperator: function (op) { + if (op == null) { + return query.common[field].high_freq_operator; + } + + op = op.toLowerCase(); + if (op === 'and' || op === 'or') { + query.common[field].high_freq_operator = op; + } + + return this; + }, + + /** + Sets the boolean operator to be used for low frequency terms. + Default: AND + + @member ejs.CommonTermsQuery + @param {String} op Any of "and" or "or", no quote characters. + @returns {Object} returns this so that calls can be chained. + */ + lowFreqOperator: function (op) { + if (op == null) { + return query.common[field].low_freq_operator; + } + + op = op.toLowerCase(); + if (op === 'and' || op === 'or') { + query.common[field].low_freq_operator = op; + } + + return this; + }, + + /** + Sets the minimum number of common that need to common in a document + before that document is returned in the results. + + @member ejs.CommonTermsQuery + @param {Integer} min A positive integer. + @returns {Object} returns this so that calls can be chained. + */ + minimumShouldMatch: function (min) { + if (min == null) { + return query.common[field].minimum_should_match; + } + + query.common[field].minimum_should_match = min; + return this; + }, + + /** + Sets the boost value for documents commoning the Query. + + @member ejs.CommonTermsQuery + @param {Number} boost A positive double value. + @returns {Object} returns this so that calls can be chained. + */ + boost: function (boost) { + if (boost == null) { + return query.common[field].boost; + } + + query.common[field].boost = boost; + return this; + }, + + /** + Allows you to serialize this object into a JSON encoded string. + + @member ejs.CommonTermsQuery + @returns {String} returns this object as a serialized JSON string. + */ + toString: function () { + return JSON.stringify(query); + }, + + /** + The type of ejs object. For internal use only. + + @member ejs.CommonTermsQuery + @returns {String} the type of object + */ + _type: function () { + return 'query'; + }, + + /** + Retrieves the internal query object. This is typically used by + internal API functions so use with caution. + + @member ejs.CommonTermsQuery + @returns {String} returns this object's internal query property. + */ + _self: function () { + return query; + } + }; + }; + + /** + @class +

A constant score query wraps another Query or + Filter and returns a constant score for each + result that is equal to the query boost.

+ +

Note that lucene's query normalization (queryNorm) attempts + to make scores between different queries comparable. It does not + change the relevance of your query, but it might confuse you when + you look at the score of your documents and they are not equal to + the query boost value as expected. The scores were normalized by + queryNorm, but maintain the same relevance.

+ + @name ejs.ConstantScoreQuery + + @desc +

Constructs a query where each documents returned by the internal + query or filter have a constant score equal to the boost factor.

+ + */ + ejs.ConstantScoreQuery = function () { + + /** + The internal Query object. Use _self(). + @member ejs.ConstantScoreQuery + @property {Object} query + */ + var query = { + constant_score: {} + }; + + return { + /** + Adds the query to apply a constant score to. + + @member ejs.ConstantScoreQuery + @param {Object} oQuery A valid Query object + @returns {Object} returns this so that calls can be chained. + */ + query: function (oQuery) { + if (oQuery == null) { + return query.constant_score.query; + } + + if (!isQuery(oQuery)) { + throw new TypeError('Argument must be a Query'); + } + + query.constant_score.query = oQuery._self(); + return this; + }, + + /** + Adds the filter to apply a constant score to. + + @member ejs.ConstantScoreQuery + @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.constant_score.filter; + } + + if (!isFilter(oFilter)) { + throw new TypeError('Argument must be a Filter'); + } + + query.constant_score.filter = oFilter._self(); + return this; + }, + + /** + Enables caching of the filter. + + @member ejs.ConstantScoreQuery + @param {Boolean} trueFalse A boolean value. + @returns {Object} returns this so that calls can be chained. + */ + cache: function (trueFalse) { + if (trueFalse == null) { + return query.constant_score._cache; + } + + query.constant_score._cache = trueFalse; + return this; + }, + + /** + Set the cache key. + + @member ejs.ConstantScoreQuery + @param {String} k A string cache key. + @returns {Object} returns this so that calls can be chained. + */ + cacheKey: function (k) { + if (k == null) { + return query.constant_score._cache_key; + } + + query.constant_score._cache_key = k; + return this; + }, + + /** + Sets the boost value of the Query. + + @member ejs.ConstantScoreQuery + @param {Double} boost A positive double value. + @returns {Object} returns this so that calls can be chained. + */ + boost: function (boost) { + if (boost == null) { + return query.constant_score.boost; + } + + query.constant_score.boost = boost; + return this; + }, + + /** + Serializes the internal query object as a JSON string. + @member ejs.ConstantScoreQuery + @returns {String} Returns a JSON representation of the Query object. + */ + toString: function () { return JSON.stringify(query); }, @@ -9277,11 +9941,12 @@ }, /** - Sets the filters and their related boost or script scoring method. - Takes an array of objects where each object has a 'filter' property +

Sets the filters and their related boost or script scoring method.

+ +

Takes an array of objects where each object has a 'filter' property and either a 'boost' or 'script' property. Pass a single object to add to the current list of filters or pass a list of objects to - overwrite all existing filters. + overwrite all existing filters.

{filter: someFilter, boost: 2.1} @@ -9312,12 +9977,13 @@ }, /** - A score_mode can be defined to control how multiple matching - filters control the score. By default, it is set to first which - means the first matching filter will control the score of the - result. It can also be set to min/max/total/avg/multiply which - will aggregate the result from all matching filters based on the - aggregation type. +

A score_mode can be defined to control how multiple matching + filters control the score.

+ +

By default, it is set to first which means the first matching filter + will control the score of the result. It can also be set to + min/max/total/avg/multiply which will aggregate the result from all + matching filters based on the aggregation type.

@member ejs.CustomFiltersScoreQuery @param {String} s The scoring type as a string. @@ -9671,11 +10337,14 @@ /** - The tie breaker value. The tie breaker capability allows results - that include the same term in multiple fields to be judged better than - results that include this term in only the best of those multiple - fields, without confusing this with the better case of two different - terms in the multiple fields. Default: 0.0. +

The tie breaker value.

+ +

The tie breaker capability allows results that include the same term in multiple + fields to be judged better than results that include this term in only the best of those + multiple fields, without confusing this with the better case of two different terms in + the multiple fields.

+ +

Default: 0.0.

@member ejs.DisMaxQuery @param {Double} tieBreaker A positive double value. @@ -9723,6 +10392,7 @@ }; }; + /** @class

Wrapper to allow SpanQuery objects participate in composite single-field @@ -9897,7 +10567,7 @@ }, /** - Sets the query string. +

Sets the query string.

@member ejs.FieldQuery @param {String} q The lucene query string. @@ -9913,10 +10583,11 @@ }, /** - Set the default Boolean operator. This operator is used - to join individual query terms when no operator is explicity used - in the query string (i.e., this AND that). - Defaults to OR (same as Google). +

Set the default Boolean operator.

+ +

This operator is used to join individual query terms when no operator is + explicity used in the query string (i.e., this AND that). + Defaults to OR (same as Google).

@member ejs.FieldQuery @param {String} op The operator, AND or OR. @@ -9936,7 +10607,7 @@ }, /** - Sets the analyzer name used to analyze the Query object. +

Sets the analyzer name used to analyze the Query object.

@member ejs.FieldQuery @param {String} analyzer A valid analyzer name. @@ -9952,8 +10623,8 @@ }, /** - Sets the quote analyzer name used to analyze the query - when in quoted text. +

Sets the quote analyzer name used to analyze the query + when in quoted text.

@member ejs.FieldQuery @param {String} analyzer A valid analyzer name. @@ -9969,8 +10640,8 @@ }, /** - Sets whether or not we should auto generate phrase queries *if* the - analyzer returns more than one term. Default: false. +

Sets whether or not we should auto generate phrase queries *if* the + analyzer returns more than one term. Default: false.

@member ejs.FieldQuery @param {Boolean} trueFalse A true/false value. @@ -9986,8 +10657,10 @@ }, /** - Sets whether or not wildcard characters (* and ?) are allowed as the - first character of the Query. Default: true. +

Sets whether or not wildcard characters (* and ?) are allowed as the + first character of the Query.

+ +

Default: true.

@member ejs.FieldQuery @param {Boolean} trueFalse A true/false value. @@ -10003,9 +10676,11 @@ }, /** - Sets whether or not terms from wildcard, prefix, fuzzy, and - range queries should automatically be lowercased in the Query - since they are not analyzed. Default: true. +

Sets whether or not terms from wildcard, prefix, fuzzy, and + range queries should automatically be lowercased in the Query + since they are not analyzed.

+ +

Default: true.

@member ejs.FieldQuery @param {Boolean} trueFalse A true/false value. @@ -10021,8 +10696,10 @@ }, /** - Sets whether or not position increments will be used in the - Query. Default: true. +

Sets whether or not position increments will be used in the + Query.

+ +

Default: true.

@member ejs.FieldQuery @param {Boolean} trueFalse A true/false value. @@ -10038,7 +10715,9 @@ }, /** - Set the minimum similarity for fuzzy queries. Default: 0.5. +

Set the minimum similarity for fuzzy queries.

+ +

Default: 0.5.

@member ejs.FieldQuery @param {Double} minSim A double value between 0 and 1. @@ -10054,7 +10733,9 @@ }, /** - Sets the boost value of the Query. Default: 1.0. +

Sets the boost value of the Query.

+ +

Default: 1.0.

@member ejs.FieldQuery @param {Double} boost A positive double value. @@ -10070,7 +10751,9 @@ }, /** - Sets the prefix length for fuzzy queries. Default: 0. +

Sets the prefix length for fuzzy queries.

+ +

Default: 0.

@member ejs.FieldQuery @param {Integer} fuzzLen A positive integer value. @@ -10086,7 +10769,7 @@ }, /** - Sets the max number of term expansions for fuzzy queries. +

Sets the max number of term expansions for fuzzy queries.

@member ejs.FieldQuery @param {Integer} max A positive integer value. @@ -10102,31 +10785,35 @@ }, /** - Sets fuzzy rewrite method. Valid values are: +

Sets fuzzy rewrite method.

+ +

Valid values are:

- constant_score_auto - tries to pick the best constant-score rewrite - method based on term and document counts from the query +
+
constant_score_auto - tries to pick the best constant-score rewrite + method based on term and document counts from the query
- scoring_boolean - translates each term into boolean should and - keeps the scores as computed by the query +
scoring_boolean - translates each term into boolean should and + keeps the scores as computed by the query
- constant_score_boolean - same as scoring_boolean, expect no scores - are computed. +
constant_score_boolean - same as scoring_boolean, expect no scores + are computed.
- constant_score_filter - first creates a private Filter, by visiting - each term in sequence and marking all docs for that term +
constant_score_filter - first creates a private Filter, by visiting + each term in sequence and marking all docs for that term
- top_terms_boost_N - first translates each term into boolean should - and scores are only computed as the boost using the top N - scoring terms. Replace N with an integer value. +
top_terms_boost_N - first translates each term into boolean should + and scores are only computed as the boost using the top N + scoring terms. Replace N with an integer value.
- top_terms_N - first translates each term into boolean should - and keeps the scores as computed by the query. Only the top N - scoring terms are used. Replace N with an integer value. +
top_terms_N - first translates each term into boolean should + and keeps the scores as computed by the query. Only the top N + scoring terms are used. Replace N with an integer value.
+
- Default is constant_score_auto. +

Default is constant_score_auto.

- This is an advanced option, use with care. +

This is an advanced option, use with care.

@member ejs.FieldQuery @param {String} m The rewrite method as a string. @@ -10150,29 +10837,33 @@ }, /** - Sets rewrite method. Valid values are: +

Sets rewrite method.

+ +

Valid values are:

- constant_score_auto - tries to pick the best constant-score rewrite - method based on term and document counts from the query +
+
constant_score_auto - tries to pick the best constant-score rewrite + method based on term and document counts from the query
- scoring_boolean - translates each term into boolean should and - keeps the scores as computed by the query +
scoring_boolean - translates each term into boolean should and + keeps the scores as computed by the query
- constant_score_boolean - same as scoring_boolean, expect no scores - are computed. +
constant_score_boolean - same as scoring_boolean, expect no scores + are computed.

- constant_score_filter - first creates a private Filter, by visiting - each term in sequence and marking all docs for that term +
constant_score_filter - first creates a private Filter, by visiting + each term in sequence and marking all docs for that term
- top_terms_boost_N - first translates each term into boolean should - and scores are only computed as the boost using the top N - scoring terms. Replace N with an integer value. +
top_terms_boost_N - first translates each term into boolean should + and scores are only computed as the boost using the top N + scoring terms. Replace N with an integer value.
- top_terms_N - first translates each term into boolean should - and keeps the scores as computed by the query. Only the top N - scoring terms are used. Replace N with an integer value. +
top_terms_N - first translates each term into boolean should + and keeps the scores as computed by the query. Only the top N + scoring terms are used. Replace N with an integer value.
+
- Default is constant_score_auto. +

Default is constant_score_auto.

This is an advanced option, use with care. @@ -10198,8 +10889,8 @@ }, /** - Sets the suffix to automatically add to the field name when - performing a quoted search. +

Sets the suffix to automatically add to the field name when + performing a quoted search.

@member ejs.FieldQuery @param {String} s The suffix as a string. @@ -10215,8 +10906,10 @@ }, /** - Sets the default slop for phrases. If zero, then exact phrase matches - are required. Default: 0. +

Sets the default slop for phrases. If zero, then exact phrase matches + are required.

+ +

Default: 0.

@member ejs.FieldQuery @param {Integer} slop A positive integer value. @@ -10232,9 +10925,12 @@ }, /** - Sets whether or not we should attempt to analyzed wilcard terms in the - Query. By default, wildcard terms are not analyzed. - Analysis of wildcard characters is not perfect. Default: false. +

Sets whether or not we should attempt to analyzed wilcard terms in the + Query.

+ +

By default, wildcard terms are not analyzed. Analysis of wildcard characters is not perfect.

+ +

Default: false.

@member ejs.FieldQuery @param {Boolean} trueFalse A true/false value. @@ -10250,7 +10946,7 @@ }, /** - If they query string should be escaped or not. +

If the query string should be escaped or not.

@member ejs.FieldQuery @param {Boolean} trueFalse A true/false value. @@ -10266,8 +10962,8 @@ }, /** - Sets a percent value controlling how many "should" clauses in the - resulting Query should match. +

Sets a percent value controlling how many should clauses in the + resulting Query should match.

@member ejs.FieldQuery @param {Integer} minMatch An integer between 0 and 100. @@ -10283,7 +10979,7 @@ }, /** - Allows you to serialize this object into a JSON encoded string. +

Allows you to serialize this object into a JSON encoded string.

@member ejs.FieldQuery @returns {String} returns this object as a serialized JSON string. @@ -10293,7 +10989,7 @@ }, /** - The type of ejs object. For internal use only. +

The type of ejs object. For internal use only.

@member ejs.FieldQuery @returns {String} the type of object @@ -10303,8 +10999,8 @@ }, /** - Retrieves the internal query object. This is typically used by - internal API functions so use with caution. +

Retrieves the internal query object. This is typically used by + internal API functions so use with caution.

@member ejs.FieldQuery @returns {String} returns this object's internal query property. @@ -10361,7 +11057,7 @@ return { /** - Adds the query to apply a constant score to. +

Adds the query to apply a constant score to.

@member ejs.FilteredQuery @param {Object} oQuery A valid Query object @@ -10381,7 +11077,7 @@ }, /** - Adds the filter to apply a constant score to. +

Adds the filter to apply a constant score to.

@member ejs.FilteredQuery @param {Object} oFilter A valid Filter object @@ -10401,17 +11097,21 @@ }, /** - Sets the filter strategy. The strategy defines how the filter is - applied during document collection. Valid values are: +

Sets the filter strategy.

+ +

The strategy defines how the filter is applied during document collection. + Valid values are:

- query_filter - advance query scorer first then filter - random_access_random - random access filter - leap_frog - query scorer and filter "leap-frog", query goes first - leap_frog_filter_first - same as leap_frog, but filter goes first - random_access_N - replace N with integer, same as random access - except you can specify a custom threshold - - This is an advanced setting, use with care. +
+
query_first - advance query scorer first then filter
+
random_access_random - random access filter
+
leap_frog - query scorer and filter "leap-frog", query goes first
+
leap_frog_filter_first - same as leap_frog, but filter goes first
+
random_access_N - replace N with integer, same as random access + except you can specify a custom threshold
+
+ +

This is an advanced setting, use with care.

@member ejs.FilteredQuery @param {String} strategy The strategy as a string. @@ -10423,7 +11123,7 @@ } strategy = strategy.toLowerCase(); - if (strategy === 'query_filter' || strategy === 'random_access_random' || + if (strategy === 'query_first' || strategy === 'random_access_always' || strategy === 'leap_frog' || strategy === 'leap_frog_filter_first' || strategy.indexOf('random_access_') === 0) { @@ -10434,7 +11134,7 @@ }, /** - Enables caching of the filter. +

Enables caching of the filter.

@member ejs.FilteredQuery @param {Boolean} trueFalse A boolean value. @@ -10450,7 +11150,7 @@ }, /** - Set the cache key. +

Set the cache key.

@member ejs.FilteredQuery @param {String} k A string cache key. @@ -10466,7 +11166,7 @@ }, /** - Sets the boost value of the Query. +

Sets the boost value of the Query.

@member ejs.FilteredQuery @param {Double} boost A positive double value. @@ -10482,7 +11182,8 @@ }, /** - Converts this object to a json string +

Converts this object to a json string

+ @member ejs.FilteredQuery @returns {Object} string */ @@ -10491,7 +11192,7 @@ }, /** - The type of ejs object. For internal use only. +

The type of ejs object. For internal use only.

@member ejs.FilteredQuery @returns {String} the type of object @@ -10501,7 +11202,8 @@ }, /** - returns the query object. +

returns the query object.

+ @member ejs.FilteredQuery @returns {Object} query object */ @@ -10981,7 +11683,7 @@ return { /** - The field to run the query against. +

The field to run the query against.

@member ejs.FuzzyQuery @param {String} f A single field name. @@ -11002,7 +11704,7 @@ }, /** - The query text to fuzzify. +

The query text to fuzzify.

@member ejs.FuzzyQuery @param {String} s A text string. @@ -11018,7 +11720,7 @@ }, /** - Set to false to use classic Levenshtein edit distance. +

Set to false to use classic Levenshtein edit distance.

@member ejs.FuzzyQuery @param {Boolean} trueFalse A boolean value @@ -11034,8 +11736,8 @@ }, /** - The maximum number of query terms that will be included in any - generated query. Defaults to 50. +

The maximum number of query terms that will be included in any + generated query. Defaults to 50.

@member ejs.FuzzyQuery @param {Integer} max A positive integer value. @@ -11051,7 +11753,7 @@ }, /** - The minimum similarity of the term variants. Defaults to 0.5. +

The minimum similarity of the term variants. Defaults to 0.5.

@member ejs.FuzzyQuery @param {Double} min A positive double value. @@ -11067,7 +11769,7 @@ }, /** - Length of required common prefix on variant terms. Defaults to 0.. +

Length of required common prefix on variant terms. Defaults to 0.

@member ejs.FuzzyQuery @param {Integer} len A positive integer value. @@ -11083,31 +11785,33 @@ }, /** - Sets rewrite method. Valid values are: +

Sets rewrite method. Valid values are:

- constant_score_auto - tries to pick the best constant-score rewrite - method based on term and document counts from the query +
+
constant_score_auto - tries to pick the best constant-score rewrite + method based on term and document counts from the query
- scoring_boolean - translates each term into boolean should and - keeps the scores as computed by the query +
scoring_boolean - translates each term into boolean should and + keeps the scores as computed by the query
- constant_score_boolean - same as scoring_boolean, expect no scores - are computed. +
constant_score_boolean - same as scoring_boolean, expect no scores + are computed.
- constant_score_filter - first creates a private Filter, by visiting - each term in sequence and marking all docs for that term +
constant_score_filter - first creates a private Filter, by visiting + each term in sequence and marking all docs for that term
- top_terms_boost_N - first translates each term into boolean should - and scores are only computed as the boost using the top N - scoring terms. Replace N with an integer value. +
top_terms_boost_N - first translates each term into boolean should + and scores are only computed as the boost using the top N + scoring terms. Replace N with an integer value.
- top_terms_N - first translates each term into boolean should - and keeps the scores as computed by the query. Only the top N - scoring terms are used. Replace N with an integer value. +
top_terms_N - first translates each term into boolean should + and keeps the scores as computed by the query. Only the top N + scoring terms are used. Replace N with an integer value.
+
- Default is constant_score_auto. +

Default is constant_score_auto.

- This is an advanced option, use with care. +

This is an advanced option, use with care.

@member ejs.FuzzyQuery @param {String} m The rewrite method as a string. @@ -11132,7 +11836,7 @@ /** - Sets the boost value of the Query. +

Sets the boost value of the Query.

@member ejs.FuzzyQuery @param {Double} boost A positive double value. @@ -11148,7 +11852,8 @@ }, /** - Serializes the internal query object as a JSON string. +

Serializes the internal query object as a JSON string.

+ @member ejs.FuzzyQuery @returns {String} Returns a JSON representation of the Query object. */ @@ -11157,7 +11862,7 @@ }, /** - The type of ejs object. For internal use only. +

The type of ejs object. For internal use only.

@member ejs.FuzzyQuery @returns {String} the type of object @@ -11167,8 +11872,9 @@ }, /** - This method is used to retrieve the raw query object. It's designed - for internal use when composing and serializing queries. +

This method is used to retrieve the raw query object. It's designed + for internal use when composing and serializing queries.

+ @member ejs.FuzzyQuery @returns {Object} Returns the object's query property. */ @@ -11294,7 +12000,40 @@ return this; }, + + /** +

Sets the spatial strategy.

+

Valid values are:

+
+
recursive - default, recursively traverse nodes in + the spatial prefix tree. This strategy has support for + searching non-point shapes.
+
term - uses a large TermsFilter on each node + in the spatial prefix tree. It only supports the search of + indexed Point shapes.
+
+ +

This is an advanced setting, use with care.

+ + @since elasticsearch 0.90 + @member ejs.GeoShapeQuery + @param {String} strategy The strategy as a string. + @returns {Object} returns this so that calls can be chained. + */ + strategy: function (strategy) { + if (strategy == null) { + return query.geo_shape[field].strategy; + } + + strategy = strategy.toLowerCase(); + if (strategy === 'recursive' || strategy === 'term') { + query.geo_shape[field].strategy = strategy; + } + + return this; + }, + /** Sets the boost value for documents matching the Query. @@ -11418,16 +12157,12 @@ Sets the scope of the query. A scope allows to run facets on the same scope name that will work against the child documents. + @deprecated since elasticsearch 0.90 @member ejs.HasChildQuery @param {String} s The scope name as a string. @returns {Object} returns this so that calls can be chained. */ scope: function (s) { - if (s == null) { - return query.has_child._scope; - } - - query.has_child._scope = s; return this; }, @@ -11579,16 +12314,12 @@ Sets the scope of the query. A scope allows to run facets on the same scope name that will work against the parent documents. + @deprecated since elasticsearch 0.90 @member ejs.HasParentQuery @param {String} s The scope name as a string. @returns {Object} returns this so that calls can be chained. */ scope: function (s) { - if (s == null) { - return query.has_parent._scope; - } - - query.has_parent._scope = s; return this; }, @@ -12140,6 +12871,24 @@ return this; }, + /** + Sets the maximum threshold/frequency to be considered a low + frequency term in a CommonTermsQuery. + Set to a value between 0 and 1. + + @member ejs.MatchQuery + @param {Number} freq A positive double value. + @returns {Object} returns this so that calls can be chained. + */ + cutoffFrequency: function (freq) { + if (freq == null) { + return query.match[field].cutoff_frequency; + } + + query.match[field].cutoff_frequency = freq; + return this; + }, + /** Sets the prefix length for a fuzzy prefix MatchQuery. @@ -12376,7 +13125,7 @@ "all" or "none". @member ejs.MatchQuery - @param {String} q A valid analyzer name. + @param {String} q A no match action, "all" or "none". @returns {Object} returns this so that calls can be chained. */ zeroTermsQuery: function (q) { @@ -13120,6 +13869,24 @@ return this; }, + /** + Sets the maximum threshold/frequency to be considered a low + frequency term in a CommonTermsQuery. + Set to a value between 0 and 1. + + @member ejs.MultiMatchQuery + @param {Number} freq A positive double value. + @returns {Object} returns this so that calls can be chained. + */ + cutoffFrequency: function (freq) { + if (freq == null) { + return query.multi_match.cutoff_frequency; + } + + query.multi_match.cutoff_frequency = freq; + return this; + }, + /** Sets a percent value controlling how many "should" clauses in the resulting Query should match. @@ -13403,6 +14170,27 @@ return this; }, + /** + Sets what happens when no terms match. Valid values are + "all" or "none". + + @member ejs.MultiMatchQuery + @param {String} q A no match action, "all" or "none". + @returns {Object} returns this so that calls can be chained. + */ + zeroTermsQuery: function (q) { + if (q == null) { + return query.multi_match.zero_terms_query; + } + + q = q.toLowerCase(); + if (q === 'all' || q === 'none') { + query.multi_match.zero_terms_query = q; + } + + return this; + }, + /** Allows you to serialize this object into a JSON encoded string. @@ -13555,16 +14343,12 @@ Sets the scope of the query. A scope allows to run facets on the same scope name that will work against the nested documents. + @deprecated since elasticsearch 0.90 @member ejs.NestedQuery @param {String} s The scope name as a string. @returns {Object} returns this so that calls can be chained. */ scope: function (s) { - if (s == null) { - return query.nested._scope; - } - - query.nested._scope = s; return this; }, @@ -15801,16 +16585,12 @@ Sets the scope of the query. A scope allows to run facets on the same scope name that will work against the child documents. + @deprecated since elasticsearch 0.90 @member ejs.TopChildrenQuery @param {String} s The scope name as a string. @returns {Object} returns this so that calls can be chained. */ scope: function (s) { - if (s == null) { - return query.top_children._scope; - } - - query.top_children._scope = s; return this; }, @@ -16820,7 +17600,44 @@ */ ejs.Request = function (conf) { - var query, indices, types, routing; + var query, indices, types, params = {}, + + // gernerates the correct url to the specified REST endpoint + getRestPath = function (endpoint) { + var searchUrl = '', + parts = []; + + // join any indices + if (indices.length > 0) { + searchUrl = searchUrl + '/' + indices.join(); + } + + // join any types + if (types.length > 0) { + searchUrl = searchUrl + '/' + types.join(); + } + + // add the endpoint + if (endpoint.length > 0 && endpoint[0] !== '/') { + searchUrl = searchUrl + '/'; + } + + searchUrl = searchUrl + endpoint; + + for (var p in params) { + if (!has(params, p) || params[p] === '') { + continue; + } + + parts.push(p + '=' + encodeURIComponent(params[p])); + } + + if (parts.length > 0) { + searchUrl = searchUrl + '?' + parts.join('&'); + } + + return searchUrl; + }; /** The internal query object. @@ -16855,29 +17672,28 @@ } if (conf.routing != null) { - routing = conf.routing; - } else { - routing = ''; + params.routing = conf.routing; } return { /** - Sets the sorting for the query. This accepts many input formats. +

Sets the sorting for the query. This accepts many input formats.

- 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. +
+
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. +

It is recommended to use Sort objects when possible.

@member ejs.Request @param {String} fieldName The field to be sorted by. @@ -16974,20 +17790,22 @@ }, /** - A search timeout, bounding the search request to be executed - within the specified time value and bail with the hits accumulated - up to that point when expired. Defaults to no timeout. + A timeout, bounding the request to be executed within the + specified time value and bail when expired. Defaults to no timeout. +

This option is valid during the following operations: + search and delete by query

+ @member ejs.Request @param {Long} t The timeout value in milliseconds. @returns {Object} returns this so that calls can be chained. */ timeout: function (t) { if (t == null) { - return query.timeout; + return params.timeout; } - query.timeout = t; + params.timeout = t; return this; }, @@ -16996,19 +17814,129 @@ values will be searched. Set to an empty string to disable routing. Disabled by default. +

This option is valid during the following operations: + search, count and delete by query

+ @member ejs.Request @param {String} route The routing values as a comma-separated string. @returns {Object} returns this so that calls can be chained. */ routing: function (route) { if (route == null) { - return routing; + return params.routing; + } + + params.routing = route; + return this; + }, + + /** +

Sets the replication mode.

+ +

Valid values are:

+ +
+
async - asynchronous replication to slaves
+
sync - synchronous replication to the slaves
+
default - the currently configured system default.
+
+ +

This option is valid during the following operations: + delete by query

+ + @member ejs.Request + @param {String} r The replication mode (async, sync, or default) + @returns {Object} returns this so that calls can be chained. + */ + replication: function (r) { + if (r == null) { + return params.replication; + } + + r = r.toLowerCase(); + if (r === 'async' || r === 'sync' || r === 'default') { + params.replication = r; } + + return this; + }, - routing = route; + /** +

Sets the write consistency.

+ +

Valid values are:

+ +
+
one - only requires write to one shard
+
quorum - requires writes to quorum (N/2 + 1)
+
all - requires write to succeed on all shards
+
default - the currently configured system default
+
+ +

This option is valid during the following operations: + delete by query

+ + @member ejs.Request + @param {String} c The write consistency (one, quorum, all, or default) + @returns {Object} returns this so that calls can be chained. + */ + consistency: function (c) { + if (c == null) { + return params.consistency; + } + + c = c.toLowerCase(); + if (c === 'default' || c === 'one' || c === 'quorum' || c === 'all') { + params.consistency = c; + } + return this; }, + + /** +

Sets the search execution type for the request.

+ +

Valid values are:

+ +
+
dfs_query_then_fetch - same as query_then_fetch, + except distributed term frequencies are calculated first.
+
dfs_query_and_fetch - same as query_and_fetch, + except distributed term frequencies are calculated first.
+
query_then_fetch - executed against all + shards, but only enough information is returned. When ready, + only the relevant shards are asked for the actual document + content
+
query_and_fetch - execute the query on all + relevant shards and return the results, including content.
+
scan - efficiently scroll a large result set
+
count - special search type that returns the + count that matched the search request without any docs
+
+ +

This option is valid during the following operations: + search

+ @member ejs.Request + @param {String} t The search execution type + @returns {Object} returns this so that calls can be chained. + */ + searchType: function (t) { + if (t == null) { + return params.search_type; + } + + t = t.toLowerCase(); + if (t === 'dfs_query_then_fetch' || t === 'dfs_query_and_fetch' || + t === 'query_then_fetch' || t === 'query_and_fetch' || + t === 'scan' || t === 'count') { + + params.search_type = t; + } + + return this; + }, + /** By default, searches return full documents, meaning every property or field. This method allows you to specify which fields you want returned. @@ -17204,6 +18132,39 @@ return this; }, + /** + Allows you to set the specified suggester on this request object. + Multiple suggesters can be set, all of which will be returned when + the search is executed. Global suggestion text can be set by + passing in a string vs. a Suggest object. + + @since elasticsearch 0.90 + + @member ejs.Request + @param {String || Suggest} s A valid Suggest object or a String to + set as the global suggest text. + @returns {Object} returns this so that calls can be chained. + */ + suggest: function (s) { + if (s == null) { + return query.suggest; + } + + if (query.suggest == null) { + query.suggest = {}; + } + + if (isString(s)) { + query.suggest.text = s; + } else if (isSuggest(s)) { + extend(query.suggest, s._self()); + } else { + throw new TypeError('Argument must be a string or Suggest object'); + } + + return this; + }, + /** Computes a document property dynamically based on the supplied ScriptField. @@ -17229,33 +18190,68 @@ }, /** - Controls a preference of which shard replicas to execute the search request on. +

Controls the preference of which shard replicas to execute the search request on. By default, the operation is randomized between the each shard replicas. The - preference can be one of the following: - - _primary - the operation will only be executed on primary shards - _local - the operation will prefer to be executed on local shards - _only_node:$nodeid - the search will only be executed on node with id $nodeid - custom - any string, will guarentee searches always happen on same node. - + preference can be one of the following:

+ +
+
_primary - the operation will only be executed on primary shards
+
_local - the operation will prefer to be executed on local shards
+
_only_node:$nodeid - the search will only be executed on node with id $nodeid
+
custom - any string, will guarentee searches always happen on same node.
+
+ +

This option is valid during the following operations: + search and count

+ @member ejs.Request - @param {String} perf the preference, any of _primary, _local, _only_:$nodeid, or a custom string value. + @param {String} perf the preference, any of _primary, _local, + _only_:$nodeid, or a custom string value. @returns {Object} returns this so that calls can be chained. */ preference: function (perf) { if (perf == null) { - return query.preference; + return params.preference; } - query.preference = perf; + params.preference = perf; return this; }, /** - Boosts hits in the specified index by the given boost value. +

Determines what type of indices to exclude from a request. The + value can be one of the following:

+
+
none - No indices / aliases will be excluded from a request
+
missing - Indices / aliases that are missing will be excluded from a request
+
+ +

This option is valid during the following operations: + search, count and delete by query

+ @member ejs.Request - @param {String} index the index to boost + @param {String} ignoreType the type of ignore (none or missing). + @returns {Object} returns this so that calls can be chained. + */ + ignoreIndices: function (ignoreType) { + if (ignoreType == null) { + return params.ignore_indices; + } + + ignoreType = ignoreType.toLowerCase(); + if (ignoreType === 'none' || ignoreType === 'missing') { + params.ignore_indices = ignoreType; + } + + return this; + }, + + /** + Boosts hits in the specified index by the given boost value. + + @member ejs.Request + @param {String} index the index to boost @param {Double} boost the boost value @returns {Object} returns this so that calls can be chained. */ @@ -17350,41 +18346,62 @@ _self: function () { return query; }, - - /** - Executes the search. This call runs synchronously when used on the server side. - The callback is still executed and the function returns the return value of the callback. + /** + Executes a delete by query request using the current query. + @member ejs.Request - @param {Function} fnCallBack A callback function that handles the search response. - @returns {void} Returns the value of the callback when executing on the server. + @param {Function} successcb A callback function that handles the response. + @param {Function} errorcb A callback function that handles errors. + @returns {Object} Returns a client specific object. */ - doSearch: function (fnCallBack) { - var - queryData = JSON.stringify(query), - searchUrl = ''; + doDeleteByQuery: function (successcb, errorcb) { + var queryData = JSON.stringify(query.query); // make sure the user has set a client if (ejs.client == null) { throw new Error("No Client Set"); } - - // generate the search url - if (indices.length > 0) { - searchUrl = searchUrl + '/' + indices.join(); - } + + return ejs.client.del(getRestPath('_query'), queryData, successcb, errorcb); + }, - if (types.length > 0) { - searchUrl = searchUrl + '/' + types.join(); + /** + Executes a count request using the current query. + + @member ejs.Request + @param {Function} successcb A callback function that handles the count response. + @param {Function} errorcb A callback function that handles errors. + @returns {Object} Returns a client specific object. + */ + doCount: function (successcb, errorcb) { + var queryData = JSON.stringify(query.query); + + // make sure the user has set a client + if (ejs.client == null) { + throw new Error("No Client Set"); } - searchUrl = searchUrl + '/_search'; - - if (routing !== '') { - searchUrl = searchUrl + '?routing=' + encodeURIComponent(routing); - } + return ejs.client.post(getRestPath('_count'), queryData, successcb, errorcb); + }, + + /** + Executes the search. - return ejs.client.post(searchUrl, queryData, fnCallBack); + @member ejs.Request + @param {Function} successcb A callback function that handles the search response. + @param {Function} errorcb A callback function that handles errors. + @returns {Object} Returns a client specific object. + */ + doSearch: function (successcb, errorcb) { + var queryData = JSON.stringify(query); + + // make sure the user has set a client + if (ejs.client == null) { + throw new Error("No Client Set"); + } + + return ejs.client.post(getRestPath('_search'), queryData, successcb, errorcb); } }; }; @@ -17461,6 +18478,23 @@ return this; }, + /** + If execeptions thrown from the script should be ignored or not. + Default: false + + @member ejs.ScriptField + @param {Boolean} trueFalse if execptions should be ignored + @returns {Object} returns this so that calls can be chained. + */ + ignoreFailure: function (trueFalse) { + if (trueFalse == null) { + return script[fieldName].ignore_failure; + } + + script[fieldName].ignore_failure = trueFalse; + return this; + }, + /** Allows you to serialize this object into a JSON encoded string. @@ -17926,8 +18960,10 @@ /** Sets the script sort type. Valid values are: - string - script return value is sorted as a string - number - script return value is sorted as a number +
+
string - script return value is sorted as a string
+
number - script return value is sorted as a number
+
Valid during sort types: script @@ -17947,7 +18983,78 @@ return this; }, - + + /** + Sets the sort mode. Valid values are: + +
+
min - sort by lowest value
+
max - sort by highest value
+
sum - sort by the sum of all values
+
avg - sort by the average of all values
+
+ + Valid during sort types: field + + @since elasticsearch 0.90 + @member ejs.Sort + @param {String} m The sort mode. Either min, max, sum, or avg. + @returns {Object} returns this so that calls can be chained. + */ + mode: function (m) { + if (m == null) { + return sort[key].mode; + } + + m = m.toLowerCase(); + if (m === 'min' || m === 'max' || m === 'sum' || m === 'avg') { + sort[key].mode = m; + } + + return this; + }, + + /** + Sets the path of the nested object. + + Valid during sort types: field + + @since elasticsearch 0.90 + @member ejs.Sort + @param {String} path The nested path value. + @returns {Object} returns this so that calls can be chained. + */ + nestedPath: function (path) { + if (path == null) { + return sort[key].nested_path; + } + + sort[key].nested_path = path; + return this; + }, + + /** +

Allows you to set a filter that nested objects must match + in order to be considered during sorting.

+ + @since elasticsearch 0.90 + @member ejs.Sort + @param {Object} oFilter A valid Filter object. + @returns {Object} returns this so that calls can be chained. + */ + nestedFilter: function (oFilter) { + if (oFilter == null) { + return sort[key].nested_filter; + } + + if (!isFilter(oFilter)) { + throw new TypeError('Argument must be a Filter'); + } + + sort[key].nested_filter = oFilter._self(); + return this; + }, + /** Allows you to serialize this object into a JSON encoded string. @@ -17981,6 +19088,902 @@ }; }; + /** + @class +

DirectGenerator is a candidate generator for PhraseSuggester. + It generates terms based on edit distance and operators much like the + TermSuggester.

+ + @name ejs.DirectGenerator + + @since elasticsearch 0.90 + + @desc +

A candidate generator that generates terms based on edit distance.

+ + @borrows ejs.DirectSettingsMixin.accuracy as accuracy + @borrows ejs.DirectSettingsMixin.suggestMode as suggestMode + @borrows ejs.DirectSettingsMixin.sort as sort + @borrows ejs.DirectSettingsMixin.stringDistance as stringDistance + @borrows ejs.DirectSettingsMixin.maxEdits as maxEdits + @borrows ejs.DirectSettingsMixin.maxInspections as maxInspections + @borrows ejs.DirectSettingsMixin.maxTermFreq as maxTermFreq + @borrows ejs.DirectSettingsMixin.prefixLength as prefixLength + @borrows ejs.DirectSettingsMixin.minWordLen as minWordLen + @borrows ejs.DirectSettingsMixin.minDocFreq as minDocFreq + */ + ejs.DirectGenerator = function () { + + + var + + // common suggester options used in this generator + _common = ejs.DirectSettingsMixin(), + + /** + The internal generator object. + @member ejs.DirectGenerator + @property {Object} suggest + */ + generator = _common._self(); + + return extend(_common, { + + /** +

Sets an analyzer that is applied to each of the tokens passed to + this generator. The analyzer is applied to the original tokens, + not the generated tokens.

+ + @member ejs.DirectGenerator + @param {String} analyzer A valid analyzer name. + @returns {Object} returns this so that calls can be chained. + */ + preFilter: function (analyzer) { + if (analyzer == null) { + return generator.pre_filter; + } + + generator.pre_filter = analyzer; + return this; + }, + + /** +

Sets an analyzer that is applied to each of the generated tokens + before they are passed to the actual phrase scorer.

+ + @member ejs.DirectGenerator + @param {String} analyzer A valid analyzer name. + @returns {Object} returns this so that calls can be chained. + */ + postFilter: function (analyzer) { + if (analyzer == null) { + return generator.post_filter; + } + + generator.post_filter = analyzer; + return this; + }, + + /** +

Sets the field used to generate suggestions from.

+ + @member ejs.DirectGenerator + @param {String} field A valid field name. + @returns {Object} returns this so that calls can be chained. + */ + field: function (field) { + if (field == null) { + return generator.field; + } + + generator.field = field; + return this; + }, + + /** +

Sets the number of suggestions returned for each token.

+ + @member ejs.DirectGenerator + @param {Integer} s A positive integer value. + @returns {Object} returns this so that calls can be chained. + */ + size: function (s) { + if (s == null) { + return generator.size; + } + + generator.size = s; + return this; + }, + + /** +

Allows you to serialize this object into a JSON encoded string.

+ + @member ejs.DirectGenerator + @returns {String} returns this object as a serialized JSON string. + */ + toString: function () { + return JSON.stringify(generator); + }, + + /** + The type of ejs object. For internal use only. + + @member ejs.DirectGenerator + @returns {String} the type of object + */ + _type: function () { + return 'generator'; + }, + + /** +

Retrieves the internal generator object. This is typically used by + internal API functions so use with caution.

+ + @member ejs.DirectGenerator + @returns {String} returns this object's internal generator property. + */ + _self: function () { + return generator; + } + }); + }; + + /** + @mixin +

The DirectSettingsMixin provides support for common options used across + various Suggester implementations. This object should not be + used directly.

+ + @name ejs.DirectSettingsMixin + */ + ejs.DirectSettingsMixin = function () { + + /** + The internal settings object. + @member ejs.DirectSettingsMixin + @property {Object} settings + */ + var settings = {}; + + return { + + /** +

Sets the accuracy. How similar the suggested terms at least + need to be compared to the original suggest text.

+ + @member ejs.DirectSettingsMixin + @param {Double} a A positive double value between 0 and 1. + @returns {Object} returns this so that calls can be chained. + */ + accuracy: function (a) { + if (a == null) { + return settings.accuracy; + } + + settings.accuracy = a; + return this; + }, + + /** +

Sets the suggest mode. Valid values are:

+ +
+
missing - Only suggest terms in the suggest text that aren't in the index
+
popular - Only suggest suggestions that occur in more docs then the original suggest text term
+
always - Suggest any matching suggestions based on terms in the suggest text
+
+ + @member ejs.DirectSettingsMixin + @param {String} m The mode of missing, popular, or always. + @returns {Object} returns this so that calls can be chained. + */ + suggestMode: function (m) { + if (m == null) { + return settings.suggest_mode; + } + + m = m.toLowerCase(); + if (m === 'missing' || m === 'popular' || m === 'always') { + settings.suggest_mode = m; + } + + return this; + }, + + /** +

Sets the sort mode. Valid values are:

+ +
+
score - Sort by score first, then document frequency, and then the term itself
+
frequency - Sort by document frequency first, then simlarity score and then the term itself
+
+ + @member ejs.DirectSettingsMixin + @param {String} s The score type of score or frequency. + @returns {Object} returns this so that calls can be chained. + */ + sort: function (s) { + if (s == null) { + return settings.sort; + } + + s = s.toLowerCase(); + if (s === 'score' || s === 'frequency') { + settings.sort = s; + } + + return this; + }, + + /** +

Sets what string distance implementation to use for comparing + how similar suggested terms are. Valid values are:

+ +
+
internal - based on damerau_levenshtein but but highly optimized for comparing string distance for terms inside the index
+
damerau_levenshtein - String distance algorithm based on Damerau-Levenshtein algorithm
+
levenstein - String distance algorithm based on Levenstein edit distance algorithm
+
jarowinkler - String distance algorithm based on Jaro-Winkler algorithm
+
ngram - String distance algorithm based on character n-grams
+
+ + @member ejs.DirectSettingsMixin + @param {String} s The string distance algorithm name. + @returns {Object} returns this so that calls can be chained. + */ + stringDistance: function (s) { + if (s == null) { + return settings.string_distance; + } + + s = s.toLowerCase(); + if (s === 'internal' || s === 'damerau_levenshtein' || + s === 'levenstein' || s === 'jarowinkler' || s === 'ngram') { + settings.string_distance = s; + } + + return this; + }, + + /** +

Sets the maximum edit distance candidate suggestions can have + in order to be considered as a suggestion.

+ + @member ejs.DirectSettingsMixin + @param {Integer} max An integer value greater than 0. + @returns {Object} returns this so that calls can be chained. + */ + maxEdits: function (max) { + if (max == null) { + return settings.max_edits; + } + + settings.max_edits = max; + return this; + }, + + /** +

The factor that is used to multiply with the size in order + to inspect more candidate suggestions.

+ + @member ejs.DirectSettingsMixin + @param {Integer} max A positive integer value. + @returns {Object} returns this so that calls can be chained. + */ + maxInspections: function (max) { + if (max == null) { + return settings.max_inspections; + } + + settings.max_inspections = max; + return this; + }, + + /** +

Sets a maximum threshold in number of documents a suggest text + token can exist in order to be corrected.

+ + @member ejs.DirectSettingsMixin + @param {Double} max A positive double value. + @returns {Object} returns this so that calls can be chained. + */ + maxTermFreq: function (max) { + if (max == null) { + return settings.max_term_freq; + } + + settings.max_term_freq = max; + return this; + }, + + /** +

Sets the number of minimal prefix characters that must match in + order be a candidate suggestion.

+ + @member ejs.DirectSettingsMixin + @param {Integer} len A positive integer value. + @returns {Object} returns this so that calls can be chained. + */ + prefixLength: function (len) { + if (len == null) { + return settings.prefix_length; + } + + settings.prefix_length = len; + return this; + }, + + /** +

Sets the minimum length a suggest text term must have in order + to be corrected.

+ + @member ejs.DirectSettingsMixin + @param {Integer} len A positive integer value. + @returns {Object} returns this so that calls can be chained. + */ + minWordLen: function (len) { + if (len == null) { + return settings.min_word_len; + } + + settings.min_word_len = len; + return this; + }, + + /** +

Sets a minimal threshold of the number of documents a suggested + term should appear in.

+ + @member ejs.DirectSettingsMixin + @param {Double} min A positive double value. + @returns {Object} returns this so that calls can be chained. + */ + minDocFreq: function (min) { + if (min == null) { + return settings.min_doc_freq; + } + + settings.min_doc_freq = min; + return this; + }, + + /** +

Retrieves the internal settings object. This is typically used by + internal API functions so use with caution.

+ + @member ejs.DirectSettingsMixin + @returns {String} returns this object's internal settings property. + */ + _self: function () { + return settings; + } + }; + }; + + /** + @class +

PhraseSuggester extends the PhraseSuggester and suggests + entire corrected phrases instead of individual tokens. The individual + phrase suggestions are weighted based on ngram-langugage models. In practice + it will be able to make better decision about which tokens to pick based on + co-occurence and frequencies.

+ + @name ejs.PhraseSuggester + + @since elasticsearch 0.90 + + @desc +

A suggester that suggests entire corrected phrases.

+ + @param {String} name The name which be used to refer to this suggester. + */ + ejs.PhraseSuggester = function (name) { + + /** + The internal suggest object. + @member ejs.PhraseSuggester + @property {Object} suggest + */ + var suggest = {}; + suggest[name] = {phrase: {}}; + + return { + + /** +

Sets the text to get suggestions for. If not set, the global + suggestion text will be used.

+ + @member ejs.PhraseSuggester + @param {String} txt A string to get suggestions for. + @returns {Object} returns this so that calls can be chained. + */ + text: function (txt) { + if (txt == null) { + return suggest[name].text; + } + + suggest[name].text = txt; + return this; + }, + + /** +

Sets analyzer used to analyze the suggest text.

+ + @member ejs.PhraseSuggester + @param {String} analyzer A valid analyzer name. + @returns {Object} returns this so that calls can be chained. + */ + analyzer: function (analyzer) { + if (analyzer == null) { + return suggest[name].phrase.analyzer; + } + + suggest[name].phrase.analyzer = analyzer; + return this; + }, + + /** +

Sets the field used to generate suggestions from.

+ + @member ejs.PhraseSuggester + @param {String} field A valid field name. + @returns {Object} returns this so that calls can be chained. + */ + field: function (field) { + if (field == null) { + return suggest[name].phrase.field; + } + + suggest[name].phrase.field = field; + return this; + }, + + /** +

Sets the number of suggestions returned for each token.

+ + @member ejs.PhraseSuggester + @param {Integer} s A positive integer value. + @returns {Object} returns this so that calls can be chained. + */ + size: function (s) { + if (s == null) { + return suggest[name].phrase.size; + } + + suggest[name].phrase.size = s; + return this; + }, + + /** +

Sets the maximum number of suggestions to be retrieved from + each individual shard.

+ + @member ejs.PhraseSuggester + @param {Integer} s A positive integer value. + @returns {Object} returns this so that calls can be chained. + */ + shardSize: function (s) { + if (s == null) { + return suggest[name].phrase.shard_size; + } + + suggest[name].phrase.shard_size = s; + return this; + }, + + /** +

Sets the likelihood of a term being a misspelled even if the + term exists in the dictionary. The default it 0.95 corresponding + to 5% or the real words are misspelled.

+ + @member ejs.PhraseSuggester + @param {Double} l A positive double value greater than 0.0. + @returns {Object} returns this so that calls can be chained. + */ + realWorldErrorLikelihood: function (l) { + if (l == null) { + return suggest[name].phrase.real_world_error_likelihood; + } + + suggest[name].phrase.real_world_error_likelihood = l; + return this; + }, + + /** +

Sets the confidence level defines a factor applied to the input + phrases score which is used as a threshold for other suggest + candidates. Only candidates that score higher than the threshold + will be included in the result.

+ + @member ejs.PhraseSuggester + @param {Double} c A positive double value. + @returns {Object} returns this so that calls can be chained. + */ + confidence: function (c) { + if (c == null) { + return suggest[name].phrase.confidence; + } + + suggest[name].phrase.confidence = c; + return this; + }, + + /** +

Sets the separator that is used to separate terms in the bigram + field. If not set the whitespce character is used as a + separator.

+ + @member ejs.PhraseSuggester + @param {String} sep A string separator. + @returns {Object} returns this so that calls can be chained. + */ + separator: function (sep) { + if (sep == null) { + return suggest[name].phrase.separator; + } + + suggest[name].phrase.separator = sep; + return this; + }, + + /** +

Sets the maximum percentage of the terms that at most + considered to be misspellings in order to form a correction.

+ + @member ejs.PhraseSuggester + @param {Double} c A positive double value greater between 0 and 1. + @returns {Object} returns this so that calls can be chained. + */ + maxErrors: function (max) { + if (max == null) { + return suggest[name].phrase.max_errors; + } + + suggest[name].phrase.max_errors = max; + return this; + }, + + /** +

Sets the max size of the n-grams (shingles) in the field. If + the field doesn't contain n-grams (shingles) this should be + omitted or set to 1.

+ + @member ejs.PhraseSuggester + @param {Integer} s A positive integer value. + @returns {Object} returns this so that calls can be chained. + */ + gramSize: function (s) { + if (s == null) { + return suggest[name].phrase.gram_size; + } + + suggest[name].phrase.gram_size = s; + return this; + }, + + /** +

Forces the use of unigrams.

+ + @member ejs.PhraseSuggester + @param {Boolean} trueFalse True to force unigrams, false otherwise. + @returns {Object} returns this so that calls can be chained. + */ + forceUnigrams: function (trueFalse) { + if (trueFalse == null) { + return suggest[name].phrase.force_unigrams; + } + + suggest[name].phrase.force_unigrams = trueFalse; + return this; + }, + + /** +

A smoothing model that takes the weighted mean of the unigrams, + bigrams and trigrams based on user supplied weights (lambdas). The + sum of tl, bl, and ul must equal 1.

+ + @member ejs.PhraseSuggester + @param {Double} tl A positive double value used for trigram weight. + @param {Double} bl A positive double value used for bigram weight. + @param {Double} ul A positive double value used for unigram weight. + @returns {Object} returns this so that calls can be chained. + */ + linearSmoothing: function (tl, bl, ul) { + if (arguments.length === 0) { + return suggest[name].phrase.smoothing; + } + + suggest[name].phrase.smoothing = { + linear: { + trigram_lambda: tl, + bigram_lambda: bl, + unigram_lambda: ul + } + }; + + return this; + }, + + /** +

A smoothing model that uses an additive smoothing model where a + constant (typically 1.0 or smaller) is added to all counts to + balance weights, The default alpha is 0.5.

+ + @member ejs.PhraseSuggester + @param {Double} alpha A double value. + @returns {Object} returns this so that calls can be chained. + */ + laplaceSmoothing: function (alpha) { + if (alpha == null) { + return suggest[name].phrase.smoothing; + } + + suggest[name].phrase.smoothing = { + laplace: { + alpha: alpha + } + }; + + return this; + }, + + /** +

A simple backoff model that backs off to lower order n-gram + models if the higher order count is 0 and discounts the lower + order n-gram model by a constant factor. The default discount is + 0.4.

+ + @member ejs.PhraseSuggester + @param {Double} discount A double value. + @returns {Object} returns this so that calls can be chained. + */ + stupidBackoffSmoothing: function (discount) { + if (discount == null) { + return suggest[name].phrase.smoothing; + } + + suggest[name].phrase.smoothing = { + stupid_backoff: { + discount: discount + } + }; + + return this; + }, + + /** + Adds a direct generator. If passed a single Generator + it is added to the list of existing generators. If passed an + array of Generators, they replace all existing generators. + + @member ejs.PhraseSuggester + @param {Generator || Array} oGenerator A valid Generator or + array of Generator objects. + @returns {Object} returns this so that calls can be chained. + */ + directGenerator: function (oGenerator) { + var i, len; + + if (suggest[name].phrase.direct_generator == null) { + suggest[name].phrase.direct_generator = []; + } + + if (oGenerator == null) { + return suggest[name].phrase.direct_generator; + } + + if (isGenerator(oGenerator)) { + suggest[name].phrase.direct_generator.push(oGenerator._self()); + } else if (isArray(oGenerator)) { + suggest[name].phrase.direct_generator = []; + for (i = 0, len = oGenerator.length; i < len; i++) { + if (!isGenerator(oGenerator[i])) { + throw new TypeError('Argument must be an array of Generators'); + } + + suggest[name].phrase.direct_generator.push(oGenerator[i]._self()); + } + } else { + throw new TypeError('Argument must be a Generator or array of Generators'); + } + + return this; + }, + + /** +

Allows you to serialize this object into a JSON encoded string.

+ + @member ejs.PhraseSuggester + @returns {String} returns this object as a serialized JSON string. + */ + toString: function () { + return JSON.stringify(suggest); + }, + + /** + The type of ejs object. For internal use only. + + @member ejs.PhraseSuggester + @returns {String} the type of object + */ + _type: function () { + return 'suggest'; + }, + + /** +

Retrieves the internal suggest object. This is typically used by + internal API functions so use with caution.

+ + @member ejs.PhraseSuggester + @returns {String} returns this object's internal suggest property. + */ + _self: function () { + return suggest; + } + }; + }; + + /** + @class +

TermSuggester suggests terms based on edit distance. The provided suggest + text is analyzed before terms are suggested. The suggested terms are + provided per analyzed suggest text token. This leaves the suggest-selection + to the API consumer. For a higher level suggester, please use the + PhraseSuggester.

+ + @name ejs.TermSuggester + + @since elasticsearch 0.90 + + @desc +

A suggester that suggests terms based on edit distance.

+ + @borrows ejs.DirectSettingsMixin.accuracy as accuracy + @borrows ejs.DirectSettingsMixin.suggestMode as suggestMode + @borrows ejs.DirectSettingsMixin.sort as sort + @borrows ejs.DirectSettingsMixin.stringDistance as stringDistance + @borrows ejs.DirectSettingsMixin.maxEdits as maxEdits + @borrows ejs.DirectSettingsMixin.maxInspections as maxInspections + @borrows ejs.DirectSettingsMixin.maxTermFreq as maxTermFreq + @borrows ejs.DirectSettingsMixin.prefixLength as prefixLength + @borrows ejs.DirectSettingsMixin.minWordLen as minWordLen + @borrows ejs.DirectSettingsMixin.minDocFreq as minDocFreq + + @param {String} name The name which be used to refer to this suggester. + */ + ejs.TermSuggester = function (name) { + + /** + The internal suggest object. + @member ejs.TermSuggester + @property {Object} suggest + */ + var suggest = {}, + + // common suggester options + _common = ejs.DirectSettingsMixin(); + + // setup correct term suggestor format + suggest[name] = {term: _common._self()}; + + return extend(_common, { + + /** +

Sets the text to get suggestions for. If not set, the global + suggestion text will be used.

+ + @member ejs.TermSuggester + @param {String} txt A string to get suggestions for. + @returns {Object} returns this so that calls can be chained. + */ + text: function (txt) { + if (txt == null) { + return suggest[name].text; + } + + suggest[name].text = txt; + return this; + }, + + /** +

Sets analyzer used to analyze the suggest text.

+ + @member ejs.TermSuggester + @param {String} analyzer A valid analyzer name. + @returns {Object} returns this so that calls can be chained. + */ + analyzer: function (analyzer) { + if (analyzer == null) { + return suggest[name].term.analyzer; + } + + suggest[name].term.analyzer = analyzer; + return this; + }, + + /** +

Sets the field used to generate suggestions from.

+ + @member ejs.TermSuggester + @param {String} field A valid field name. + @returns {Object} returns this so that calls can be chained. + */ + field: function (field) { + if (field == null) { + return suggest[name].term.field; + } + + suggest[name].term.field = field; + return this; + }, + + /** +

Sets the number of suggestions returned for each token.

+ + @member ejs.TermSuggester + @param {Integer} s A positive integer value. + @returns {Object} returns this so that calls can be chained. + */ + size: function (s) { + if (s == null) { + return suggest[name].term.size; + } + + suggest[name].term.size = s; + return this; + }, + + /** +

Sets the maximum number of suggestions to be retrieved from + each individual shard.

+ + @member ejs.TermSuggester + @param {Integer} s A positive integer value. + @returns {Object} returns this so that calls can be chained. + */ + shardSize: function (s) { + if (s == null) { + return suggest[name].term.shard_size; + } + + suggest[name].term.shard_size = s; + return this; + }, + + /** +

Allows you to serialize this object into a JSON encoded string.

+ + @member ejs.TermSuggester + @returns {String} returns this object as a serialized JSON string. + */ + toString: function () { + return JSON.stringify(suggest); + }, + + /** + The type of ejs object. For internal use only. + + @member ejs.TermSuggester + @returns {String} the type of object + */ + _type: function () { + return 'suggest'; + }, + + /** +

Retrieves the internal suggest object. This is typically used by + internal API functions so use with caution.

+ + @member ejs.TermSuggester + @returns {String} returns this object's internal suggest property. + */ + _self: function () { + return suggest; + } + }); + }; + // run in noConflict mode ejs.noConflict = function () { root.ejs = _ejs; diff --git a/common/lib/elastic.min.js b/common/lib/elastic.min.js index b63fb6de718..586930115e7 100644 --- a/common/lib/elastic.min.js +++ b/common/lib/elastic.min.js @@ -1,4 +1,4 @@ -/*! elastic.js - v1.0.0 - 2013-01-15 +/*! elastic.js - v1.0.0 - 2013-04-04 * https://github.com/fullscale/elastic.js * Copyright (c) 2013 FullScale Labs, LLC; Licensed MIT */ -(function(){"use strict";var e=this,t=e&&e.ejs,n=Array.prototype,r=Object.prototype,i=n.slice,s=r.toString,o=r.hasOwnProperty,u=n.forEach,a=Array.isArray,f={},l,c,h,p,d,v,m,g,y,b,w,E,S,x,T,N,C,k,L;typeof exports!="undefined"?L=exports:L=e.ejs={},l=function(e,t){return o.call(e,t)},c=function(e,t,n){if(e==null)return;if(u&&e.forEach===u)e.forEach(t,n);else if(e.length===+e.length){for(var r=0,i=e.length;r0&&(n=["_all"]),e.routing!=null?i=e.routing:i="",{sort:function(){var e,n;l(t,"sort")||(t.sort=[]);if(arguments.length===0)return t.sort;if(arguments.length===1){var r=arguments[0];if(v(r))t.sort.push(r);else if(C(r))t.sort.push(r._self());else{if(!p(r))throw new TypeError("Argument must be string, Sort, or array");t.sort=[];for(e=0,n=r.length;e0&&(n=["_all"]),this},types:function(e){if(e==null)return r;if(v(e))r=[e];else{if(!p(e))throw new TypeError("Argument must be a string or array");r=e}return n.length===0&&r.length>0&&(n=["_all"]),this},facet:function(e){if(e==null)return t.facets;t.facets==null&&(t.facets={});if(!E(e))throw new TypeError("Argument must be a Facet");return h(t.facets,e._self()),this},filter:function(e){if(e==null)return t.filter;if(!w(e))throw new TypeError("Argument must be a Filter");return t.filter=e._self(),this},highlight:function(e){if(e==null)return t.highlight;if(!k(e))throw new TypeError("Argument must be a Highlight object");return t.highlight=e._self(),this},scriptField:function(e){if(e==null)return t.script_fields;t.script_fields==null&&(t.script_fields={});if(!S(e))throw new TypeError("Argument must be a ScriptField");return h(t.script_fields,e._self()),this},preference:function(e){return e==null?t.preference:(t.preference=e,this)},indexBoost:function(e,n){return t.indices_boost==null&&(t.indices_boost={}),arguments.length===0?t.indices_boost:(t.indices_boost[e]=n,this)},explain:function(e){return e==null?t.explain:(t.explain=e,this)},version:function(e){return e==null?t.version:(t.version=e,this)},minScore:function(e){return e==null?t.min_score:(t.min_score=e,this)},toString:function(){return JSON.stringify(t)},_type:function(){return"request"},_self:function(){return t},doSearch:function(e){var s=JSON.stringify(t),o="";if(L.client==null)throw new Error("No Client Set");return n.length>0&&(o=o+"/"+n.join()),r.length>0&&(o=o+"/"+r.join()),o+="/_search",i!==""&&(o=o+"?routing="+encodeURIComponent(i)),L.client.post(o,s,e)}}},L.ScriptField=function(e){var t={};return t[e]={},{lang:function(n){return n==null?t[e].lang:(t[e].lang=n,this)},script:function(n){return n==null?t[e].script:(t[e].script=n,this)},params:function(n){return n==null?t[e].params:(t[e].params=n,this)},toString:function(){return JSON.stringify(t)},_type:function(){return"script field"},_self:function(){return t}}},L.Shape=function(e,t){var n={},r=function(e){var t=!1;if(e==="point"||e==="linestring"||e==="polygon"||e==="multipoint"||e==="envelope"||e==="multipolygon")t=!0;return t};return e=e.toLowerCase(),r(e)&&(n.type=e,n.coordinates=t),{type:function(e){return e==null?n.type:(e=e.toLowerCase(),r(e)&&(n.type=e),this)},coordinates:function(e){return e==null?n.coordinates:(n.coordinates=e,this)},toString:function(){return JSON.stringify(n)},_type:function(){return"shape"},_self:function(){return n}}},L.Sort=function(e){e==null&&(e="_score");var t={},n=e,r="_geo_distance",i="_script";return t[n]={},{field:function(r){var i=t[n];return r==null?e:(delete t[n],e=r,n=r,t[n]=i,this)},geoDistance:function(i){var s=t[n];if(i==null)return t[n][e];if(!x(i))throw new TypeError("Argument must be a GeoPoint");return delete t[n],n=r,t[n]=s,t[n][e]=i._self(),this},script:function(e){var r=t[n];return e==null?t[n].script:(delete t[n],n=i,t[n]=r,t[n].script=e,this)},order:function(e){if(e==null)return t[n].order;e=e.toLowerCase();if(e==="asc"||e==="desc")t[n].order=e;return this},asc:function(){return t[n].order="asc",this},desc:function(){return t[n].order="desc",this},reverse:function(e){return e==null?t[n].reverse:(t[n].reverse=e,this)},missing:function(e){return e==null?t[n].missing:(t[n].missing=e,this)},ignoreUnmapped:function(e){return e==null?t[n].ignore_unmapped:(t[n].ignore_unmapped=e,this)},unit:function(e){if(e==null)return t[n].unit;e=e.toLowerCase();if(e==="mi"||e==="km")t[n].unit=e;return this},normalize:function(e){return e==null?t[n].normalize:(t[n].normalize=e,this)},distanceType:function(e){if(e==null)return t[n].distance_type;e=e.toLowerCase();if(e==="arc"||e==="plane")t[n].distance_type=e;return this},params:function(e){return e==null?t[n].params:(t[n].params=e,this)},lang:function(e){return e==null?t[n].lang:(t[n].lang=e,this)},type:function(e){if(e==null)return t[n].type;e=e.toLowerCase();if(e==="string"||e==="number")t[n].type=e;return this},toString:function(){return JSON.stringify(t)},_type:function(){return"sort"},_self:function(){return t}}},L.noConflict=function(){return e.ejs=t,this}}).call(this); \ No newline at end of file +(function(){"use strict";var e=this,t=e&&e.ejs,n=Array.prototype,r=Object.prototype,i=n.slice,s=r.toString,o=r.hasOwnProperty,u=n.forEach,a=Array.isArray,f={},l,c,h,p,d,v,m,g,y,b,w,E,S,x,T,N,C,k,L,A,O;typeof exports!="undefined"?O=exports:O=e.ejs={},l=function(e,t){return o.call(e,t)},c=function(e,t,n){if(e==null)return;if(u&&e.forEach===u)e.forEach(t,n);else if(e.length===+e.length){for(var r=0,i=e.length;r0&&(t=t+"/"+n.join()),r.length>0&&(t=t+"/"+r.join()),e.length>0&&e[0]!=="/"&&(t+="/"),t+=e;for(var o in i){if(!l(i,o)||i[o]==="")continue;s.push(o+"="+encodeURIComponent(i[o]))}return s.length>0&&(t=t+"?"+s.join("&")),t};return t={},e=e||{},e.indices==null?n=[]:v(e.indices)?n=[e.indices]:n=e.indices,e.types==null?r=[]:v(e.types)?r=[e.types]:r=e.types,n.length===0&&r.length>0&&(n=["_all"]),e.routing!=null&&(i.routing=e.routing),{sort:function(){var e,n;l(t,"sort")||(t.sort=[]);if(arguments.length===0)return t.sort;if(arguments.length===1){var r=arguments[0];if(v(r))t.sort.push(r);else if(C(r))t.sort.push(r._self());else{if(!p(r))throw new TypeError("Argument must be string, Sort, or array");t.sort=[];for(e=0,n=r.length;e0&&(n=["_all"]),this},types:function(e){if(e==null)return r;if(v(e))r=[e];else{if(!p(e))throw new TypeError("Argument must be a string or array");r=e}return n.length===0&&r.length>0&&(n=["_all"]),this},facet:function(e){if(e==null)return t.facets;t.facets==null&&(t.facets={});if(!E(e))throw new TypeError("Argument must be a Facet");return h(t.facets,e._self()),this},filter:function(e){if(e==null)return t.filter;if(!w(e))throw new TypeError("Argument must be a Filter");return t.filter=e._self(),this},highlight:function(e){if(e==null)return t.highlight;if(!k(e))throw new TypeError("Argument must be a Highlight object");return t.highlight=e._self(),this},suggest:function(e){if(e==null)return t.suggest;t.suggest==null&&(t.suggest={});if(v(e))t.suggest.text=e;else{if(!L(e))throw new TypeError("Argument must be a string or Suggest object");h(t.suggest,e._self())}return this},scriptField:function(e){if(e==null)return t.script_fields;t.script_fields==null&&(t.script_fields={});if(!S(e))throw new TypeError("Argument must be a ScriptField");return h(t.script_fields,e._self()),this},preference:function(e){return e==null?i.preference:(i.preference=e,this)},ignoreIndices:function(e){if(e==null)return i.ignore_indices;e=e.toLowerCase();if(e==="none"||e==="missing")i.ignore_indices=e;return this},indexBoost:function(e,n){return t.indices_boost==null&&(t.indices_boost={}),arguments.length===0?t.indices_boost:(t.indices_boost[e]=n,this)},explain:function(e){return e==null?t.explain:(t.explain=e,this)},version:function(e){return e==null?t.version:(t.version=e,this)},minScore:function(e){return e==null?t.min_score:(t.min_score=e,this)},toString:function(){return JSON.stringify(t)},_type:function(){return"request"},_self:function(){return t},doDeleteByQuery:function(e,n){var r=JSON.stringify(t.query);if(O.client==null)throw new Error("No Client Set");return O.client.del(s("_query"),r,e,n)},doCount:function(e,n){var r=JSON.stringify(t.query);if(O.client==null)throw new Error("No Client Set");return O.client.post(s("_count"),r,e,n)},doSearch:function(e,n){var r=JSON.stringify(t);if(O.client==null)throw new Error("No Client Set");return O.client.post(s("_search"),r,e,n)}}},O.ScriptField=function(e){var t={};return t[e]={},{lang:function(n){return n==null?t[e].lang:(t[e].lang=n,this)},script:function(n){return n==null?t[e].script:(t[e].script=n,this)},params:function(n){return n==null?t[e].params:(t[e].params=n,this)},ignoreFailure:function(n){return n==null?t[e].ignore_failure:(t[e].ignore_failure=n,this)},toString:function(){return JSON.stringify(t)},_type:function(){return"script field"},_self:function(){return t}}},O.Shape=function(e,t){var n={},r=function(e){var t=!1;if(e==="point"||e==="linestring"||e==="polygon"||e==="multipoint"||e==="envelope"||e==="multipolygon")t=!0;return t};return e=e.toLowerCase(),r(e)&&(n.type=e,n.coordinates=t),{type:function(e){return e==null?n.type:(e=e.toLowerCase(),r(e)&&(n.type=e),this)},coordinates:function(e){return e==null?n.coordinates:(n.coordinates=e,this)},toString:function(){return JSON.stringify(n)},_type:function(){return"shape"},_self:function(){return n}}},O.Sort=function(e){e==null&&(e="_score");var t={},n=e,r="_geo_distance",i="_script";return t[n]={},{field:function(r){var i=t[n];return r==null?e:(delete t[n],e=r,n=r,t[n]=i,this)},geoDistance:function(i){var s=t[n];if(i==null)return t[n][e];if(!x(i))throw new TypeError("Argument must be a GeoPoint");return delete t[n],n=r,t[n]=s,t[n][e]=i._self(),this},script:function(e){var r=t[n];return e==null?t[n].script:(delete t[n],n=i,t[n]=r,t[n].script=e,this)},order:function(e){if(e==null)return t[n].order;e=e.toLowerCase();if(e==="asc"||e==="desc")t[n].order=e;return this},asc:function(){return t[n].order="asc",this},desc:function(){return t[n].order="desc",this},reverse:function(e){return e==null?t[n].reverse:(t[n].reverse=e,this)},missing:function(e){return e==null?t[n].missing:(t[n].missing=e,this)},ignoreUnmapped:function(e){return e==null?t[n].ignore_unmapped:(t[n].ignore_unmapped=e,this)},unit:function(e){if(e==null)return t[n].unit;e=e.toLowerCase();if(e==="mi"||e==="km")t[n].unit=e;return this},normalize:function(e){return e==null?t[n].normalize:(t[n].normalize=e,this)},distanceType:function(e){if(e==null)return t[n].distance_type;e=e.toLowerCase();if(e==="arc"||e==="plane")t[n].distance_type=e;return this},params:function(e){return e==null?t[n].params:(t[n].params=e,this)},lang:function(e){return e==null?t[n].lang:(t[n].lang=e,this)},type:function(e){if(e==null)return t[n].type;e=e.toLowerCase();if(e==="string"||e==="number")t[n].type=e;return this},mode:function(e){if(e==null)return t[n].mode;e=e.toLowerCase();if(e==="min"||e==="max"||e==="sum"||e==="avg")t[n].mode=e;return this},nestedPath:function(e){return e==null?t[n].nested_path:(t[n].nested_path=e,this)},nestedFilter:function(e){if(e==null)return t[n].nested_filter;if(!w(e))throw new TypeError("Argument must be a Filter");return t[n].nested_filter=e._self(),this},toString:function(){return JSON.stringify(t)},_type:function(){return"sort"},_self:function(){return t}}},O.DirectGenerator=function(){var e=O.DirectSettingsMixin(),t=e._self();return h(e,{preFilter:function(e){return e==null?t.pre_filter:(t.pre_filter=e,this)},postFilter:function(e){return e==null?t.post_filter:(t.post_filter=e,this)},field:function(e){return e==null?t.field:(t.field=e,this)},size:function(e){return e==null?t.size:(t.size=e,this)},toString:function(){return JSON.stringify(t)},_type:function(){return"generator"},_self:function(){return t}})},O.DirectSettingsMixin=function(){var e={};return{accuracy:function(t){return t==null?e.accuracy:(e.accuracy=t,this)},suggestMode:function(t){if(t==null)return e.suggest_mode;t=t.toLowerCase();if(t==="missing"||t==="popular"||t==="always")e.suggest_mode=t;return this},sort:function(t){if(t==null)return e.sort;t=t.toLowerCase();if(t==="score"||t==="frequency")e.sort=t;return this},stringDistance:function(t){if(t==null)return e.string_distance;t=t.toLowerCase();if(t==="internal"||t==="damerau_levenshtein"||t==="levenstein"||t==="jarowinkler"||t==="ngram")e.string_distance=t;return this},maxEdits:function(t){return t==null?e.max_edits:(e.max_edits=t,this)},maxInspections:function(t){return t==null?e.max_inspections:(e.max_inspections=t,this)},maxTermFreq:function(t){return t==null?e.max_term_freq:(e.max_term_freq=t,this)},prefixLength:function(t){return t==null?e.prefix_length:(e.prefix_length=t,this)},minWordLen:function(t){return t==null?e.min_word_len:(e.min_word_len=t,this)},minDocFreq:function(t){return t==null?e.min_doc_freq:(e.min_doc_freq=t,this)},_self:function(){return e}}},O.PhraseSuggester=function(e){var t={};return t[e]={phrase:{}},{text:function(n){return n==null?t[e].text:(t[e].text=n,this)},analyzer:function(n){return n==null?t[e].phrase.analyzer:(t[e].phrase.analyzer=n,this)},field:function(n){return n==null?t[e].phrase.field:(t[e].phrase.field=n,this)},size:function(n){return n==null?t[e].phrase.size:(t[e].phrase.size=n,this)},shardSize:function(n){return n==null?t[e].phrase.shard_size:(t[e].phrase.shard_size=n,this)},realWorldErrorLikelihood:function(n){return n==null?t[e].phrase.real_world_error_likelihood:(t[e].phrase.real_world_error_likelihood=n,this)},confidence:function(n){return n==null?t[e].phrase.confidence:(t[e].phrase.confidence=n,this)},separator:function(n){return n==null?t[e].phrase.separator:(t[e].phrase.separator=n,this)},maxErrors:function(n){return n==null?t[e].phrase.max_errors:(t[e].phrase.max_errors=n,this)},gramSize:function(n){return n==null?t[e].phrase.gram_size:(t[e].phrase.gram_size=n,this)},forceUnigrams:function(n){return n==null?t[e].phrase.force_unigrams:(t[e].phrase.force_unigrams=n,this)},linearSmoothing:function(n,r,i){return arguments.length===0?t[e].phrase.smoothing:(t[e].phrase.smoothing={linear:{trigram_lambda:n,bigram_lambda:r,unigram_lambda:i}},this)},laplaceSmoothing:function(n){return n==null?t[e].phrase.smoothing:(t[e].phrase.smoothing={laplace:{alpha:n}},this)},stupidBackoffSmoothing:function(n){return n==null?t[e].phrase.smoothing:(t[e].phrase.smoothing={stupid_backoff:{discount:n}},this)},directGenerator:function(n){var r,i;t[e].phrase.direct_generator==null&&(t[e].phrase.direct_generator=[]);if(n==null)return t[e].phrase.direct_generator;if(A(n))t[e].phrase.direct_generator.push(n._self());else{if(!p(n))throw new TypeError("Argument must be a Generator or array of Generators");t[e].phrase.direct_generator=[];for(r=0,i=n.length;r