elastic-builder
Version:
A JavaScript implementation of the elasticsearch Query DSL
1,234 lines (1,119 loc) • 365 kB
TypeScript
// Type definitions for elastic-builder
// Project: https://elastic-builder.js.org
// Definitions by: Suhas Karanth <sudo.suhas@gmail.com>
export = esb;
declare namespace esb {
/**
* The `RequestBodySearch` object provides methods generating an elasticsearch
* search request body. The search request can be executed with a search DSL,
* which includes the Query DSL, within its body.
*/
export class RequestBodySearch {
/**
* Define query on the search request body using the Query DSL.
*
* @param {Query} query
*/
query(query: Query): this;
/**
* Sets aggregation on the request body.
* Alias for method `aggregation`
*
* @param {Aggregation} agg Any valid `Aggregation`
* @throws {TypeError} If `agg` is not an instance of `Aggregation`
*/
agg(agg: Aggregation): this;
/**
* Sets aggregation on the request body.
*
* @param {Aggregation} agg Any valid `Aggregation`
* @throws {TypeError} If `agg` is not an instance of `Aggregation`
*/
aggregation(agg: Aggregation): this;
/**
* Sets multiple aggregation items on the request body.
* Alias for method `aggregations`
*
* @param {Array<Aggregation>} aggs Array of valid `Aggregation` items
* @throws {TypeError} If `aggs` is not an instance of `Array`
* @throws {TypeError} If `aggs` contains instances not of type `Aggregation`
*/
aggs(aggs: Aggregation[]): this;
/**
* Sets multiple aggregation items on the request body.
*
* @param {Array<Aggregation>} aggs Array of valid `Aggregation` items
* @throws {TypeError} If `aggs` is not an instance of `Array`
* @throws {TypeError} If `aggs` contains instances not of type `Aggregation`
*/
aggregations(aggs: Aggregation[]): this;
/**
* Sets suggester on the request body.
*
* @param {Suggester} suggest Any valid `Suggester`
* @throws {TypeError} If `suggest` is not an instance of `Suggester`
*/
suggest(suggest: Suggester): this;
/**
* Sets the global suggest text to avoid repetition for multiple suggestions.
*
* @param {string} txt Global suggest text
*/
suggestText(txt: string): this;
/**
* Sets 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.
*
* @param {string} timeout Duration can be specified using time units.
* Defaults to no timeout.
*/
timeout(timeout: string): this;
/**
* To retrieve hits from a certain offset.
*
* @param {number} from Defaults to 0.
*/
from(from: number): this;
/**
* The number of hits to return. If you do not care about getting some hits back
* but only about the number of matches and/or aggregations, setting the value
* to 0 will help performance.
*
* @param {number} size Defaults to 10.
*/
size(size: number): this;
/**
* The maximum number of documents to collect for each shard, upon reaching which
* the query execution will terminate early. If set, the response will have a
* boolean field `terminated_early` to indicate whether the query execution has
* actually terminated early.
*
* @param {number} numberOfDocs Maximum number of documents to collect for each shard.
* Defaults to no limit.
*/
terminateAfter(numberOfDocs: number): this;
/**
* Allows to add sort on specific field. The sort can be reversed as well.
* The sort is defined on a per field level, with special field name for `_score` to
* sort by score, and `_doc` to sort by index order.
*
* @param {Sort} sort
* @throws {TypeError} If parameter `sort` is not an instance of `Sort`.
*/
sort(sort: Sort): this;
/**
* Allows to add multiple sort on specific fields. Each sort can be reversed as well.
* The sort is defined on a per field level, with special field name for _score to
* sort by score, and _doc to sort by index order.
*
* @param {Array<Sort>} sorts Arry of sort
* @throws {TypeError} If any item in parameter `sorts` is not an instance of `Sort`.
*/
sorts(sorts: Sort[]): this;
/**
* When sorting on a field, scores are not computed. By setting `track_scores` to true,
* scores will still be computed and tracked.
*
* @param {boolean} enable
*/
trackScores(enable: boolean): this;
/**
* The `track_total_hits` parameter allows you to control how the total number of hits
* should be tracked. Passing `false` can increase performance in some situations.
* (Added in elasticsearch@7)
*
* Pass true, false, or the upper limit of hits you want tracked.
*
* @param {boolean|number} enable
*/
trackTotalHits(enable: boolean | number): this;
/**
* Allows to control how the `_source` field is returned with every hit.
* You can turn off `_source` retrieval by passing `false`.
* It also accepts one(string) or more wildcard(array) patterns to control
* what parts of the `_source` should be returned
* An object can also be used to specify the wildcard patterns for `includes` and `excludes`.
*
* @param {boolean|string|Array|Object} source
*/
source(source: boolean | string | string[] | object): this;
/**
* The `stored_fields` parameter is about fields that are explicitly marked as stored in the mapping.
* Selectively load specific stored fields for each document represented by a search hit
* using array of stored fields.
* An empty array will cause only the `_id` and `_type` for each hit to be returned.
* To disable the stored fields (and metadata fields) entirely use: `_none_`
*
* @param {Array|string} fields
*/
storedFields(fields: object | string): this;
/**
* Computes a document property dynamically based on the supplied `Script`.
*
* @param {string} scriptFieldName
* @param {string|Script} script string or instance of `Script`
*/
scriptField(scriptFieldName: string, script: string | Script): this;
/**
* Sets given dynamic document properties to be computed using supplied `Script`s.
* Object should have `scriptFieldName` as key and `script` as the value.
*
* @param {object} scriptFields Object with `scriptFieldName` as key and `script` as the value.
*/
scriptFields(scriptFields: object): this;
/**
* Allows to return the doc value representation of a field for each hit.
* Doc value fields can work on fields that are not stored.
*
* @param {Array<string>} fields
*/
docvalueFields(fields: string[]): this;
/**
* The `post_filter` is applied to the search hits at the very end of a search request,
* after aggregations have already been calculated.
*
* @param {Query} filterQuery The filter to be applied after aggregation.
*/
postFilter(filterQuery: Query): this;
/**
* Allows to highlight search results on one or more fields. The implementation
* uses either the lucene `plain` highlighter, the fast vector highlighter (`fvh`)
* or `postings` highlighter.
*
* Note: The `postings` highlighter has been removed in elasticsearch 6.0. The `unified`
* highlighter outputs the same highlighting when `index_options` is set to `offsets`.
*
* @param {Highlight} highlight
*/
highlight(highlight: Highlight): this;
/**
* Rescoring can help to improve precision by reordering just the top (eg 100 - 500)
* documents returned by the `query` and `post_filter` phases, using a secondary
* (usually more costly) algorithm, instead of applying the costly algorithm to
* all documents in the index.
*
* @param {Rescore} rescore
* @throws {TypeError} If `query` is not an instance of `Rescore`
*/
rescore(rescore: Rescore): this;
/**
* Enables explanation for each hit on how its score was computed.
*
* @param {boolean} enable
*/
explain(enable: boolean): this;
/**
* Returns a version for each search hit.
*
* @param {boolean} enable
*/
version(enable: boolean): this;
/**
* Allows to configure different boost level per index when searching across
* more than one indices. This is very handy when hits coming from one index
* matter more than hits coming from another index.
* Alias for method `indicesBoost`.
*
* @param {string} index Index windcard expression or alias
* @param {number} boost
*/
indexBoost(index: string, boost: number): this;
/**
* Allows to configure different boost level per index when searching across
* more than one indices. This is very handy when hits coming from one index
* matter more than hits coming from another index.
*
* @param {string} index Index windcard expression or alias
* @param {number} boost
*/
indicesBoost(index: string, boost: number): this;
/**
* Exclude documents which have a `_score` less than the minimum specified in `min_score`.
*
* @param {number} score
*/
minScore(score: number): this;
/**
* Allows to collapse search results based on field values. The collapsing
* is done by selecting only the top sorted document per collapse key.
* The field used for collapsing must be a single valued `keyword` or `numeric`
* field with `doc_values` activated
*
* @param {string} field
* @param {InnerHits=} innerHits Allows to expand each collapsed top hits.
* @param {number=} maxConcurrentGroupRequests The number of concurrent
* requests allowed to retrieve the inner_hits' per group
* @throws {TypeError} If `innerHits` is not an instance of `InnerHits`
*/
collapse(
field: string,
innerHits?: InnerHits,
maxConcurrentGroupRequests?: number
): this;
/**
* Allows to use the results from the previous page to help the retrieval
* of the next page. The `search_after` parameter provides a live cursor.
* The parameter `from` must be set to `0` (or `-1`) when `search_after` is used.
*
* @param {Array<*>} values The `sort values` of the last document to retrieve
* the next page of results
*/
searchAfter(values: any[]): this;
/**
* Override default `toJSON` to return DSL representation for the request body search
*
* @override
*/
toJSON(): object;
}
/**
* The `RequestBodySearch` object provides methods generating an elasticsearch
* search request body. The search request can be executed with a search DSL,
* which includes the Query DSL, within its body.
*/
export function requestBodySearch(): RequestBodySearch;
/**
* Base class implementation for all query types.
*
* **NOTE:** Instantiating this directly should not be required.
* However, if you wish to add a custom implementation for whatever reason,
* this class should be extended and used, as validation against the class
* type is present in various places.
*
* @param {string} queryType
*/
class Query {
constructor(queryType: string);
/**
* Sets the boost value for documents matching the `Query`.
*
* @param {number} factor
*/
boost(factor: number): this;
/**
* Sets the query name.
*
* @param {string} name
*/
name(name: string): this;
/**
* Build and returns DSL representation of the `Query` class instance.
*
*/
getDSL(): object;
/**
* Override default `toJSON` to return DSL representation for the `query`
*
* @override
*/
toJSON(): object;
}
/**
* The most simple query, which matches all documents, giving them all a `_score` of `1.0`.
*
* @extends Query
*/
export class MatchAllQuery extends Query {
constructor();
}
/**
* The most simple query, which matches all documents, giving them all a `_score` of `1.0`.
*/
export function matchAllQuery(): MatchAllQuery;
/**
* The inverse of the `match_all` query, which matches no documents.
*
* @extends Query
*/
export class MatchNoneQuery extends Query {
constructor();
}
/**
* The inverse of the `match_all` query, which matches no documents.
*/
export function matchNoneQuery(): MatchNoneQuery;
/**
* The `FullTextQueryBase` provides support for common options used across
* various full text query implementations.
*
* **NOTE:** Instantiating this directly should not be required.
* However, if you wish to add a custom implementation for whatever reason,
* this class could be extended.
*
* @param {string} queryType
* @param {string=} queryString The query string
* @extends Query
*/
class FullTextQueryBase extends Query {
constructor(queryType: string, queryString?: string);
/**
* Set the analyzer to control which analyzer will perform the analysis process on the text
*
* @param {string} analyzer
*/
analyzer(analyzer: string): this;
/**
* Sets the value controlling how many "should" clauses in the resulting boolean
* query should match. It can be an absolute value (2), a percentage (30%)
* or a combination of both. For Common Terms Query when specifying different
* `minimum_should_match` for low and high frequency terms, an object with the
* keys `low_freq` and `high_freq` can be used.
*
* @param {string|number|Object} minimumShouldMatch
* Note: Object notation can only be used with Common Terms Query.
*/
minimumShouldMatch(minimumShouldMatch: string | number | object): this;
/**
* Sets the query string.
*
* @param {string} queryString
*/
query(queryString: string): this;
}
/**
* The `MonoFieldQueryBase` provides support for common options used across
* various full text query implementations with single search field.
*
* **NOTE:** Instantiating this directly should not be required.
* However, if you wish to add a custom implementation for whatever reason,
* this class could be extended.
*
* @param {string} queryType
* @param {string=} field The document field to query against
* @param {string=} queryString The query string
* @extends FullTextQueryBase
*/
class MonoFieldQueryBase extends FullTextQueryBase {
constructor(queryType: string, field?: string, queryString?: string);
/**
* Sets the field to search on.
*
* @param {string} field
*/
field(field: string): this;
/**
* Override default `toJSON` to return DSL representation of the Full text query
* class instance.
*
* @override
*/
toJSON(): object;
}
/**
* `match` query accepts text/numerics/dates, analyzes them, and constructs a query.
*
* @param {string=} field The document field to query against
* @param {string=} queryString The query string
* @extends MonoFieldQueryBase
*/
export class MatchQuery extends MonoFieldQueryBase {
constructor(field?: string, queryString?: string);
/**
* The operator to be used in the boolean query which is constructed
* by analyzing the text provided. The `operator` flag can be set to `or` or
* `and` to control the boolean clauses (defaults to `or`).
*
* @param {string} operator Can be `and`/`or`. Default is `or`.
*/
operator(operator: 'and' | 'or'): this;
/**
* Sets the `lenient` parameter which allows to ignore exceptions caused
* by data-type mismatches such as trying to query a numeric field with a
* text query string when set to `true`.
*
* @param {boolean} enable Defaules to `false`
*/
lenient(enable: boolean): this;
/**
* Sets the `fuzziness` parameter which is interpreted as a Levenshtein Edit Distance —
* the number of one character changes that need to be made to one string to make it
* the same as another string.
*
* @param {number|string} factor Can be specified either as a number, or the maximum
* number of edits, or as `AUTO` which generates an edit distance based on the length
* of the term.
*/
fuzziness(factor: number | string): this;
/**
* Sets the prefix length for a fuzzy prefix `MatchQuery`
*
* @param {number} len
*/
prefixLength(len: number): this;
/**
* Sets the max expansions for a fuzzy prefix `MatchQuery`
*
* @param {number} limit
*/
maxExpansions(limit: number): this;
/**
* Sets the rewrite method. Valid values are:
* - `constant_score` - tries to pick the best constant-score rewrite
* method based on term and document counts from the query.
* Synonyms - `constant_score_auto`, `constant_score_filter`
* - `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_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_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`.
* This is an advanced option, use with care.
*
* Note: The deprecated multi term rewrite parameters `constant_score_auto`,
* `constant_score_filter` (synonyms for `constant_score`) have been removed in
* elasticsearch 6.0.
*
* @param {string} method The rewrite method as a string.
* @throws {Error} If the given `rewrite` method is not valid.
*/
rewrite(method: string): this;
/**
* Sets the fuzzy rewrite method. Valid values are:
* - `constant_score` - tries to pick the best constant-score rewrite
* method based on term and document counts from the query.
* Synonyms - `constant_score_auto`, `constant_score_filter`
* - `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_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_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`.
* This is an advanced option, use with care.
*
* Note: The deprecated multi term rewrite parameters `constant_score_auto`,
* `constant_score_filter` (synonyms for `constant_score`) have been removed in
* elasticsearch 6.0.
*
* @param {string} method The rewrite method as a string.
* @throws {Error} If the given `fuzzy_rewrite` method is not valid.
*/
fuzzyRewrite(method: string): this;
/**
* Fuzzy transpositions (`ab` → `ba`) are allowed by default but can be disabled
* by setting `fuzzy_transpositions` to false.
*
* @param {boolean} enable
*/
fuzzyTranspositions(enable: boolean): this;
/**
* If the analyzer used removes all tokens in a query like a `stop` filter does,
* the default behavior is to match no documents at all. In order to change that
* the `zero_terms_query` option can be used, which accepts `none` (default) and `all`
* which corresponds to a `match_all` query.
*
* @param {string} behavior A no match action, `all` or `none`. Default is `none`.
*/
zeroTermsQuery(behavior: 'all' | 'none'): this;
/**
* Allows specifying an absolute or relative document frequency where high frequency
* terms are moved into an optional subquery and are only scored if one of the
* low frequency (below the cutoff) terms in the case of an `or` operator or
* all of the low frequency terms in the case of an `and` operator match.
*
* @param {number} frequency It can either be relative to the total number of documents
* if in the range `[0..1)` or absolute if greater or equal to `1.0`.
*/
cutoffFrequency(frequency: number): this;
}
/**
* `match` query accepts text/numerics/dates, analyzes them, and constructs a query.
*
* @param {string=} field The document field to query against
* @param {string=} queryString The query string
*/
export function matchQuery(
field?: string,
queryString?: string
): MatchQuery;
/**
* The `MatchPhraseQueryBase` provides support for common options used across
* various bucket match phrase query implementations.
*
* **NOTE:** Instantiating this directly should not be required.
* However, if you wish to add a custom implementation for whatever reason,
* this class could be extended.
*
* @param {string} queryType
* @param {string} refUrl
* @param {string=} field The document field to query against
* @param {string=} queryString The query string
* @extends MonoFieldQueryBase
*/
class MatchPhraseQueryBase extends MonoFieldQueryBase {
constructor(
queryType: string,
refUrl: string,
field?: string,
queryString?: string
);
/**
* @override
* @throws {Error} This method cannot be called on `MatchPhraseQueryBase`
*/
minimumShouldMatch(): never;
/**
* Configures the `slop`(default is 0) for matching terms in any order.
* Transposed terms have a slop of 2.
* @param {number} slop A positive integer value, defaults is 0.
*/
slop(slop: number): this;
}
/**
* The `match_phrase` query analyzes the text and creates a `phrase` query out of
* the analyzed text.
*
* @param {string=} field The document field to query against
* @param {string=} queryString The query string
* @extends MatchPhraseQueryBase
*/
export class MatchPhraseQuery extends MatchPhraseQueryBase {
constructor(field?: string, queryString?: string);
}
/**
* The `match_phrase` query analyzes the text and creates a `phrase` query out of
* the analyzed text.
*
* @param {string=} field The document field to query against
* @param {string=} queryString The query string
*/
export function matchPhraseQuery(
field?: string,
queryString?: string
): MatchPhraseQuery;
/**
* @param {string=} field The document field to query against
* @param {string=} queryString The query string
* @extends MatchPhraseQueryBase
*/
export class MatchPhrasePrefixQuery extends MatchPhraseQueryBase {
constructor(field?: string, queryString?: string);
/**
* Control to how many prefixes the last term will be expanded.
*
* @param {number} limit Defaults to 50.
*/
maxExpansions(limit: number): this;
}
/**
* @param {string=} field The document field to query against
* @param {string=} queryString The query string
*/
export function matchPhrasePrefixQuery(
field?: string,
queryString?: string
): MatchPhrasePrefixQuery;
/**
* A `MultiMatchQuery` query builds further on top of the
* `MultiMatchQuery` by allowing multiple fields to be specified.
* The idea here is to allow to more easily build a concise match type query
* over multiple fields instead of using a relatively more expressive query
* by using multiple match queries within a bool query.
*
* @param {Array<string>|string=} fields The fields to be queried
* @param {string=} queryString The query string
* @extends FullTextQueryBase
*/
export class MultiMatchQuery extends FullTextQueryBase {
constructor(fields?: string[] | string, queryString?: string);
/**
* Appends given field to the list of fields to search against.
* Fields can be specified with wildcards.
* Individual fields can be boosted with the caret (^) notation.
* Example - `"subject^3"`
*
* @param {string} field One of the fields to be queried
*/
field(field: string): this;
/**
* Appends given fields to the list of fields to search against.
* Fields can be specified with wildcards.
* Individual fields can be boosted with the caret (^) notation.
*
* @param {Array<string>} fields The fields to be queried
*/
fields(fields: string[]): this;
/**
* Sets the type of multi match query. Valid values are:
* - `best_fields` - (default) Finds documents which match any field,
* but uses the `_score` from the best field.
* - `most_fields` - Finds documents which match any field and combines
* the `_score` from each field.
* - `cross_fields` - Treats fields with the same `analyzer` as though
* they were one big field. Looks for each word in *any* field
* - `phrase` - Runs a `match_phrase` query on each field and combines
* the `_score` from each field.
* - `phrase_prefix` - Runs a `match_phrase_prefix` query on each field
* and combines the `_score` from each field.
* - `bool_prefix` - (added in v7.2) Creates a match_bool_prefix query on each field and
* combines the _score from each field.
*
* @param {string} type Can be one of `best_fields`, `most_fields`,
* `cross_fields`, `phrase`, `phrase_prefix` and `bool_prefix`. Default is `best_fields`.
*/
type(
type:
| 'best_fields'
| 'most_fields'
| 'cross_fields'
| 'phrase'
| 'phrase_prefix'
| 'bool_prefix'
): this;
/**
* 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`.
*
* @param {number} factor
*/
tieBreaker(factor: number): this;
/**
* The operator to be used in the boolean query which is constructed
* by analyzing the text provided. The `operator` flag can be set to `or` or
* `and` to control the boolean clauses (defaults to `or`).
*
* @param {string} operator Can be `and`/`or`. Default is `or`.
*/
operator(operator: 'and' | 'or'): this;
/**
* Sets the `lenient` parameter which allows to ignore exceptions caused
* by data-type mismatches such as trying to query a numeric field with a
* text query string when set to `true`.
*
* @param {boolean} enable Defaules to `false`
*/
lenient(enable: boolean): this;
/**
* Configures the `slop`(default is 0) for matching terms in any order.
* Transposed terms have a slop of 2.
*
* @param {number} slop A positive integer value, defaults is 0.
*/
slop(slop: number): this;
/**
* Sets the `fuzziness` parameter which is interpreted as a Levenshtein Edit Distance —
* the number of one character changes that need to be made to one string to make it
* the same as another string.
* The `fuzziness` parameter cannot be used with the `phrase`, `phrase_prefix`
* or `cross_fields` type.
*
* @param {number|string} factor Can be specified either as a number, or the maximum
* number of edits, or as `AUTO` which generates an edit distance based on the length
* of the term.
*/
fuzziness(factor: number | string): this;
/**
* Sets the prefix length for a fuzzy prefix `MultiMatchQuery`
*
* @param {number} len
*/
prefixLength(len: number): this;
/**
* Sets the max expansions for a fuzzy prefix `MultiMatchQuery`
*
* @param {number} limit
*/
maxExpansions(limit: number): this;
/**
* Sets the rewrite method. Valid values are:
* - `constant_score` - tries to pick the best constant-score rewrite
* method based on term and document counts from the query.
* Synonyms - `constant_score_auto`, `constant_score_filter`
* - `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_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_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`.
* This is an advanced option, use with care.
*
* Note: The deprecated multi term rewrite parameters `constant_score_auto`,
* `constant_score_filter` (synonyms for `constant_score`) have been removed in
* elasticsearch 6.0.
*
* @param {string} method The rewrite method as a string.
* @throws {Error} If the given `rewrite` method is not valid.
*/
rewrite(method: string): this;
/**
* Sets the fuzzy rewrite method. Valid values are:
* - `constant_score` - tries to pick the best constant-score rewrite
* method based on term and document counts from the query.
* Synonyms - `constant_score_auto`, `constant_score_filter`
* - `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_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_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`.
* This is an advanced option, use with care.
*
* Note: The deprecated multi term rewrite parameters `constant_score_auto`,
* `constant_score_filter` (synonyms for `constant_score`) have been removed in
* elasticsearch 6.0.
*
* @param {string} method The rewrite method as a string.
* @throws {Error} If the given `fuzzy_rewrite` method is not valid.
*/
fuzzyRewrite(method: string): this;
/**
* If the analyzer used removes all tokens in a query like a `stop` filter does,
* the default behavior is to match no documents at all. In order to change that
* the `zero_terms_query` option can be used, which accepts `none` (default) and `all`
* which corresponds to a `match_all` query.
*
* @param {string} behavior A no match action, `all` or `none`. Default is `none`.
*/
zeroTermsQuery(behavior: 'all' | 'none'): this;
/**
* Allows specifying an absolute or relative document frequency where high frequency
* terms are moved into an optional subquery and are only scored if one of the
* low frequency (below the cutoff) terms in the case of an `or` operator or
* all of the low frequency terms in the case of an `and` operator match.
*
* @param {number} frequency It can either be relative to the total number of documents
* if in the range `[0..1)` or absolute if greater or equal to `1.0`.
*/
cutoffFrequency(frequency: number): this;
}
/**
* A `MultiMatchQuery` query builds further on top of the
* `MultiMatchQuery` by allowing multiple fields to be specified.
* The idea here is to allow to more easily build a concise match type query
* over multiple fields instead of using a relatively more expressive query
* by using multiple match queries within a bool query.
*
* @param {Array<string>|string=} fields The fields to be queried
* @param {string=} queryString The query string
*/
export function multiMatchQuery(
fields?: string[] | string,
queryString?: string
): MultiMatchQuery;
/**
* The `common` terms query is a modern alternative to stopwords which
* improves the precision and recall of search results (by taking
* stopwords into account), without sacrificing performance.
*
* @param {string=} field The document field to query against
* @param {string=} queryString The query string
* @extends MonoFieldQueryBase
*/
export class CommonTermsQuery extends MonoFieldQueryBase {
constructor(field?: string, queryString?: string);
/**
* Allows specifying an absolute or relative document frequency where high frequency
* terms are moved into an optional subquery and are only scored if one of the
* low frequency (below the cutoff) terms in the case of an `or` operator or
* all of the low frequency terms in the case of an `and` operator match.
*
* @param {number} frequency It can either be relative to the total number of documents
* if in the range `[0..1)` or absolute if greater or equal to `1.0`.
*/
cutoffFrequency(frequency: number): this;
/**
* The operator to be used on low frequency terms in the boolean query
* which is constructed by analyzing the text provided. The `operator` flag
* can be set to `or` or `and` to control the boolean clauses (defaults to `or`).
*
* @param {string} operator Can be `and`/`or`. Default is `or`.
*/
lowFreqOperator(operator: 'and' | 'or'): this;
/**
* The operator to be used on high frequency terms in the boolean query
* which is constructed by analyzing the text provided. The `operator` flag
* can be set to `or` or `and` to control the boolean clauses (defaults to `or`).
*
* @param {string} operator Can be `and`/`or`. Default is `or`.
*/
highFreqOperator(operator: 'and' | 'or'): this;
/**
* Sets the value controlling how many "should" clauses in the resulting boolean
* query should match for low frequency terms. It can be an absolute value (2),
* a percentage (30%) or a combination of both.
*
* @param {string|number} lowFreqMinMatch
*/
lowFreq(lowFreqMinMatch: string | number): this;
/**
* Sets the value controlling how many "should" clauses in the resulting boolean
* query should match for high frequency terms. It can be an absolute value (2),
* a percentage (30%) or a combination of both.
*
* @param {string|number} highFreqMinMatch
*/
highFreq(highFreqMinMatch: string | number): this;
/**
* Enables or disables similarity coordinate scoring of documents
* commoning the `CommonTermsQuery`. Default: `false`.
*
* NOTE: This has been removed in elasticsearch 6.0. If provided,
* it will be ignored and a deprecation warning will be issued.
*
* @param {boolean} enable
*/
disableCoord(enable: boolean): this;
}
/**
* The `common` terms query is a modern alternative to stopwords which
* improves the precision and recall of search results (by taking
* stopwords into account), without sacrificing performance.
*
* @param {string=} field The document field to query against
* @param {string=} queryString The query string
*/
export function commonTermsQuery(
field?: string,
queryString?: string
): CommonTermsQuery;
/**
* The `QueryStringQueryBase` provides support for common options used across
* full text query implementations `QueryStringQuery` and `SimpleQueryStringQuery`.
* A query that uses a query parser in order to parse its content.
*
* **NOTE:** Instantiating this directly should not be required.
* However, if you wish to add a custom implementation for whatever reason,
* this class could be extended.
*
* @param {string} queryType
* @param {string} refUrl
* @param {string=} queryString The actual query to be parsed.
* @extends FullTextQueryBase
*/
class QueryStringQueryBase extends FullTextQueryBase {
constructor(queryType: string, refUrl: string, queryString?: string);
/**
* Appends given field to the list of fields to search against.
* Fields can be specified with wildcards.
* Individual fields can be boosted with the caret (^) notation.
* Example - `"subject^3"`
*
* @param {string} field One of the fields to be queried
*/
field(field: string): this;
/**
* Appends given fields to the list of fields to search against.
* Fields can be specified with wildcards.
* Individual fields can be boosted with the caret (^) notation.
* Example - `[ "subject^3", "message" ]`
*
* @param {Array<string>} fields The fields to be queried
*/
fields(fields: string[]): this;
/**
* The default operator used if no explicit operator is specified.
* For example, with a default operator of `OR`, the query `capital of Hungary`
* is translated to `capital OR of OR Hungary`, and with default operator of AND,
* the same query is translated to `capital AND of AND Hungary`.
* The default value is OR.
*
* @param {string} operator Can be `AND`/`OR`. Default is `OR`.
*/
defaultOperator(operator: 'AND' | 'OR'): this;
/**
* By default, wildcards terms in a query string are not analyzed.
* By setting this value to `true`, a best effort will be made to analyze those as well.
*
* @param {boolean} enable
*/
analyzeWildcard(enable: boolean): this;
/**
* Sets the `lenient` parameter which allows to ignore exceptions caused
* by data-type mismatches such as trying to query a numeric field with a
* text query string when set to `true`.
*
* @param {boolean} enable Defaules to `false`
*/
lenient(enable: boolean): this;
/**
* A suffix to append to fields for quoted parts of the query string.
* This allows to use a field that has a different analysis chain for exact matching.
*
* @param {string} suffix
*/
quoteFieldSuffix(suffix: string): this;
/**
* Perform the query on all fields detected in the mapping that can be queried.
* Will be used by default when the `_all` field is disabled and
* no `default_field` is specified (either in the index settings or
* in the request body) and no `fields` are specified.
*
* @param {boolean} enable
*/
allFields(enable: boolean): this;
}
/**
* A query that uses a query parser in order to parse its content.
*
* @param {string=} queryString The actual query to be parsed.
* @extends QueryStringQueryBase
*/
export class QueryStringQuery extends QueryStringQueryBase {
constructor(queryString?: string);
/**
* The default field for query terms if no prefix field is specified.
* Defaults to the `index.query.default_field` index settings, which
* in turn defaults to `_all`.
*
* @param {string} field
*/
defaultField(field: string): this;
/**
* When set, `*` or `?` are allowed as the first character. Defaults to `true`.
*
* @param {boolean} enable
*/
allowLeadingWildcard(enable: boolean): this;
/**
* Set to true to enable position increments in result queries. Defaults to true.
*
* @param {boolean} enable
*/
enablePositionIncrements(enable: boolean): this;
/**
* Controls the number of terms fuzzy queries will expand to. Defaults to `50`.
*
* @param {number} limit
*/
fuzzyMaxExpansions(limit: number): this;
/**
* Sets the `fuzziness` parameter which is interpreted as a Levenshtein Edit Distance —
* the number of one character changes that need to be made to one string to make it
* the same as another string. Defaults to `AUTO`.
*
* @param {number|string} factor Can be specified either as a number, or the maximum
* number of edits, or as `AUTO` which generates an edit distance based on the length
* of the term. Defaults to `AUTO`.
*/
fuzziness(factor: number | string): this;
/**
* Set the prefix length for fuzzy queries. Default is `0`.
*
* @param {number} len
*/
fuzzyPrefixLength(len: number): this;
/**
* Sets the rewrite method. Valid values are:
* - `constant_score` - tries to pick the best constant-score rewrite
* method based on term and document counts from the query.
* Synonyms - `constant_score_auto`, `constant_score_filter`
* - `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_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_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`.
* This is an advanced option, use with care.
*
* Note: The deprecated multi term rewrite parameters `constant_score_auto`,
* `constant_score_filter` (synonyms for `constant_score`) have been removed in
* elasticsearch 6.0.
*
* @param {string} method The rewrite method as a string.
* @throws {Error} If the given `rewrite` method is not valid.
*/
rewrite(method: string): this;
/**
* Sets the fuzzy rewrite method. Valid values are:
* - `constant_score` - tries to pick the best constant-score rewrite
* method based on term and document counts from the query.
* Synonyms - `constant_score_auto`, `constant_score_filter`
* - `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_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_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`.
* This is an advanced option, use with care.
*
* Note: The deprecated multi term rewrite parameters `constant_score_auto`,
* `constant_score_filter` (synonyms for `constant_score`) have been removed in
* elasticsearch 6.0.
*
* @param {string} method The rewrite method as a string.
* @throws {Error} If the given `fuzzy_rewrite` method is not valid.
*/
fuzzyRewrite(method: string): this;
/**
* Sets the default slop for phrases. If zero, then exact phrase matches are required.
* Default value is 0.
*
* @param {number} slop A positive integer value, defaults is 0.
*/
phraseSlop(slop: number): this;
/**
* Auto generate phrase queries. Defaults to `false`.
*
* Note: This parameter has been removed in elasticsearch 6.0. If provided, it will be
* ignored and issue a deprecation warning.
*
* @param {boolean} enable
*/
autoGeneratePhraseQueries(enable: boolean): this;
/**
* Limit on how many automaton states regexp queries are allowed to create.
* This protects against too-difficult (e.g. exponentially hard) regexps.
* Defaults to 10000.
*
* @param {number} limit
*/
maxDeterminizedStates(limit: number): this;
/**
* Time Zone to be applied to any range query related to dates.
*
* @param {string} zone
*/
timeZone(zone: string): this;
/**
* Whether query text should be split on whitespace prior to analysis.
* Instead the queryparser would parse around only real operators.
* Default is `false`. It i