Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions docs/reference.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
89 changes: 89 additions & 0 deletions src/api/api/esql.ts
Original file line number Diff line number Diff line change
@@ -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<T.EsqlQueryResponse>
async query (this: That, params: T.EsqlQueryRequest | TB.EsqlQueryRequest, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<T.EsqlQueryResponse, unknown>>
async query (this: That, params: T.EsqlQueryRequest | TB.EsqlQueryRequest, options?: TransportRequestOptions): Promise<T.EsqlQueryResponse>
async query (this: That, params: T.EsqlQueryRequest | TB.EsqlQueryRequest, options?: TransportRequestOptions): Promise<any> {
const acceptedPath: string[] = []
const acceptedBody: string[] = ['columnar', 'filter', 'locale', 'params', 'query', 'version']
const querystring: Record<string, any> = {}
// @ts-expect-error
const userBody: any = params?.body
let body: Record<string, any> | 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)
}
}
8 changes: 8 additions & 0 deletions src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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')
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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] }
},
Expand Down
44 changes: 39 additions & 5 deletions src/api/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -655,8 +655,8 @@ export interface KnnSearchResponse<TDocument = unknown> {
export interface KnnSearchQuery {
field: Field
query_vector: QueryVector
k: long
num_candidates: long
k: integer
num_candidates: integer
}

export interface MgetMultiGetError {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
}

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
44 changes: 39 additions & 5 deletions src/api/typesWithBodyKey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -680,8 +680,8 @@ export interface KnnSearchResponse<TDocument = unknown> {
export interface KnnSearchQuery {
field: Field
query_vector: QueryVector
k: long
num_candidates: long
k: integer
num_candidates: integer
}

export interface MgetMultiGetError {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
}

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down