-
-
Notifications
You must be signed in to change notification settings - Fork 77
/
Copy pathSearchBody.ts
59 lines (54 loc) · 1.69 KB
/
SearchBody.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import { InputTypeComposer } from 'graphql-compose';
import { getQueryITC, prepareQueryInResolve } from './Query/Query';
import { getAggsITC, prepareAggsInResolve } from './Aggs/Aggs';
import { getSortITC } from './Sort';
import { getTypeName, CommonOpts, desc } from '../utils';
export function getSearchBodyITC<TContext>(
opts: CommonOpts<TContext>
): InputTypeComposer<TContext> {
const name = getTypeName('SearchBody', opts);
const description = desc(
`
Request Body Search
[Documentation](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-body.html)
`
);
return opts.getOrCreateITC(name, () => ({
name,
description,
fields: {
query: { type: () => getQueryITC(opts) },
collapse: 'JSON',
aggs: { type: () => getAggsITC(opts) },
size: 'Int',
from: 'Int',
sort: { type: () => [getSortITC(opts)] },
_source: 'JSON',
script_fields: 'JSON',
post_filter: { type: () => getQueryITC(opts) },
highlight: 'JSON',
search_after: 'JSON',
explain: 'Boolean',
version: 'Boolean',
indices_boost: 'JSON',
min_score: 'Float',
search_type: 'String',
rescore: 'JSON',
docvalue_fields: '[String]',
stored_fields: '[String]',
},
}));
}
export function prepareBodyInResolve(body: any, fieldMap: any): { [argName: string]: any } {
/* eslint-disable no-param-reassign */
if (body.post_filter) {
body.post_filter = prepareQueryInResolve(body.post_filter, fieldMap);
}
if (body.query) {
body.query = prepareQueryInResolve(body.query, fieldMap);
}
if (body.aggs) {
body.aggs = prepareAggsInResolve(body.aggs, fieldMap);
}
return body;
}