diff --git a/src/core/script.js b/src/core/script.js index 7ad583ce..0dfa9364 100644 --- a/src/core/script.js +++ b/src/core/script.js @@ -7,7 +7,12 @@ const isNil = require('lodash.isnil'); * * [Elasticsearch reference](https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-scripting-using.html) * - * @param {string=} type One of `inline`, `stored`, `file` + * Note: `inline` script type was deprecated in [elasticsearch v5.0](https://www.elastic.co/guide/en/elasticsearch/reference/5.6/breaking_50_scripting.html). + * `source` should be used instead. And similarly for `stored` scripts, type + * `id` must be used instead. `file` scripts were removed as part of the + * breaking changes in [elasticsearch v6.0](https://www.elastic.co/guide/en/elasticsearch/reference/6.0/breaking_60_scripting_changes.html#_file_scripts_removed) + * + * @param {string=} type One of `inline`, `stored`, `file`, `source`, `id`. * @param {string=} source Source of the script. * This needs to be specified if optional argument `type` is passed. * @@ -39,10 +44,18 @@ class Script { this.inline(source); break; + case 'source': + this.source(source); + break; + case 'stored': this.stored(source); break; + case 'id': + this.id(source); + break; + case 'file': this.file(source); break; @@ -71,21 +84,26 @@ class Script { * @private */ _checkMixedRepr() { - if (this._isTypeSet) { - this._warn( - 'Script source(`inline`/`stored`/`file`) was already specified!' - ); - this._warn('Overwriting.'); - - delete this._body.file; - delete this._body.stored; - delete this._body.file; - } + if (!this._isTypeSet) return; + + this._warn( + 'Script source(`inline`/`source`/`stored`/`id`/`file`) was already specified!' + ); + this._warn('Overwriting.'); + + delete this._body.inline; + delete this._body.source; + delete this._body.stored; + delete this._body.id; + delete this._body.file; } /** * Sets the type of script to be `inline` and specifies the source of the script. * + * Note: This type was deprecated in elasticsearch v5.0. Use `source` + * instead if you are using elasticsearch `>= 5.0`. + * * @param {string} scriptCode * @returns {Script} returns `this` so that calls can be chained. */ @@ -97,9 +115,30 @@ class Script { return this; } + /** + * Sets the type of script to be `source` and specifies the source of the script. + * + * Note: `source` is an alias for the `inline` type which was deprecated + * in elasticsearch v5.0. So this type is supported only in versions + * `>= 5.0`. + * + * @param {string} scriptCode + * @returns {Script} returns `this` so that calls can be chained. + */ + source(scriptCode) { + this._checkMixedRepr(); + + this._body.source = scriptCode; + this._isTypeSet = true; + return this; + } + /** * Specify the `stored` script by `id` which will be retrieved from cluster state. * + * Note: This type was deprecated in elasticsearch v5.0. Use `id` + * instead if you are using elasticsearch `>= 5.0`. + * * @param {string} scriptId The unique identifier for the stored script. * @returns {Script} returns `this` so that calls can be chained. */ @@ -111,6 +150,24 @@ class Script { return this; } + /** + * Specify the stored script to be used by it's `id` which will be retrieved + * from cluster state. + * + * Note: `id` is an alias for the `stored` type which was deprecated in + * elasticsearch v5.0. So this type is supported only in versions `>= 5.0`. + * + * @param {string} scriptId The unique identifier for the stored script. + * @returns {Script} returns `this` so that calls can be chained. + */ + id(scriptId) { + this._checkMixedRepr(); + + this._body.id = scriptId; + this._isTypeSet = true; + return this; + } + /** * Specify the `file` script by stored as a file in the scripts folder. * diff --git a/src/index.d.ts b/src/index.d.ts index 8098bba2..86dbf999 100644 --- a/src/index.d.ts +++ b/src/index.d.ts @@ -4724,7 +4724,11 @@ declare namespace esb { * @extends ValuesSourceBase */ export class DateHistogramValuesSource extends ValuesSourceBase { - constructor(name: string, field?: string, interval?: string | number); + constructor( + name: string, + field?: string, + interval?: string | number + ); /** * Sets the histogram interval. Buckets are generated based on this interval value. @@ -4752,12 +4756,11 @@ declare namespace esb { * in the field mapping. * * @param {string} fmt Format mask to apply on aggregation response. - * For Date Histograms, supports expressive [date format pattern](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-daterange-aggregation.html#date-format-pattern) + * For Date Histograms, supports expressive [date format pattern](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-daterange-aggregation.html#date-format-pattern) */ format(fmt: string): this; } - /** * `DateHistogramValuesSource` is a source for the `CompositeAggregation` that * handles date histograms. It works very similar to a histogram aggregation @@ -6560,9 +6563,7 @@ declare namespace esb { * * @param {string} name The name which will be used to refer to this aggregation. */ - export function bucketSortAggregation( - name: string - ): BucketSortAggregation; + export function bucketSortAggregation(name: string): BucketSortAggregation; /** * Serial differencing is a technique where values in a time series are @@ -7934,7 +7935,12 @@ declare namespace esb { /** * Class supporting the Elasticsearch scripting API. * - * @param {string=} type One of `inline`, `stored`, `file` + * Note: `inline` script type was deprecated in [elasticsearch v5.0](https://www.elastic.co/guide/en/elasticsearch/reference/5.6/breaking_50_scripting.html). + * `source` should be used instead. And similarly for `stored` scripts, type + * `id` must be used instead. `file` scripts were removed as part of the + * breaking changes in [elasticsearch v6.0](https://www.elastic.co/guide/en/elasticsearch/reference/6.0/breaking_60_scripting_changes.html#_file_scripts_removed) + * + * @param {string=} type One of `inline`, `stored`, `file`, `source`, `id`. * @param {string=} source Source of the script. * This needs to be specified if optional argument `type` is passed. */ @@ -7944,17 +7950,45 @@ declare namespace esb { /** * Sets the type of script to be `inline` and specifies the source of the script. * + * Note: This type was deprecated in elasticsearch v5.0. Use `source` + * instead if you are using elasticsearch `>= 5.0`. + * * @param {string} scriptCode */ inline(scriptCode: string): this; + /** + * Sets the type of script to be `source` and specifies the source of the script. + * + * Note: `source` is an alias for the `inline` type which was deprecated + * in elasticsearch v5.0. So this type is supported only in versions + * `>= 5.0`. + * + * @param {string} scriptCode + */ + source(scriptCode): this; + /** * Specify the `stored` script by `id` which will be retrieved from cluster state. * + * Note: This type was deprecated in elasticsearch v5.0. Use `id` + * instead if you are using elasticsearch `>= 5.0`. + * * @param {string} scriptId The unique identifier for the stored script. */ stored(scriptId: string): this; + /** + * Specify the stored script to be used by it's `id` which will be retrieved + * from cluster state. + * + * Note: `id` is an alias for the `stored` type which was deprecated in + * elasticsearch v5.0. So this type is supported only in versions `>= 5.0`. + * + * @param {string} scriptId The unique identifier for the stored script. + */ + id(scriptId): this; + /** * Specify the `stored` script by `id` which will be retrieved from cluster state. *