@@ -35,12 +35,133 @@ import {
35
35
TransportResult
36
36
} from '@elastic/transport'
37
37
import * as T from '../types'
38
- interface That { transport : Transport }
38
+
39
+ interface That {
40
+ transport : Transport
41
+ acceptedParams : Record < string , { path : string [ ] , body : string [ ] , query : string [ ] } >
42
+ }
43
+
44
+ const commonQueryParams = [ 'error_trace' , 'filter_path' , 'human' , 'pretty' ]
39
45
40
46
export default class AsyncSearch {
41
47
transport : Transport
48
+ acceptedParams : Record < string , { path : string [ ] , body : string [ ] , query : string [ ] } >
42
49
constructor ( transport : Transport ) {
43
50
this . transport = transport
51
+ this . acceptedParams = {
52
+ 'async_search.delete' : {
53
+ path : [
54
+ 'id'
55
+ ] ,
56
+ body : [ ] ,
57
+ query : [ ]
58
+ } ,
59
+ 'async_search.get' : {
60
+ path : [
61
+ 'id'
62
+ ] ,
63
+ body : [ ] ,
64
+ query : [
65
+ 'keep_alive' ,
66
+ 'typed_keys' ,
67
+ 'wait_for_completion_timeout'
68
+ ]
69
+ } ,
70
+ 'async_search.status' : {
71
+ path : [
72
+ 'id'
73
+ ] ,
74
+ body : [ ] ,
75
+ query : [
76
+ 'keep_alive'
77
+ ]
78
+ } ,
79
+ 'async_search.submit' : {
80
+ path : [
81
+ 'index'
82
+ ] ,
83
+ body : [
84
+ 'aggregations' ,
85
+ 'aggs' ,
86
+ 'collapse' ,
87
+ 'explain' ,
88
+ 'ext' ,
89
+ 'from' ,
90
+ 'highlight' ,
91
+ 'track_total_hits' ,
92
+ 'indices_boost' ,
93
+ 'docvalue_fields' ,
94
+ 'knn' ,
95
+ 'min_score' ,
96
+ 'post_filter' ,
97
+ 'profile' ,
98
+ 'query' ,
99
+ 'rescore' ,
100
+ 'script_fields' ,
101
+ 'search_after' ,
102
+ 'size' ,
103
+ 'slice' ,
104
+ 'sort' ,
105
+ '_source' ,
106
+ 'fields' ,
107
+ 'suggest' ,
108
+ 'terminate_after' ,
109
+ 'timeout' ,
110
+ 'track_scores' ,
111
+ 'version' ,
112
+ 'seq_no_primary_term' ,
113
+ 'stored_fields' ,
114
+ 'pit' ,
115
+ 'runtime_mappings' ,
116
+ 'stats'
117
+ ] ,
118
+ query : [
119
+ 'wait_for_completion_timeout' ,
120
+ 'keep_alive' ,
121
+ 'keep_on_completion' ,
122
+ 'allow_no_indices' ,
123
+ 'allow_partial_search_results' ,
124
+ 'analyzer' ,
125
+ 'analyze_wildcard' ,
126
+ 'batched_reduce_size' ,
127
+ 'ccs_minimize_roundtrips' ,
128
+ 'default_operator' ,
129
+ 'df' ,
130
+ 'docvalue_fields' ,
131
+ 'expand_wildcards' ,
132
+ 'explain' ,
133
+ 'ignore_throttled' ,
134
+ 'ignore_unavailable' ,
135
+ 'lenient' ,
136
+ 'max_concurrent_shard_requests' ,
137
+ 'preference' ,
138
+ 'request_cache' ,
139
+ 'routing' ,
140
+ 'search_type' ,
141
+ 'stats' ,
142
+ 'stored_fields' ,
143
+ 'suggest_field' ,
144
+ 'suggest_mode' ,
145
+ 'suggest_size' ,
146
+ 'suggest_text' ,
147
+ 'terminate_after' ,
148
+ 'timeout' ,
149
+ 'track_total_hits' ,
150
+ 'track_scores' ,
151
+ 'typed_keys' ,
152
+ 'rest_total_hits_as_int' ,
153
+ 'version' ,
154
+ '_source' ,
155
+ '_source_excludes' ,
156
+ '_source_includes' ,
157
+ 'seq_no_primary_term' ,
158
+ 'q' ,
159
+ 'size' ,
160
+ 'from' ,
161
+ 'sort'
162
+ ]
163
+ }
164
+ }
44
165
}
45
166
46
167
/**
@@ -51,7 +172,10 @@ export default class AsyncSearch {
51
172
async delete ( this : That , params : T . AsyncSearchDeleteRequest , options ?: TransportRequestOptionsWithMeta ) : Promise < TransportResult < T . AsyncSearchDeleteResponse , unknown > >
52
173
async delete ( this : That , params : T . AsyncSearchDeleteRequest , options ?: TransportRequestOptions ) : Promise < T . AsyncSearchDeleteResponse >
53
174
async delete ( this : That , params : T . AsyncSearchDeleteRequest , options ?: TransportRequestOptions ) : Promise < any > {
54
- const acceptedPath : string [ ] = [ 'id' ]
175
+ const {
176
+ path : acceptedPath
177
+ } = this . acceptedParams [ 'async_search.delete' ]
178
+
55
179
const userQuery = params ?. querystring
56
180
const querystring : Record < string , any > = userQuery != null ? { ...userQuery } : { }
57
181
@@ -93,7 +217,10 @@ export default class AsyncSearch {
93
217
async get < TDocument = unknown , TAggregations = Record < T . AggregateName , T . AggregationsAggregate > > ( this : That , params : T . AsyncSearchGetRequest , options ?: TransportRequestOptionsWithMeta ) : Promise < TransportResult < T . AsyncSearchGetResponse < TDocument , TAggregations > , unknown > >
94
218
async get < TDocument = unknown , TAggregations = Record < T . AggregateName , T . AggregationsAggregate > > ( this : That , params : T . AsyncSearchGetRequest , options ?: TransportRequestOptions ) : Promise < T . AsyncSearchGetResponse < TDocument , TAggregations > >
95
219
async get < TDocument = unknown , TAggregations = Record < T . AggregateName , T . AggregationsAggregate > > ( this : That , params : T . AsyncSearchGetRequest , options ?: TransportRequestOptions ) : Promise < any > {
96
- const acceptedPath : string [ ] = [ 'id' ]
220
+ const {
221
+ path : acceptedPath
222
+ } = this . acceptedParams [ 'async_search.get' ]
223
+
97
224
const userQuery = params ?. querystring
98
225
const querystring : Record < string , any > = userQuery != null ? { ...userQuery } : { }
99
226
@@ -135,7 +262,10 @@ export default class AsyncSearch {
135
262
async status ( this : That , params : T . AsyncSearchStatusRequest , options ?: TransportRequestOptionsWithMeta ) : Promise < TransportResult < T . AsyncSearchStatusResponse , unknown > >
136
263
async status ( this : That , params : T . AsyncSearchStatusRequest , options ?: TransportRequestOptions ) : Promise < T . AsyncSearchStatusResponse >
137
264
async status ( this : That , params : T . AsyncSearchStatusRequest , options ?: TransportRequestOptions ) : Promise < any > {
138
- const acceptedPath : string [ ] = [ 'id' ]
265
+ const {
266
+ path : acceptedPath
267
+ } = this . acceptedParams [ 'async_search.status' ]
268
+
139
269
const userQuery = params ?. querystring
140
270
const querystring : Record < string , any > = userQuery != null ? { ...userQuery } : { }
141
271
@@ -177,8 +307,12 @@ export default class AsyncSearch {
177
307
async submit < TDocument = unknown , TAggregations = Record < T . AggregateName , T . AggregationsAggregate > > ( this : That , params ?: T . AsyncSearchSubmitRequest , options ?: TransportRequestOptionsWithMeta ) : Promise < TransportResult < T . AsyncSearchSubmitResponse < TDocument , TAggregations > , unknown > >
178
308
async submit < TDocument = unknown , TAggregations = Record < T . AggregateName , T . AggregationsAggregate > > ( this : That , params ?: T . AsyncSearchSubmitRequest , options ?: TransportRequestOptions ) : Promise < T . AsyncSearchSubmitResponse < TDocument , TAggregations > >
179
309
async submit < TDocument = unknown , TAggregations = Record < T . AggregateName , T . AggregationsAggregate > > ( this : That , params ?: T . AsyncSearchSubmitRequest , options ?: TransportRequestOptions ) : Promise < any > {
180
- const acceptedPath : string [ ] = [ 'index' ]
181
- const acceptedBody : string [ ] = [ 'aggregations' , 'aggs' , 'collapse' , 'explain' , 'ext' , 'from' , 'highlight' , 'track_total_hits' , 'indices_boost' , 'docvalue_fields' , 'knn' , 'min_score' , 'post_filter' , 'profile' , 'query' , 'rescore' , 'script_fields' , 'search_after' , 'size' , 'slice' , 'sort' , '_source' , 'fields' , 'suggest' , 'terminate_after' , 'timeout' , 'track_scores' , 'version' , 'seq_no_primary_term' , 'stored_fields' , 'pit' , 'runtime_mappings' , 'stats' ]
310
+ const {
311
+ path : acceptedPath ,
312
+ body : acceptedBody ,
313
+ query : acceptedQuery
314
+ } = this . acceptedParams [ 'async_search.submit' ]
315
+
182
316
const userQuery = params ?. querystring
183
317
const querystring : Record < string , any > = userQuery != null ? { ...userQuery } : { }
184
318
@@ -205,8 +339,14 @@ export default class AsyncSearch {
205
339
} else if ( acceptedPath . includes ( key ) ) {
206
340
continue
207
341
} else if ( key !== 'body' && key !== 'querystring' ) {
208
- // @ts -expect-error
209
- querystring [ key ] = params [ key ]
342
+ if ( acceptedQuery . includes ( key ) || commonQueryParams . includes ( key ) ) {
343
+ // @ts -expect-error
344
+ querystring [ key ] = params [ key ]
345
+ } else {
346
+ body = body ?? { }
347
+ // @ts -expect-error
348
+ body [ key ] = params [ key ]
349
+ }
210
350
}
211
351
}
212
352
0 commit comments