Skip to content

Commit

Permalink
feat: case_insensitive support for Wildcard query (#142)
Browse files Browse the repository at this point in the history
case_insensitive support for Wildcard query was added in Elasticsearch
7.10.0.

Co-authored-by: Tengis Batsaikhan <[email protected]>
  • Loading branch information
tengis and Tengis Batsaikhan authored May 9, 2021
1 parent 47bf1ca commit 0dccb2a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1755,6 +1755,14 @@ declare namespace esb {
export class WildcardQuery extends MultiTermQueryBase {
constructor(field?: string, value?: string);

/**
* Allow case insensitive matching or not (added in 7.10.0).
* Defaults to false.
*
* @param {boolean} caseInsensitive
*/
caseInsensitive(caseInsensitive: boolean): this;

/**
* Sets the rewrite method. Valid values are:
* - `constant_score` - tries to pick the best constant-score rewrite
Expand Down
16 changes: 16 additions & 0 deletions src/queries/term-level-queries/wildcard-query.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,22 @@ class WildcardQuery extends MultiTermQueryBase {
super('wildcard', field, value);
}

/**
* Allow case insensitive matching or not (added in 7.10.0).
* Defaults to false.
*
* @example
* const qry = esb.wildcardQuery('user', 'ki*y')
* .caseInsensitive(true);
*
* @param {boolean} caseInsensitive
* @returns {RegexpQuery} returns `this` so that calls can be chained.
*/
caseInsensitive(caseInsensitive) {
this._queryOpts.case_insensitive = caseInsensitive;
return this;
}

/**
* Sets the rewrite method. Valid values are:
* - `constant_score` - tries to pick the best constant-score rewrite
Expand Down
1 change: 1 addition & 0 deletions test/queries-test/wildcard-query.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ const validRewrites = [

test(validatedCorrectly, getInstance, 'rewrite', validRewrites, false);
test(setsOption, 'rewrite', { param: 'constant_score' });
test(setsOption, 'caseInsensitive', true);

0 comments on commit 0dccb2a

Please sign in to comment.