@travetto/model-elasticsearch 3.1.6 → 3.1.7
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/package.json +2 -2
- package/src/internal/query.ts +22 -1
- package/src/service.ts +11 -6
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@travetto/model-elasticsearch",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.7",
|
|
4
4
|
"description": "Elasticsearch backing for the travetto model module, with real-time modeling support for Elasticsearch mappings.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"elasticsearch",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"@elastic/elasticsearch": "^8.6.0",
|
|
31
31
|
"@travetto/config": "^3.1.2",
|
|
32
32
|
"@travetto/model": "^3.1.8",
|
|
33
|
-
"@travetto/model-query": "^3.1.
|
|
33
|
+
"@travetto/model-query": "^3.1.7"
|
|
34
34
|
},
|
|
35
35
|
"peerDependencies": {
|
|
36
36
|
"@travetto/command": "^3.1.2"
|
package/src/internal/query.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { QueryDslQueryContainer, SearchRequest, SearchResponse, Sort, SortOptions } from '@elastic/elasticsearch/lib/api/types';
|
|
1
|
+
import { InlineScript, QueryDslQueryContainer, SearchRequest, SearchResponse, Sort, SortOptions } from '@elastic/elasticsearch/lib/api/types';
|
|
2
2
|
|
|
3
3
|
import { Class, DataUtil, ObjectUtil } from '@travetto/base';
|
|
4
4
|
import { WhereClause, SelectClause, SortClause, Query } from '@travetto/model-query';
|
|
@@ -24,6 +24,18 @@ const has$Not = (o: unknown): o is ({ $not: WhereClause<unknown> }) => !!o && '$
|
|
|
24
24
|
*/
|
|
25
25
|
export class ElasticsearchQueryUtil {
|
|
26
26
|
|
|
27
|
+
/**
|
|
28
|
+
* Build the update script for a given object
|
|
29
|
+
*/
|
|
30
|
+
static generateEmptyScript(path: string): InlineScript {
|
|
31
|
+
const out: InlineScript = {
|
|
32
|
+
lang: 'painless',
|
|
33
|
+
source: 'return doc[params.key] == null || doc[params.key].size() == 0;',
|
|
34
|
+
params: { key: path },
|
|
35
|
+
};
|
|
36
|
+
return out;
|
|
37
|
+
}
|
|
38
|
+
|
|
27
39
|
/**
|
|
28
40
|
* Convert `a.b.c` to `a : { b : { c : ... }}`
|
|
29
41
|
*/
|
|
@@ -156,6 +168,15 @@ export class ElasticsearchQueryUtil {
|
|
|
156
168
|
items.push({ range: { [sPath]: out } });
|
|
157
169
|
break;
|
|
158
170
|
}
|
|
171
|
+
case '$empty': {
|
|
172
|
+
const q = {
|
|
173
|
+
script: {
|
|
174
|
+
script: this.generateEmptyScript(sPath)
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
items.push(v ? q : { bool: { ['must_not']: q } });
|
|
178
|
+
break;
|
|
179
|
+
}
|
|
159
180
|
case '$regex': {
|
|
160
181
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
161
182
|
const pattern = DataUtil.toRegex(v as string);
|
package/src/service.ts
CHANGED
|
@@ -61,12 +61,17 @@ export class ElasticsearchModelService implements
|
|
|
61
61
|
if (query && Object.keys(query).length === 0) {
|
|
62
62
|
query = undefined;
|
|
63
63
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
64
|
+
try {
|
|
65
|
+
const res = await this.client.search<T>({
|
|
66
|
+
...this.manager.getIdentity(cls),
|
|
67
|
+
...search,
|
|
68
|
+
query
|
|
69
|
+
});
|
|
70
|
+
return res;
|
|
71
|
+
} catch (err) {
|
|
72
|
+
console.error((err as any).meta.body.error);
|
|
73
|
+
throw err;
|
|
74
|
+
}
|
|
70
75
|
}
|
|
71
76
|
|
|
72
77
|
/**
|