Skip to content

Commit 5ce0325

Browse files
authored
feat: Add combined_fields query to index.d.ts (#218)
1 parent 7335699 commit 5ce0325

File tree

2 files changed

+129
-0
lines changed

2 files changed

+129
-0
lines changed

src/index.d.ts

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1391,6 +1391,108 @@ declare namespace esb {
13911391
queryString?: string
13921392
): SimpleQueryStringQuery;
13931393

1394+
/**
1395+
* The `combined_fields` query supports searching multiple text fields as if
1396+
* their contents had been indexed into one combined field. It takes a term-centric
1397+
* view of the query: first it analyzes the query string to produce individual terms,
1398+
* then looks for each term in any of the fields.
1399+
*
1400+
* [Elasticsearch reference](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-combined-fields-query.html)
1401+
*
1402+
* NOTE: This query was added in elasticsearch v7.13.
1403+
*
1404+
* @param {Array<string>|string=} fields The fields to be queried
1405+
* @param {string=} queryString The query string
1406+
* @extends FullTextQueryBase
1407+
*/
1408+
export class CombinedFieldsQuery extends FullTextQueryBase {
1409+
constructor(fields?: string[] | string, queryString?: string);
1410+
1411+
/**
1412+
* Appends given field to the list of fields to search against.
1413+
* Fields can be specified with wildcards.
1414+
* Individual fields can be boosted with the caret (^) notation.
1415+
* Example - `"subject^3"`
1416+
*
1417+
* @param {string} field One of the fields to be queried
1418+
* @returns {CombinedFieldsQuery} returns `this` so that calls can be chained.
1419+
*/
1420+
field(field: string): this;
1421+
1422+
/**
1423+
* Appends given fields to the list of fields to search against.
1424+
* Fields can be specified with wildcards.
1425+
* Individual fields can be boosted with the caret (^) notation.
1426+
*
1427+
* @example
1428+
* // Boost individual fields with caret `^` notation
1429+
* const qry = esb.combinedFieldsQuery(['subject^3', 'message'], 'this is a test');
1430+
*
1431+
* @example
1432+
* // Specify fields with wildcards
1433+
* const qry = esb.combinedFieldsQuery(['title', '*_name'], 'Will Smith');
1434+
*
1435+
* @param {Array<string>} fields The fields to be queried
1436+
* @returns {CombinedFieldsQuery} returns `this` so that calls can be chained.
1437+
*/
1438+
fields(fields: string[]): this;
1439+
1440+
/**
1441+
* If true, match phrase queries are automatically created for multi-term synonyms.
1442+
*
1443+
* @param {boolean} enable Defaults to `true`
1444+
* @returns {CombinedFieldsQuery} returns `this` so that calls can be chained.
1445+
*/
1446+
autoGenerateSynonymsPhraseQuery(enable: boolean): this;
1447+
1448+
/**
1449+
* The operator to be used in the boolean query which is constructed
1450+
* by analyzing the text provided. The `operator` flag can be set to `or` or
1451+
* `and` to control the boolean clauses (defaults to `or`).
1452+
*
1453+
* @param {string} operator Can be `and`/`or`. Default is `or`.
1454+
* @returns {CombinedFieldsQuery} returns `this` so that calls can be chained.
1455+
*/
1456+
operator(operator: 'and' | 'or'): this;
1457+
1458+
/**
1459+
* If the analyzer used removes all tokens in a query like a `stop` filter does,
1460+
* the default behavior is to match no documents at all. In order to change that
1461+
* the `zero_terms_query` option can be used, which accepts `none` (default) and `all`
1462+
* which corresponds to a `match_all` query.
1463+
*
1464+
* @example
1465+
* const qry = esb.combinedFieldsQuery('message', 'to be or not to be')
1466+
* .operator('and')
1467+
* .zeroTermsQuery('all');
1468+
*
1469+
* @param {string} behavior A no match action, `all` or `none`. Default is `none`.
1470+
* @returns {CombinedFieldsQuery} returns `this` so that calls can be chained.
1471+
*/
1472+
zeroTermsQuery(behavior: 'all' | 'none'): this;
1473+
}
1474+
1475+
/**
1476+
* The `combined_fields` query supports searching multiple text fields as if
1477+
* their contents had been indexed into one combined field. It takes a term-centric
1478+
* view of the query: first it analyzes the query string to produce individual terms,
1479+
* then looks for each term in any of the fields.
1480+
*
1481+
* [Elasticsearch reference](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-combined-fields-query.html)
1482+
*
1483+
* NOTE: This query was added in elasticsearch v7.13.
1484+
*
1485+
* @example
1486+
* const qry = esb.combinedFieldsQuery(['subject', 'message'], 'this is a test');
1487+
*
1488+
* @param {Array<string>|string=} fields The fields to be queried
1489+
* @param {string=} queryString The query string
1490+
*/
1491+
export function combinedFieldsQuery(
1492+
fields?: string[] | string,
1493+
queryString?: string
1494+
): CombinedFieldsQuery;
1495+
13941496
/**
13951497
* The `ValueTermQueryBase` provides support for common options used across
13961498
* various term level query implementations.

test/typedef.test.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,33 @@ esb
2222
.minimumShouldMatch('30%')
2323
);
2424

25+
// Combined Fields Query
26+
esb
27+
.requestBodySearch()
28+
.query(
29+
esb
30+
.combinedFieldsQuery(['title', 'body'], 'Quick brown fox')
31+
.operator('and')
32+
.autoGenerateSynonymsPhraseQuery(true)
33+
.zeroTermsQuery('all')
34+
);
35+
36+
// Combined Fields Query with single field
37+
esb
38+
.requestBodySearch()
39+
.query(
40+
esb
41+
.combinedFieldsQuery('title', 'Quick brown fox')
42+
.field('description')
43+
.fields(['tags', 'content^2'])
44+
);
45+
46+
// Combined Fields Query - class constructor
47+
new esb.CombinedFieldsQuery(['title', 'content'], 'search terms')
48+
.operator('or')
49+
.autoGenerateSynonymsPhraseQuery(false)
50+
.toJSON();
51+
2552
// Percolate Query
2653
esb
2754
.requestBodySearch()

0 commit comments

Comments
 (0)