diff --git a/src/core/sort.js b/src/core/sort.js index 61876ed4..588fd8c2 100644 --- a/src/core/sort.js +++ b/src/core/sort.js @@ -31,19 +31,19 @@ const invalidUnitParam = invalidParam(ES_REF_URL, 'unit', UNIT_SET); * .query(esb.termQuery('user', 'kimchy')) * .sort(esb.sort('post_date', 'asc')) * - * @param {string} field The field to sort on + * @param {string=} field The field to sort on. + * If a script is used to specify the sort order, `field` should be omitted. * @param {string=} order The `order` option can have the following values. * `asc`, `desc` to sort in ascending, descending order respectively. */ class Sort { // eslint-disable-next-line require-jsdoc constructor(field, order) { - this._field = field; - this._opts = {}; this._geoPoint = null; this._script = null; + if (!isNil(field)) this._field = field; if (!isNil(order)) this.order(order); } diff --git a/src/index.d.ts b/src/index.d.ts index a9d60d99..3d451fbe 100644 --- a/src/index.d.ts +++ b/src/index.d.ts @@ -8258,13 +8258,14 @@ declare namespace esb { /** * Allows creating and configuring sort on specified field. * - * @param {string} field The field to sort on + * @param {string=} field The field to sort on. + * If a script is used to specify the sort order, `field` should be omitted. * @param {string=} order The `order` option can have the following values. * `asc`, `desc` to sort in ascending, descending order respectively. */ export class Sort { - constructor(field: string, order?: string); - + constructor(field?: string, order?: string); + /** * Set order for sorting. The order defaults to `desc` when sorting on the `_score`, * and defaults to `asc` when sorting on anything else. @@ -8417,11 +8418,12 @@ declare namespace esb { /** * Allows creating and configuring sort on specified field. * - * @param {string} field The field to sort on + * @param {string=} field The field to sort on. + * If a script is used to specify the sort order, `field` should be omitted. * @param {string=} order The `order` option can have the following values. * `asc`, `desc` to sort in ascending, descending order respectively. */ - export function sort(field: string, order?: string): Sort; + export function sort(field?: string, order?: string): Sort; /** * A `rescore` request can help to improve precision by reordering just