Skip to content

Commit 6a86e25

Browse files
Auto-generated code for main (#63)
Auto-generated API code
1 parent 7d20f6d commit 6a86e25

File tree

5 files changed

+200
-10
lines changed

5 files changed

+200
-10
lines changed

docs/reference.asciidoc

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1853,6 +1853,31 @@ client.eql.search({ index, query })
18531853
** *`expand_wildcards` (Optional, Enum("all" | "open" | "closed" | "hidden" | "none") | Enum("all" | "open" | "closed" | "hidden" | "none")[])*
18541854
** *`ignore_unavailable` (Optional, boolean)*: If true, missing or closed indices are not included in the response.
18551855

1856+
[discrete]
1857+
=== esql
1858+
[discrete]
1859+
==== query
1860+
Executes an ESQL request
1861+
1862+
{ref}/esql-rest.html[Endpoint documentation]
1863+
[source,ts]
1864+
----
1865+
client.esql.query({ query })
1866+
----
1867+
1868+
[discrete]
1869+
==== Arguments
1870+
1871+
* *Request (object):*
1872+
** *`query` (string)*: The ES|QL query API accepts an ES|QL query string in the query parameter, runs it, and returns the results.
1873+
** *`columnar` (Optional, boolean)*: By default, ES|QL returns results as rows. For example, FROM returns each individual document as one row. For the JSON, YAML, CBOR and smile formats, ES|QL can return the results in a columnar fashion where one row represents all the values of a certain column in the results.
1874+
** *`filter` (Optional, { bool, boosting, common, constant_score, dis_max, distance_feature, exists, function_score, fuzzy, geo_bounding_box, geo_distance, geo_polygon, geo_shape, has_child, has_parent, ids, intervals, knn, match, match_all, match_bool_prefix, match_none, match_phrase, match_phrase_prefix, more_like_this, multi_match, nested, parent_id, percolate, pinned, prefix, query_string, range, rank_feature, regexp, rule_query, script, script_score, shape, simple_query_string, span_containing, field_masking_span, span_first, span_multi, span_near, span_not, span_or, span_term, span_within, term, terms, terms_set, wildcard, wrapper, type })*: Specify a Query DSL query in the filter parameter to filter the set of documents that an ES|QL query runs on.
1875+
** *`locale` (Optional, string)*
1876+
** *`params` (Optional, number | number | string | boolean | null[])*: To avoid any attempts of hacking or code injection, extract the values in a separate list of parameters. Use question mark placeholders (?) in the query string for each of the parameters.
1877+
** *`version` (Optional, Enum("2024.04.01"))*: The version of the ES|QL language in which the "query" field was written.
1878+
** *`format` (Optional, string)*: A short version of the Accept header, e.g. json, yaml.
1879+
** *`delimiter` (Optional, string)*: The character to use between values within a CSV row. Only valid for the CSV format.
1880+
18561881
[discrete]
18571882
=== graph
18581883
[discrete]

src/api/api/esql.ts

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/*
2+
* Licensed to Elasticsearch B.V. under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch B.V. licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
/* eslint-disable import/export */
21+
/* eslint-disable @typescript-eslint/no-misused-new */
22+
/* eslint-disable @typescript-eslint/no-extraneous-class */
23+
/* eslint-disable @typescript-eslint/no-unused-vars */
24+
25+
// This file was automatically generated by elastic/elastic-client-generator-js
26+
// DO NOT MODIFY IT BY HAND. Instead, modify the source open api file,
27+
// and elastic/elastic-client-generator-js to regenerate this file again.
28+
29+
import {
30+
Transport,
31+
TransportRequestOptions,
32+
TransportRequestOptionsWithMeta,
33+
TransportRequestOptionsWithOutMeta,
34+
TransportResult
35+
} from '@elastic/transport'
36+
import * as T from '../types'
37+
import * as TB from '../typesWithBodyKey'
38+
interface That { transport: Transport }
39+
40+
export default class Esql {
41+
transport: Transport
42+
constructor (transport: Transport) {
43+
this.transport = transport
44+
}
45+
46+
/**
47+
* Executes an ESQL request
48+
* @see {@link https://www.elastic.co/guide/en/elasticsearch/reference/master/esql-rest.html | Elasticsearch API documentation}
49+
*/
50+
async query (this: That, params: T.EsqlQueryRequest | TB.EsqlQueryRequest, options?: TransportRequestOptionsWithOutMeta): Promise<T.EsqlQueryResponse>
51+
async query (this: That, params: T.EsqlQueryRequest | TB.EsqlQueryRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.EsqlQueryResponse, unknown>>
52+
async query (this: That, params: T.EsqlQueryRequest | TB.EsqlQueryRequest, options?: TransportRequestOptions): Promise<T.EsqlQueryResponse>
53+
async query (this: That, params: T.EsqlQueryRequest | TB.EsqlQueryRequest, options?: TransportRequestOptions): Promise<any> {
54+
const acceptedPath: string[] = []
55+
const acceptedBody: string[] = ['columnar', 'filter', 'locale', 'params', 'query', 'version']
56+
const querystring: Record<string, any> = {}
57+
// @ts-expect-error
58+
const userBody: any = params?.body
59+
let body: Record<string, any> | string
60+
if (typeof userBody === 'string') {
61+
body = userBody
62+
} else {
63+
body = userBody != null ? { ...userBody } : undefined
64+
}
65+
66+
// a version number is required for all ES|QL queries.
67+
// inject a default value if none is provided.
68+
if (typeof body === 'object' && body.version == null) {
69+
body.version = '2024.04.01'
70+
}
71+
72+
for (const key in params) {
73+
if (acceptedBody.includes(key)) {
74+
body = body ?? {}
75+
// @ts-expect-error
76+
body[key] = params[key]
77+
} else if (acceptedPath.includes(key)) {
78+
continue
79+
} else if (key !== 'body') {
80+
// @ts-expect-error
81+
querystring[key] = params[key]
82+
}
83+
}
84+
85+
const method = 'POST'
86+
const path = '/_query'
87+
return await this.transport.request({ path, method, querystring, body }, options)
88+
}
89+
}

src/api/index.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import deleteByQueryApi from './api/delete_by_query'
3939
import deleteScriptApi from './api/delete_script'
4040
import EnrichApi from './api/enrich'
4141
import EqlApi from './api/eql'
42+
import EsqlApi from './api/esql'
4243
import existsApi from './api/exists'
4344
import existsSourceApi from './api/exists_source'
4445
import explainApi from './api/explain'
@@ -97,6 +98,7 @@ export default interface API {
9798
deleteScript: typeof deleteScriptApi
9899
enrich: EnrichApi
99100
eql: EqlApi
101+
esql: EsqlApi
100102
exists: typeof existsApi
101103
existsSource: typeof existsSourceApi
102104
explain: typeof explainApi
@@ -146,6 +148,7 @@ const kCat = Symbol('Cat')
146148
const kCluster = Symbol('Cluster')
147149
const kEnrich = Symbol('Enrich')
148150
const kEql = Symbol('Eql')
151+
const kEsql = Symbol('Esql')
149152
const kGraph = Symbol('Graph')
150153
const kIndices = Symbol('Indices')
151154
const kInference = Symbol('Inference')
@@ -167,6 +170,7 @@ export default class API {
167170
[kCluster]: symbol | null
168171
[kEnrich]: symbol | null
169172
[kEql]: symbol | null
173+
[kEsql]: symbol | null
170174
[kGraph]: symbol | null
171175
[kIndices]: symbol | null
172176
[kInference]: symbol | null
@@ -187,6 +191,7 @@ export default class API {
187191
this[kCluster] = null
188192
this[kEnrich] = null
189193
this[kEql] = null
194+
this[kEsql] = null
190195
this[kGraph] = null
191196
this[kIndices] = null
192197
this[kInference] = null
@@ -257,6 +262,9 @@ Object.defineProperties(API.prototype, {
257262
eql: {
258263
get () { return this[kEql] === null ? (this[kEql] = new EqlApi(this.transport)) : this[kEql] }
259264
},
265+
esql: {
266+
get () { return this[kEsql] === null ? (this[kEsql] = new EsqlApi(this.transport)) : this[kEsql] }
267+
},
260268
graph: {
261269
get () { return this[kGraph] === null ? (this[kGraph] = new GraphApi(this.transport)) : this[kGraph] }
262270
},

src/api/types.ts

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -655,8 +655,8 @@ export interface KnnSearchResponse<TDocument = unknown> {
655655
export interface KnnSearchQuery {
656656
field: Field
657657
query_vector: QueryVector
658-
k: long
659-
num_candidates: long
658+
k: integer
659+
num_candidates: integer
660660
}
661661

662662
export interface MgetMultiGetError {
@@ -2278,17 +2278,26 @@ export interface KnnQuery extends QueryDslQueryBase {
22782278
field: Field
22792279
query_vector?: QueryVector
22802280
query_vector_builder?: QueryVectorBuilder
2281-
num_candidates?: long
2281+
num_candidates?: integer
22822282
filter?: QueryDslQueryContainer | QueryDslQueryContainer[]
22832283
similarity?: float
22842284
}
22852285

2286+
export interface KnnRetriever extends RetrieverBase {
2287+
field: string
2288+
query_vector?: QueryVector
2289+
query_vector_builder?: QueryVectorBuilder
2290+
k: integer
2291+
num_candidates: integer
2292+
similarity?: float
2293+
}
2294+
22862295
export interface KnnSearch {
22872296
field: Field
22882297
query_vector?: QueryVector
22892298
query_vector_builder?: QueryVectorBuilder
2290-
k?: long
2291-
num_candidates?: long
2299+
k?: integer
2300+
num_candidates?: integer
22922301
boost?: float
22932302
filter?: QueryDslQueryContainer | QueryDslQueryContainer[]
22942303
similarity?: float
@@ -2426,6 +2435,12 @@ export interface QueryVectorBuilder {
24262435
text_embedding?: TextEmbedding
24272436
}
24282437

2438+
export interface RRFRetriever extends RetrieverBase {
2439+
retrievers: RetrieverContainer[]
2440+
rank_constant?: integer
2441+
rank_window_size?: integer
2442+
}
2443+
24292444
export interface RankBase {
24302445
}
24312446

@@ -2475,6 +2490,16 @@ export interface Retries {
24752490
search: long
24762491
}
24772492

2493+
export interface RetrieverBase {
2494+
filter?: QueryDslQueryContainer | QueryDslQueryContainer[]
2495+
}
2496+
2497+
export interface RetrieverContainer {
2498+
standard?: StandardRetriever
2499+
knn?: KnnRetriever
2500+
rrf?: RRFRetriever
2501+
}
2502+
24782503
export type Routing = string
24792504

24802505
export interface RrfRank {
@@ -2630,6 +2655,15 @@ export type SortOrder = 'asc' | 'desc'
26302655

26312656
export type SortResults = FieldValue[]
26322657

2658+
export interface StandardRetriever extends RetrieverBase {
2659+
query?: QueryDslQueryContainer
2660+
search_after?: SortResults
2661+
terminate_after?: integer
2662+
sort?: Sort
2663+
min_score?: float
2664+
collapse?: SearchFieldCollapse
2665+
}
2666+
26332667
export interface StoreStats {
26342668
size?: ByteSize
26352669
size_in_bytes: long

src/api/typesWithBodyKey.ts

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -680,8 +680,8 @@ export interface KnnSearchResponse<TDocument = unknown> {
680680
export interface KnnSearchQuery {
681681
field: Field
682682
query_vector: QueryVector
683-
k: long
684-
num_candidates: long
683+
k: integer
684+
num_candidates: integer
685685
}
686686

687687
export interface MgetMultiGetError {
@@ -2351,17 +2351,26 @@ export interface KnnQuery extends QueryDslQueryBase {
23512351
field: Field
23522352
query_vector?: QueryVector
23532353
query_vector_builder?: QueryVectorBuilder
2354-
num_candidates?: long
2354+
num_candidates?: integer
23552355
filter?: QueryDslQueryContainer | QueryDslQueryContainer[]
23562356
similarity?: float
23572357
}
23582358

2359+
export interface KnnRetriever extends RetrieverBase {
2360+
field: string
2361+
query_vector?: QueryVector
2362+
query_vector_builder?: QueryVectorBuilder
2363+
k: integer
2364+
num_candidates: integer
2365+
similarity?: float
2366+
}
2367+
23592368
export interface KnnSearch {
23602369
field: Field
23612370
query_vector?: QueryVector
23622371
query_vector_builder?: QueryVectorBuilder
2363-
k?: long
2364-
num_candidates?: long
2372+
k?: integer
2373+
num_candidates?: integer
23652374
boost?: float
23662375
filter?: QueryDslQueryContainer | QueryDslQueryContainer[]
23672376
similarity?: float
@@ -2499,6 +2508,12 @@ export interface QueryVectorBuilder {
24992508
text_embedding?: TextEmbedding
25002509
}
25012510

2511+
export interface RRFRetriever extends RetrieverBase {
2512+
retrievers: RetrieverContainer[]
2513+
rank_constant?: integer
2514+
rank_window_size?: integer
2515+
}
2516+
25022517
export interface RankBase {
25032518
}
25042519

@@ -2548,6 +2563,16 @@ export interface Retries {
25482563
search: long
25492564
}
25502565

2566+
export interface RetrieverBase {
2567+
filter?: QueryDslQueryContainer | QueryDslQueryContainer[]
2568+
}
2569+
2570+
export interface RetrieverContainer {
2571+
standard?: StandardRetriever
2572+
knn?: KnnRetriever
2573+
rrf?: RRFRetriever
2574+
}
2575+
25512576
export type Routing = string
25522577

25532578
export interface RrfRank {
@@ -2703,6 +2728,15 @@ export type SortOrder = 'asc' | 'desc'
27032728

27042729
export type SortResults = FieldValue[]
27052730

2731+
export interface StandardRetriever extends RetrieverBase {
2732+
query?: QueryDslQueryContainer
2733+
search_after?: SortResults
2734+
terminate_after?: integer
2735+
sort?: Sort
2736+
min_score?: float
2737+
collapse?: SearchFieldCollapse
2738+
}
2739+
27062740
export interface StoreStats {
27072741
size?: ByteSize
27082742
size_in_bytes: long

0 commit comments

Comments
 (0)