From 29c9072a4a4d968a08ddb0deb0a65cfad2e6eb82 Mon Sep 17 00:00:00 2001 From: Elastic Machine Date: Sat, 18 May 2024 06:07:46 +0000 Subject: [PATCH] Auto-generated API code --- docs/reference.asciidoc | 25 +++++++++++ src/api/api/esql.ts | 89 +++++++++++++++++++++++++++++++++++++ src/api/index.ts | 8 ++++ src/api/types.ts | 44 +++++++++++++++--- src/api/typesWithBodyKey.ts | 44 +++++++++++++++--- 5 files changed, 200 insertions(+), 10 deletions(-) create mode 100644 src/api/api/esql.ts diff --git a/docs/reference.asciidoc b/docs/reference.asciidoc index a9b9c06..ca28d96 100644 --- a/docs/reference.asciidoc +++ b/docs/reference.asciidoc @@ -1853,6 +1853,31 @@ client.eql.search({ index, query }) ** *`expand_wildcards` (Optional, Enum("all" | "open" | "closed" | "hidden" | "none") | Enum("all" | "open" | "closed" | "hidden" | "none")[])* ** *`ignore_unavailable` (Optional, boolean)*: If true, missing or closed indices are not included in the response. +[discrete] +=== esql +[discrete] +==== query +Executes an ESQL request + +{ref}/esql-rest.html[Endpoint documentation] +[source,ts] +---- +client.esql.query({ query }) +---- + +[discrete] +==== Arguments + +* *Request (object):* +** *`query` (string)*: The ES|QL query API accepts an ES|QL query string in the query parameter, runs it, and returns the results. +** *`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. +** *`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. +** *`locale` (Optional, string)* +** *`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. +** *`version` (Optional, Enum("2024.04.01"))*: The version of the ES|QL language in which the "query" field was written. +** *`format` (Optional, string)*: A short version of the Accept header, e.g. json, yaml. +** *`delimiter` (Optional, string)*: The character to use between values within a CSV row. Only valid for the CSV format. + [discrete] === graph [discrete] diff --git a/src/api/api/esql.ts b/src/api/api/esql.ts new file mode 100644 index 0000000..a4029c1 --- /dev/null +++ b/src/api/api/esql.ts @@ -0,0 +1,89 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/* eslint-disable import/export */ +/* eslint-disable @typescript-eslint/no-misused-new */ +/* eslint-disable @typescript-eslint/no-extraneous-class */ +/* eslint-disable @typescript-eslint/no-unused-vars */ + +// This file was automatically generated by elastic/elastic-client-generator-js +// DO NOT MODIFY IT BY HAND. Instead, modify the source open api file, +// and elastic/elastic-client-generator-js to regenerate this file again. + +import { + Transport, + TransportRequestOptions, + TransportRequestOptionsWithMeta, + TransportRequestOptionsWithOutMeta, + TransportResult +} from '@elastic/transport' +import * as T from '../types' +import * as TB from '../typesWithBodyKey' +interface That { transport: Transport } + +export default class Esql { + transport: Transport + constructor (transport: Transport) { + this.transport = transport + } + + /** + * Executes an ESQL request + * @see {@link https://www.elastic.co/guide/en/elasticsearch/reference/master/esql-rest.html | Elasticsearch API documentation} + */ + async query (this: That, params: T.EsqlQueryRequest | TB.EsqlQueryRequest, options?: TransportRequestOptionsWithOutMeta): Promise + async query (this: That, params: T.EsqlQueryRequest | TB.EsqlQueryRequest, options?: TransportRequestOptionsWithMeta): Promise> + async query (this: That, params: T.EsqlQueryRequest | TB.EsqlQueryRequest, options?: TransportRequestOptions): Promise + async query (this: That, params: T.EsqlQueryRequest | TB.EsqlQueryRequest, options?: TransportRequestOptions): Promise { + const acceptedPath: string[] = [] + const acceptedBody: string[] = ['columnar', 'filter', 'locale', 'params', 'query', 'version'] + const querystring: Record = {} + // @ts-expect-error + const userBody: any = params?.body + let body: Record | string + if (typeof userBody === 'string') { + body = userBody + } else { + body = userBody != null ? { ...userBody } : undefined + } + + // a version number is required for all ES|QL queries. + // inject a default value if none is provided. + if (typeof body === 'object' && body.version == null) { + body.version = '2024.04.01' + } + + for (const key in params) { + if (acceptedBody.includes(key)) { + body = body ?? {} + // @ts-expect-error + body[key] = params[key] + } else if (acceptedPath.includes(key)) { + continue + } else if (key !== 'body') { + // @ts-expect-error + querystring[key] = params[key] + } + } + + const method = 'POST' + const path = '/_query' + return await this.transport.request({ path, method, querystring, body }, options) + } +} diff --git a/src/api/index.ts b/src/api/index.ts index 47a0e9d..0579c25 100644 --- a/src/api/index.ts +++ b/src/api/index.ts @@ -39,6 +39,7 @@ import deleteByQueryApi from './api/delete_by_query' import deleteScriptApi from './api/delete_script' import EnrichApi from './api/enrich' import EqlApi from './api/eql' +import EsqlApi from './api/esql' import existsApi from './api/exists' import existsSourceApi from './api/exists_source' import explainApi from './api/explain' @@ -97,6 +98,7 @@ export default interface API { deleteScript: typeof deleteScriptApi enrich: EnrichApi eql: EqlApi + esql: EsqlApi exists: typeof existsApi existsSource: typeof existsSourceApi explain: typeof explainApi @@ -146,6 +148,7 @@ const kCat = Symbol('Cat') const kCluster = Symbol('Cluster') const kEnrich = Symbol('Enrich') const kEql = Symbol('Eql') +const kEsql = Symbol('Esql') const kGraph = Symbol('Graph') const kIndices = Symbol('Indices') const kInference = Symbol('Inference') @@ -167,6 +170,7 @@ export default class API { [kCluster]: symbol | null [kEnrich]: symbol | null [kEql]: symbol | null + [kEsql]: symbol | null [kGraph]: symbol | null [kIndices]: symbol | null [kInference]: symbol | null @@ -187,6 +191,7 @@ export default class API { this[kCluster] = null this[kEnrich] = null this[kEql] = null + this[kEsql] = null this[kGraph] = null this[kIndices] = null this[kInference] = null @@ -257,6 +262,9 @@ Object.defineProperties(API.prototype, { eql: { get () { return this[kEql] === null ? (this[kEql] = new EqlApi(this.transport)) : this[kEql] } }, + esql: { + get () { return this[kEsql] === null ? (this[kEsql] = new EsqlApi(this.transport)) : this[kEsql] } + }, graph: { get () { return this[kGraph] === null ? (this[kGraph] = new GraphApi(this.transport)) : this[kGraph] } }, diff --git a/src/api/types.ts b/src/api/types.ts index 0d1d292..6483c16 100644 --- a/src/api/types.ts +++ b/src/api/types.ts @@ -655,8 +655,8 @@ export interface KnnSearchResponse { export interface KnnSearchQuery { field: Field query_vector: QueryVector - k: long - num_candidates: long + k: integer + num_candidates: integer } export interface MgetMultiGetError { @@ -2278,17 +2278,26 @@ export interface KnnQuery extends QueryDslQueryBase { field: Field query_vector?: QueryVector query_vector_builder?: QueryVectorBuilder - num_candidates?: long + num_candidates?: integer filter?: QueryDslQueryContainer | QueryDslQueryContainer[] similarity?: float } +export interface KnnRetriever extends RetrieverBase { + field: string + query_vector?: QueryVector + query_vector_builder?: QueryVectorBuilder + k: integer + num_candidates: integer + similarity?: float +} + export interface KnnSearch { field: Field query_vector?: QueryVector query_vector_builder?: QueryVectorBuilder - k?: long - num_candidates?: long + k?: integer + num_candidates?: integer boost?: float filter?: QueryDslQueryContainer | QueryDslQueryContainer[] similarity?: float @@ -2426,6 +2435,12 @@ export interface QueryVectorBuilder { text_embedding?: TextEmbedding } +export interface RRFRetriever extends RetrieverBase { + retrievers: RetrieverContainer[] + rank_constant?: integer + rank_window_size?: integer +} + export interface RankBase { } @@ -2475,6 +2490,16 @@ export interface Retries { search: long } +export interface RetrieverBase { + filter?: QueryDslQueryContainer | QueryDslQueryContainer[] +} + +export interface RetrieverContainer { + standard?: StandardRetriever + knn?: KnnRetriever + rrf?: RRFRetriever +} + export type Routing = string export interface RrfRank { @@ -2630,6 +2655,15 @@ export type SortOrder = 'asc' | 'desc' export type SortResults = FieldValue[] +export interface StandardRetriever extends RetrieverBase { + query?: QueryDslQueryContainer + search_after?: SortResults + terminate_after?: integer + sort?: Sort + min_score?: float + collapse?: SearchFieldCollapse +} + export interface StoreStats { size?: ByteSize size_in_bytes: long diff --git a/src/api/typesWithBodyKey.ts b/src/api/typesWithBodyKey.ts index 64146d0..a887731 100644 --- a/src/api/typesWithBodyKey.ts +++ b/src/api/typesWithBodyKey.ts @@ -680,8 +680,8 @@ export interface KnnSearchResponse { export interface KnnSearchQuery { field: Field query_vector: QueryVector - k: long - num_candidates: long + k: integer + num_candidates: integer } export interface MgetMultiGetError { @@ -2351,17 +2351,26 @@ export interface KnnQuery extends QueryDslQueryBase { field: Field query_vector?: QueryVector query_vector_builder?: QueryVectorBuilder - num_candidates?: long + num_candidates?: integer filter?: QueryDslQueryContainer | QueryDslQueryContainer[] similarity?: float } +export interface KnnRetriever extends RetrieverBase { + field: string + query_vector?: QueryVector + query_vector_builder?: QueryVectorBuilder + k: integer + num_candidates: integer + similarity?: float +} + export interface KnnSearch { field: Field query_vector?: QueryVector query_vector_builder?: QueryVectorBuilder - k?: long - num_candidates?: long + k?: integer + num_candidates?: integer boost?: float filter?: QueryDslQueryContainer | QueryDslQueryContainer[] similarity?: float @@ -2499,6 +2508,12 @@ export interface QueryVectorBuilder { text_embedding?: TextEmbedding } +export interface RRFRetriever extends RetrieverBase { + retrievers: RetrieverContainer[] + rank_constant?: integer + rank_window_size?: integer +} + export interface RankBase { } @@ -2548,6 +2563,16 @@ export interface Retries { search: long } +export interface RetrieverBase { + filter?: QueryDslQueryContainer | QueryDslQueryContainer[] +} + +export interface RetrieverContainer { + standard?: StandardRetriever + knn?: KnnRetriever + rrf?: RRFRetriever +} + export type Routing = string export interface RrfRank { @@ -2703,6 +2728,15 @@ export type SortOrder = 'asc' | 'desc' export type SortResults = FieldValue[] +export interface StandardRetriever extends RetrieverBase { + query?: QueryDslQueryContainer + search_after?: SortResults + terminate_after?: integer + sort?: Sort + min_score?: float + collapse?: SearchFieldCollapse +} + export interface StoreStats { size?: ByteSize size_in_bytes: long