Skip to content

Commit 5b20e48

Browse files
committed
examples/ added
1 parent 823f28d commit 5b20e48

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

examples/compound-bool.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
const { ElasticSearchDynamicQuery } = require('elasticsearch-dynamic-query');
2+
3+
function example1() {
4+
const command = {
5+
title: {
6+
type: 'TEXT',
7+
conditions: {
8+
$eq: title
9+
}
10+
}
11+
}
12+
13+
const builder = new ElasticSearchDynamicQuery(command);
14+
const query = builder.compoundQuery().build();
15+
console.log(query);
16+
// bool: {
17+
// must: [
18+
// {
19+
// match: {
20+
// title: title
21+
// }
22+
// }
23+
// ]
24+
// }
25+
}
26+
27+
function example2() {
28+
const releaseYear = 2022;
29+
30+
const command = {
31+
release_year: {
32+
type: DataTypeEnum.NUMBER,
33+
conditions: {
34+
$eq: releaseYear
35+
}
36+
}
37+
}
38+
39+
const builder = new ElasticSearchDynamicQuery(command);
40+
const query = builder.compoundQuery().build();
41+
console.log(query);
42+
// bool: {
43+
// must: [
44+
// {
45+
// term: {
46+
// release_year: releaseYear
47+
// }
48+
// }
49+
// ]
50+
// }
51+
}

0 commit comments

Comments
 (0)