@webiny/api-elasticsearch 0.0.0-mt-1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +1 -0
- package/client.d.ts +5 -0
- package/client.js +47 -0
- package/compression.d.ts +6 -0
- package/compression.js +68 -0
- package/cursors.d.ts +9 -0
- package/cursors.js +49 -0
- package/index.d.ts +9 -0
- package/index.js +38 -0
- package/limit.d.ts +1 -0
- package/limit.js +45 -0
- package/normalize.d.ts +5 -0
- package/normalize.js +27 -0
- package/operators.d.ts +18 -0
- package/operators.js +42 -0
- package/package.json +49 -0
- package/plugins/GzipCompression.d.ts +19 -0
- package/plugins/GzipCompression.js +75 -0
- package/plugins/definition/CompressionPlugin.d.ts +20 -0
- package/plugins/definition/CompressionPlugin.js +17 -0
- package/plugins/definition/ElasticsearchBodyModifierPlugin.d.ts +13 -0
- package/plugins/definition/ElasticsearchBodyModifierPlugin.js +35 -0
- package/plugins/definition/ElasticsearchFieldPlugin.d.ts +87 -0
- package/plugins/definition/ElasticsearchFieldPlugin.js +128 -0
- package/plugins/definition/ElasticsearchQueryBuilderOperatorPlugin.d.ts +10 -0
- package/plugins/definition/ElasticsearchQueryBuilderOperatorPlugin.js +20 -0
- package/plugins/definition/ElasticsearchQueryModifierPlugin.d.ts +14 -0
- package/plugins/definition/ElasticsearchQueryModifierPlugin.js +35 -0
- package/plugins/definition/ElasticsearchSortModifierPlugin.d.ts +13 -0
- package/plugins/definition/ElasticsearchSortModifierPlugin.js +35 -0
- package/plugins/operator/andIn.d.ts +7 -0
- package/plugins/operator/andIn.js +56 -0
- package/plugins/operator/between.d.ts +7 -0
- package/plugins/operator/between.js +51 -0
- package/plugins/operator/contains.d.ts +7 -0
- package/plugins/operator/contains.js +43 -0
- package/plugins/operator/equal.d.ts +7 -0
- package/plugins/operator/equal.js +45 -0
- package/plugins/operator/gt.d.ts +7 -0
- package/plugins/operator/gt.js +40 -0
- package/plugins/operator/gte.d.ts +7 -0
- package/plugins/operator/gte.js +40 -0
- package/plugins/operator/in.d.ts +7 -0
- package/plugins/operator/in.js +54 -0
- package/plugins/operator/index.d.ts +13 -0
- package/plugins/operator/index.js +174 -0
- package/plugins/operator/lt.d.ts +7 -0
- package/plugins/operator/lt.js +40 -0
- package/plugins/operator/lte.d.ts +7 -0
- package/plugins/operator/lte.js +40 -0
- package/plugins/operator/not.d.ts +7 -0
- package/plugins/operator/not.js +40 -0
- package/plugins/operator/notBetween.d.ts +7 -0
- package/plugins/operator/notBetween.js +51 -0
- package/plugins/operator/notContains.d.ts +7 -0
- package/plugins/operator/notContains.js +43 -0
- package/plugins/operator/notIn.d.ts +7 -0
- package/plugins/operator/notIn.js +46 -0
- package/sort.d.ts +12 -0
- package/sort.js +67 -0
- package/types.d.ts +49 -0
- package/types.js +18 -0
- package/where.d.ts +17 -0
- package/where.js +106 -0
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { Plugin } from "@webiny/plugins";
|
|
2
|
+
import { FieldSortOptions, SortOrder } from "elastic-ts";
|
|
3
|
+
export declare type UnmappedTypes = "date" | "long" | string;
|
|
4
|
+
export interface ToSearchValueParams {
|
|
5
|
+
/**
|
|
6
|
+
* The value to transform.
|
|
7
|
+
*/
|
|
8
|
+
value: any;
|
|
9
|
+
/**
|
|
10
|
+
* When using toSearchValue() in our code we send a field.getPath() value here.
|
|
11
|
+
*/
|
|
12
|
+
path: string;
|
|
13
|
+
/**
|
|
14
|
+
* When using toSearchValue() in our code we send a field.getBasePath() value here.
|
|
15
|
+
*/
|
|
16
|
+
basePath: string;
|
|
17
|
+
}
|
|
18
|
+
export interface Params {
|
|
19
|
+
/**
|
|
20
|
+
* Which field is this plugin for.
|
|
21
|
+
*/
|
|
22
|
+
field: string;
|
|
23
|
+
/**
|
|
24
|
+
* Some specific path of a field?
|
|
25
|
+
* Example: createdBy is createdBy.id
|
|
26
|
+
*/
|
|
27
|
+
path?: string;
|
|
28
|
+
/**
|
|
29
|
+
* Add a .keyword at the end of the field path?
|
|
30
|
+
*/
|
|
31
|
+
keyword?: boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Is the field of a specific type, but possibly not mapped?
|
|
34
|
+
* Happens when inserting a date in string format.
|
|
35
|
+
* You need to cast it as date when running the search/sort to work correctly.
|
|
36
|
+
*/
|
|
37
|
+
unmappedType?: UnmappedTypes;
|
|
38
|
+
/**
|
|
39
|
+
* Is the field sortable?
|
|
40
|
+
*/
|
|
41
|
+
sortable?: boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Is the field searchable?
|
|
44
|
+
*/
|
|
45
|
+
searchable?: boolean;
|
|
46
|
+
/**
|
|
47
|
+
* Used to transform the input value for the search.
|
|
48
|
+
*/
|
|
49
|
+
toSearchValue?: (params: ToSearchValueParams) => any;
|
|
50
|
+
}
|
|
51
|
+
export declare abstract class ElasticsearchFieldPlugin extends Plugin {
|
|
52
|
+
static readonly type: string;
|
|
53
|
+
static readonly ALL: string;
|
|
54
|
+
private readonly _field;
|
|
55
|
+
private readonly _path;
|
|
56
|
+
private readonly _keyword;
|
|
57
|
+
private readonly _unmappedType;
|
|
58
|
+
private readonly _sortable;
|
|
59
|
+
private readonly _searchable;
|
|
60
|
+
get field(): string;
|
|
61
|
+
get path(): string;
|
|
62
|
+
get keyword(): boolean;
|
|
63
|
+
get unmappedType(): string | undefined;
|
|
64
|
+
get sortable(): boolean;
|
|
65
|
+
get searchable(): boolean;
|
|
66
|
+
constructor(params: Params);
|
|
67
|
+
/**
|
|
68
|
+
* The default sort options. Extend in your own plugin if you want to add more options.
|
|
69
|
+
*/
|
|
70
|
+
getSortOptions(order: SortOrder): FieldSortOptions;
|
|
71
|
+
/**
|
|
72
|
+
* The default path generator. Extend in your own plugin if you want to add more options.
|
|
73
|
+
* Field parameter is here because there is a possibility that this is the ALL field plugin, so we need to know which field are we working on.
|
|
74
|
+
*/
|
|
75
|
+
getPath(field: string): string;
|
|
76
|
+
/**
|
|
77
|
+
* @see getPath
|
|
78
|
+
*
|
|
79
|
+
* This is the default base path generator. Basically it replaces ALL with given field name.
|
|
80
|
+
*/
|
|
81
|
+
getBasePath(field: string): string;
|
|
82
|
+
/**
|
|
83
|
+
* The default transformer. Just returns the value by default.
|
|
84
|
+
* Override to implement what ever is required.
|
|
85
|
+
*/
|
|
86
|
+
toSearchValue(params: ToSearchValueParams): any;
|
|
87
|
+
}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.ElasticsearchFieldPlugin = void 0;
|
|
9
|
+
|
|
10
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
+
|
|
12
|
+
var _plugins = require("@webiny/plugins");
|
|
13
|
+
|
|
14
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
|
15
|
+
|
|
16
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
17
|
+
|
|
18
|
+
const keywordLessUnmappedType = ["date", "long"];
|
|
19
|
+
|
|
20
|
+
const unmappedTypeHasKeyword = type => {
|
|
21
|
+
if (keywordLessUnmappedType.includes(type)) {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return true;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
class ElasticsearchFieldPlugin extends _plugins.Plugin {
|
|
29
|
+
get field() {
|
|
30
|
+
return this._field;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
get path() {
|
|
34
|
+
return this._path;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
get keyword() {
|
|
38
|
+
return this._keyword;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
get unmappedType() {
|
|
42
|
+
return this._unmappedType;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
get sortable() {
|
|
46
|
+
return this._sortable;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
get searchable() {
|
|
50
|
+
return this._searchable;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
constructor(params) {
|
|
54
|
+
super();
|
|
55
|
+
(0, _defineProperty2.default)(this, "_field", void 0);
|
|
56
|
+
(0, _defineProperty2.default)(this, "_path", void 0);
|
|
57
|
+
(0, _defineProperty2.default)(this, "_keyword", void 0);
|
|
58
|
+
(0, _defineProperty2.default)(this, "_unmappedType", void 0);
|
|
59
|
+
(0, _defineProperty2.default)(this, "_sortable", void 0);
|
|
60
|
+
(0, _defineProperty2.default)(this, "_searchable", void 0);
|
|
61
|
+
this._field = params.field;
|
|
62
|
+
this._path = params.path || params.field;
|
|
63
|
+
this._keyword = params.keyword === undefined ? true : params.keyword;
|
|
64
|
+
this._unmappedType = params.unmappedType;
|
|
65
|
+
|
|
66
|
+
if (unmappedTypeHasKeyword(params.unmappedType) === false) {
|
|
67
|
+
this._keyword = false;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
this._sortable = params.sortable === undefined ? true : params.sortable;
|
|
71
|
+
this._searchable = params.searchable === undefined ? true : params.searchable;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* The default sort options. Extend in your own plugin if you want to add more options.
|
|
75
|
+
*/
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
getSortOptions(order) {
|
|
79
|
+
const options = {
|
|
80
|
+
order
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
if (!this._unmappedType) {
|
|
84
|
+
return options;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
return _objectSpread(_objectSpread({}, options), {}, {
|
|
88
|
+
unmapped_type: this._unmappedType
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* The default path generator. Extend in your own plugin if you want to add more options.
|
|
93
|
+
* Field parameter is here because there is a possibility that this is the ALL field plugin, so we need to know which field are we working on.
|
|
94
|
+
*/
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
getPath(field) {
|
|
98
|
+
return `${this.getBasePath(field)}${this._keyword ? ".keyword" : ""}`;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* @see getPath
|
|
102
|
+
*
|
|
103
|
+
* This is the default base path generator. Basically it replaces ALL with given field name.
|
|
104
|
+
*/
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
getBasePath(field) {
|
|
108
|
+
if (this._path === this.constructor.ALL) {
|
|
109
|
+
return field;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return this._path;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* The default transformer. Just returns the value by default.
|
|
116
|
+
* Override to implement what ever is required.
|
|
117
|
+
*/
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
toSearchValue(params) {
|
|
121
|
+
return params.value;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
exports.ElasticsearchFieldPlugin = ElasticsearchFieldPlugin;
|
|
127
|
+
(0, _defineProperty2.default)(ElasticsearchFieldPlugin, "type", "elasticsearch.fieldDefinition");
|
|
128
|
+
(0, _defineProperty2.default)(ElasticsearchFieldPlugin, "ALL", "*");
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Plugin } from "@webiny/plugins";
|
|
2
|
+
import { ElasticsearchBoolQueryConfig, ElasticsearchQueryBuilderArgsPlugin } from "../../types";
|
|
3
|
+
/**
|
|
4
|
+
* Built-in operators name ends with .default because user can override the operator, just write a name without the .default keyword.
|
|
5
|
+
*/
|
|
6
|
+
export declare abstract class ElasticsearchQueryBuilderOperatorPlugin extends Plugin {
|
|
7
|
+
static readonly type = "elasticsearch.queryBuilder.operator";
|
|
8
|
+
abstract getOperator(): string;
|
|
9
|
+
abstract apply(query: ElasticsearchBoolQueryConfig, params: ElasticsearchQueryBuilderArgsPlugin): void;
|
|
10
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.ElasticsearchQueryBuilderOperatorPlugin = void 0;
|
|
9
|
+
|
|
10
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
+
|
|
12
|
+
var _plugins = require("@webiny/plugins");
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Built-in operators name ends with .default because user can override the operator, just write a name without the .default keyword.
|
|
16
|
+
*/
|
|
17
|
+
class ElasticsearchQueryBuilderOperatorPlugin extends _plugins.Plugin {}
|
|
18
|
+
|
|
19
|
+
exports.ElasticsearchQueryBuilderOperatorPlugin = ElasticsearchQueryBuilderOperatorPlugin;
|
|
20
|
+
(0, _defineProperty2.default)(ElasticsearchQueryBuilderOperatorPlugin, "type", "elasticsearch.queryBuilder.operator");
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Plugin } from "@webiny/plugins";
|
|
2
|
+
import { ElasticsearchBoolQueryConfig } from "../../types";
|
|
3
|
+
export interface ModifyQueryParams {
|
|
4
|
+
query: ElasticsearchBoolQueryConfig;
|
|
5
|
+
where: Record<string, any>;
|
|
6
|
+
}
|
|
7
|
+
export interface ModifyQueryCallable<T extends ModifyQueryParams> {
|
|
8
|
+
(params: T): void;
|
|
9
|
+
}
|
|
10
|
+
export declare abstract class ElasticsearchQueryModifierPlugin<T extends ModifyQueryParams = ModifyQueryParams> extends Plugin {
|
|
11
|
+
private readonly callable?;
|
|
12
|
+
constructor(callable?: ModifyQueryCallable<T>);
|
|
13
|
+
modifyQuery(params: T): void;
|
|
14
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.ElasticsearchQueryModifierPlugin = void 0;
|
|
9
|
+
|
|
10
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
+
|
|
12
|
+
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
13
|
+
|
|
14
|
+
var _plugins = require("@webiny/plugins");
|
|
15
|
+
|
|
16
|
+
class ElasticsearchQueryModifierPlugin extends _plugins.Plugin {
|
|
17
|
+
constructor(callable) {
|
|
18
|
+
super();
|
|
19
|
+
(0, _defineProperty2.default)(this, "callable", void 0);
|
|
20
|
+
this.callable = callable;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
modifyQuery(params) {
|
|
24
|
+
if (typeof this.callable !== "function") {
|
|
25
|
+
throw new _error.default(`Missing modification for the query.`, "QUERY_MODIFICATION_MISSING", {
|
|
26
|
+
params
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
this.callable(params);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
exports.ElasticsearchQueryModifierPlugin = ElasticsearchQueryModifierPlugin;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Plugin } from "@webiny/plugins";
|
|
2
|
+
import { Sort } from "elastic-ts";
|
|
3
|
+
export interface ModifySortParams {
|
|
4
|
+
sort: Sort;
|
|
5
|
+
}
|
|
6
|
+
export interface ModifySortCallable<T extends ModifySortParams> {
|
|
7
|
+
(params: T): void;
|
|
8
|
+
}
|
|
9
|
+
export declare abstract class ElasticsearchSortModifierPlugin<T extends ModifySortParams = ModifySortParams> extends Plugin {
|
|
10
|
+
private readonly callable?;
|
|
11
|
+
constructor(callable?: ModifySortCallable<T>);
|
|
12
|
+
modifySort(params: T): void;
|
|
13
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.ElasticsearchSortModifierPlugin = void 0;
|
|
9
|
+
|
|
10
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
+
|
|
12
|
+
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
13
|
+
|
|
14
|
+
var _plugins = require("@webiny/plugins");
|
|
15
|
+
|
|
16
|
+
class ElasticsearchSortModifierPlugin extends _plugins.Plugin {
|
|
17
|
+
constructor(callable) {
|
|
18
|
+
super();
|
|
19
|
+
(0, _defineProperty2.default)(this, "callable", void 0);
|
|
20
|
+
this.callable = callable;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
modifySort(params) {
|
|
24
|
+
if (typeof this.callable !== "function") {
|
|
25
|
+
throw new _error.default(`Missing modification for the sort.`, "SORT_MODIFICATION_MISSING", {
|
|
26
|
+
params
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
this.callable(params);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
exports.ElasticsearchSortModifierPlugin = ElasticsearchSortModifierPlugin;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ElasticsearchQueryBuilderOperatorPlugin } from "../definition/ElasticsearchQueryBuilderOperatorPlugin";
|
|
2
|
+
import { ElasticsearchBoolQueryConfig, ElasticsearchQueryBuilderArgsPlugin } from "../../types";
|
|
3
|
+
export declare class ElasticsearchQueryBuilderOperatorAndInPlugin extends ElasticsearchQueryBuilderOperatorPlugin {
|
|
4
|
+
name: string;
|
|
5
|
+
getOperator(): string;
|
|
6
|
+
apply(query: ElasticsearchBoolQueryConfig, params: ElasticsearchQueryBuilderArgsPlugin): void;
|
|
7
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.ElasticsearchQueryBuilderOperatorAndInPlugin = void 0;
|
|
9
|
+
|
|
10
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
+
|
|
12
|
+
var _ElasticsearchQueryBuilderOperatorPlugin = require("../definition/ElasticsearchQueryBuilderOperatorPlugin");
|
|
13
|
+
|
|
14
|
+
class ElasticsearchQueryBuilderOperatorAndInPlugin extends _ElasticsearchQueryBuilderOperatorPlugin.ElasticsearchQueryBuilderOperatorPlugin {
|
|
15
|
+
constructor(...args) {
|
|
16
|
+
super(...args);
|
|
17
|
+
(0, _defineProperty2.default)(this, "name", "elasticsearch.queryBuilder.operator.andIn.default");
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
getOperator() {
|
|
21
|
+
return "and_in";
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
apply(query, params) {
|
|
25
|
+
const {
|
|
26
|
+
value: values,
|
|
27
|
+
path,
|
|
28
|
+
basePath
|
|
29
|
+
} = params;
|
|
30
|
+
const isArray = Array.isArray(values);
|
|
31
|
+
|
|
32
|
+
if (isArray === false || values.length === 0) {
|
|
33
|
+
throw new Error(`You cannot filter field "${path}" with "in" operator and not send an array of values.`);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
let useBasePath = false; // Only use ".keyword" if all of the provided values are strings.
|
|
37
|
+
|
|
38
|
+
for (const value of values) {
|
|
39
|
+
if (typeof value !== "string") {
|
|
40
|
+
useBasePath = true;
|
|
41
|
+
break;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
for (const value of values) {
|
|
46
|
+
query.must.push({
|
|
47
|
+
term: {
|
|
48
|
+
[useBasePath ? basePath : path]: value
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
exports.ElasticsearchQueryBuilderOperatorAndInPlugin = ElasticsearchQueryBuilderOperatorAndInPlugin;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ElasticsearchQueryBuilderOperatorPlugin } from "../definition/ElasticsearchQueryBuilderOperatorPlugin";
|
|
2
|
+
import { ElasticsearchBoolQueryConfig, ElasticsearchQueryBuilderArgsPlugin } from "../../types";
|
|
3
|
+
export declare class ElasticsearchQueryBuilderOperatorBetweenPlugin extends ElasticsearchQueryBuilderOperatorPlugin {
|
|
4
|
+
name: string;
|
|
5
|
+
getOperator(): string;
|
|
6
|
+
apply(query: ElasticsearchBoolQueryConfig, params: ElasticsearchQueryBuilderArgsPlugin): void;
|
|
7
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.ElasticsearchQueryBuilderOperatorBetweenPlugin = void 0;
|
|
9
|
+
|
|
10
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
+
|
|
12
|
+
var _ElasticsearchQueryBuilderOperatorPlugin = require("../definition/ElasticsearchQueryBuilderOperatorPlugin");
|
|
13
|
+
|
|
14
|
+
class ElasticsearchQueryBuilderOperatorBetweenPlugin extends _ElasticsearchQueryBuilderOperatorPlugin.ElasticsearchQueryBuilderOperatorPlugin {
|
|
15
|
+
constructor(...args) {
|
|
16
|
+
super(...args);
|
|
17
|
+
(0, _defineProperty2.default)(this, "name", "elasticsearch.queryBuilder.operator.between.default");
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
getOperator() {
|
|
21
|
+
return "between";
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
apply(query, params) {
|
|
25
|
+
const {
|
|
26
|
+
value,
|
|
27
|
+
basePath
|
|
28
|
+
} = params;
|
|
29
|
+
|
|
30
|
+
if (Array.isArray(value) === false) {
|
|
31
|
+
throw new Error(`You cannot filter field path "${basePath}" with between query and not send an array of values.`);
|
|
32
|
+
} else if (value.length !== 2) {
|
|
33
|
+
throw new Error(`You must pass 2 values in the array for field path "${basePath}" filtering.`);
|
|
34
|
+
} // we take gte first because it should be a lesser value than lte, eg [5, 10]
|
|
35
|
+
// 6 >= gte && 6 <= lte
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
const [gte, lte] = value;
|
|
39
|
+
query.must.push({
|
|
40
|
+
range: {
|
|
41
|
+
[basePath]: {
|
|
42
|
+
lte,
|
|
43
|
+
gte
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
exports.ElasticsearchQueryBuilderOperatorBetweenPlugin = ElasticsearchQueryBuilderOperatorBetweenPlugin;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ElasticsearchQueryBuilderOperatorPlugin } from "../definition/ElasticsearchQueryBuilderOperatorPlugin";
|
|
2
|
+
import { ElasticsearchBoolQueryConfig, ElasticsearchQueryBuilderArgsPlugin } from "../../types";
|
|
3
|
+
export declare class ElasticsearchQueryBuilderOperatorContainsPlugin extends ElasticsearchQueryBuilderOperatorPlugin {
|
|
4
|
+
name: string;
|
|
5
|
+
getOperator(): string;
|
|
6
|
+
apply(query: ElasticsearchBoolQueryConfig, params: ElasticsearchQueryBuilderArgsPlugin): void;
|
|
7
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.ElasticsearchQueryBuilderOperatorContainsPlugin = void 0;
|
|
9
|
+
|
|
10
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
+
|
|
12
|
+
var _ElasticsearchQueryBuilderOperatorPlugin = require("../definition/ElasticsearchQueryBuilderOperatorPlugin");
|
|
13
|
+
|
|
14
|
+
var _normalize = require("../../normalize");
|
|
15
|
+
|
|
16
|
+
class ElasticsearchQueryBuilderOperatorContainsPlugin extends _ElasticsearchQueryBuilderOperatorPlugin.ElasticsearchQueryBuilderOperatorPlugin {
|
|
17
|
+
constructor(...args) {
|
|
18
|
+
super(...args);
|
|
19
|
+
(0, _defineProperty2.default)(this, "name", "elasticsearch.queryBuilder.operator.contains.default");
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
getOperator() {
|
|
23
|
+
return "contains";
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
apply(query, params) {
|
|
27
|
+
const {
|
|
28
|
+
value,
|
|
29
|
+
basePath
|
|
30
|
+
} = params;
|
|
31
|
+
query.must.push({
|
|
32
|
+
query_string: {
|
|
33
|
+
allow_leading_wildcard: true,
|
|
34
|
+
fields: [basePath],
|
|
35
|
+
query: (0, _normalize.normalizeValue)(value),
|
|
36
|
+
default_operator: "and"
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
exports.ElasticsearchQueryBuilderOperatorContainsPlugin = ElasticsearchQueryBuilderOperatorContainsPlugin;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ElasticsearchQueryBuilderOperatorPlugin } from "../definition/ElasticsearchQueryBuilderOperatorPlugin";
|
|
2
|
+
import { ElasticsearchBoolQueryConfig, ElasticsearchQueryBuilderArgsPlugin } from "../../types";
|
|
3
|
+
export declare class ElasticsearchQueryBuilderOperatorEqualPlugin extends ElasticsearchQueryBuilderOperatorPlugin {
|
|
4
|
+
name: string;
|
|
5
|
+
getOperator(): string;
|
|
6
|
+
apply(query: ElasticsearchBoolQueryConfig, params: ElasticsearchQueryBuilderArgsPlugin): void;
|
|
7
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.ElasticsearchQueryBuilderOperatorEqualPlugin = void 0;
|
|
9
|
+
|
|
10
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
+
|
|
12
|
+
var _ElasticsearchQueryBuilderOperatorPlugin = require("../definition/ElasticsearchQueryBuilderOperatorPlugin");
|
|
13
|
+
|
|
14
|
+
class ElasticsearchQueryBuilderOperatorEqualPlugin extends _ElasticsearchQueryBuilderOperatorPlugin.ElasticsearchQueryBuilderOperatorPlugin {
|
|
15
|
+
constructor(...args) {
|
|
16
|
+
super(...args);
|
|
17
|
+
(0, _defineProperty2.default)(this, "name", "elasticsearch.queryBuilder.operator.equal.default");
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
getOperator() {
|
|
21
|
+
return "eq";
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
apply(query, params) {
|
|
25
|
+
const {
|
|
26
|
+
value,
|
|
27
|
+
path,
|
|
28
|
+
basePath
|
|
29
|
+
} = params;
|
|
30
|
+
/**
|
|
31
|
+
* In case we are searching for a string, use regular path.
|
|
32
|
+
* Otherwise use base path
|
|
33
|
+
*/
|
|
34
|
+
|
|
35
|
+
const useBasePath = typeof value !== "string";
|
|
36
|
+
query.must.push({
|
|
37
|
+
term: {
|
|
38
|
+
[useBasePath ? basePath : path]: value
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
exports.ElasticsearchQueryBuilderOperatorEqualPlugin = ElasticsearchQueryBuilderOperatorEqualPlugin;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ElasticsearchQueryBuilderOperatorPlugin } from "../definition/ElasticsearchQueryBuilderOperatorPlugin";
|
|
2
|
+
import { ElasticsearchBoolQueryConfig, ElasticsearchQueryBuilderArgsPlugin } from "../../types";
|
|
3
|
+
export declare class ElasticsearchQueryBuilderOperatorGreaterThanPlugin extends ElasticsearchQueryBuilderOperatorPlugin {
|
|
4
|
+
name: string;
|
|
5
|
+
getOperator(): string;
|
|
6
|
+
apply(query: ElasticsearchBoolQueryConfig, params: ElasticsearchQueryBuilderArgsPlugin): void;
|
|
7
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.ElasticsearchQueryBuilderOperatorGreaterThanPlugin = void 0;
|
|
9
|
+
|
|
10
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
+
|
|
12
|
+
var _ElasticsearchQueryBuilderOperatorPlugin = require("../definition/ElasticsearchQueryBuilderOperatorPlugin");
|
|
13
|
+
|
|
14
|
+
class ElasticsearchQueryBuilderOperatorGreaterThanPlugin extends _ElasticsearchQueryBuilderOperatorPlugin.ElasticsearchQueryBuilderOperatorPlugin {
|
|
15
|
+
constructor(...args) {
|
|
16
|
+
super(...args);
|
|
17
|
+
(0, _defineProperty2.default)(this, "name", "elasticsearch.queryBuilder.operator.greaterThan.default");
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
getOperator() {
|
|
21
|
+
return "gt";
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
apply(query, params) {
|
|
25
|
+
const {
|
|
26
|
+
value,
|
|
27
|
+
basePath
|
|
28
|
+
} = params;
|
|
29
|
+
query.must.push({
|
|
30
|
+
range: {
|
|
31
|
+
[basePath]: {
|
|
32
|
+
gt: value
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
exports.ElasticsearchQueryBuilderOperatorGreaterThanPlugin = ElasticsearchQueryBuilderOperatorGreaterThanPlugin;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ElasticsearchQueryBuilderOperatorPlugin } from "../definition/ElasticsearchQueryBuilderOperatorPlugin";
|
|
2
|
+
import { ElasticsearchBoolQueryConfig, ElasticsearchQueryBuilderArgsPlugin } from "../../types";
|
|
3
|
+
export declare class ElasticsearchQueryBuilderOperatorGreaterThanOrEqualToPlugin extends ElasticsearchQueryBuilderOperatorPlugin {
|
|
4
|
+
name: string;
|
|
5
|
+
getOperator(): string;
|
|
6
|
+
apply(query: ElasticsearchBoolQueryConfig, params: ElasticsearchQueryBuilderArgsPlugin): void;
|
|
7
|
+
}
|