Skip to content

Add ES|QL API #67

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 24, 2024
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
7 changes: 7 additions & 0 deletions docs/sphinx/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ Enrich Policies
Event Query Language (EQL)
--------------------------

.. autoclass:: EqlClient
:members:


ES|QL
-----

.. autoclass:: EqlClient
:members:

Expand Down
2 changes: 2 additions & 0 deletions elasticsearch_serverless/_async/client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
from .cluster import ClusterClient
from .enrich import EnrichClient
from .eql import EqlClient
from .esql import EsqlClient
from .graph import GraphClient
from .indices import IndicesClient
from .inference import InferenceClient
Expand Down Expand Up @@ -286,6 +287,7 @@ def __init__(

self.enrich = EnrichClient(self)
self.eql = EqlClient(self)
self.esql = EsqlClient(self)
self.graph = GraphClient(self)
self.license = LicenseClient(self)
self.logstash = LogstashClient(self)
Expand Down
100 changes: 100 additions & 0 deletions elasticsearch_serverless/_async/client/esql.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
# 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.

import typing as t

from elastic_transport import ObjectApiResponse

from ._base import NamespacedClient
from .utils import _rewrite_parameters


class EsqlClient(NamespacedClient):

@_rewrite_parameters(
body_fields=("query", "columnar", "filter", "locale", "params"),
ignore_deprecated_options={"params"},
)
async def query(
self,
*,
query: t.Optional[str] = None,
columnar: t.Optional[bool] = None,
delimiter: t.Optional[str] = None,
error_trace: t.Optional[bool] = None,
filter: t.Optional[t.Mapping[str, t.Any]] = None,
filter_path: t.Optional[t.Union[str, t.Sequence[str]]] = None,
format: t.Optional[str] = None,
human: t.Optional[bool] = None,
locale: t.Optional[str] = None,
params: t.Optional[t.Sequence[t.Union[None, bool, float, int, str]]] = None,
pretty: t.Optional[bool] = None,
body: t.Optional[t.Dict[str, t.Any]] = None,
) -> ObjectApiResponse[t.Any]:
"""
Executes an ES|QL request

`<https://www.elastic.co/guide/en/elasticsearch/reference/master/esql-rest.html>`_

:param query: The ES|QL query API accepts an ES|QL query string in the query
parameter, runs it, and returns the results.
:param columnar: 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.
:param delimiter: The character to use between values within a CSV row. Only
valid for the CSV format.
:param filter: Specify a Query DSL query in the filter parameter to filter the
set of documents that an ES|QL query runs on.
:param format: A short version of the Accept header, e.g. json, yaml.
:param locale:
:param params: 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.
"""
if query is None and body is None:
raise ValueError("Empty value passed for parameter 'query'")
__path = "/_query"
__query: t.Dict[str, t.Any] = {}
__body: t.Dict[str, t.Any] = body if body is not None else {}
if delimiter is not None:
__query["delimiter"] = delimiter
if error_trace is not None:
__query["error_trace"] = error_trace
if filter_path is not None:
__query["filter_path"] = filter_path
if format is not None:
__query["format"] = format
if human is not None:
__query["human"] = human
if pretty is not None:
__query["pretty"] = pretty
if not __body:
if query is not None:
__body["query"] = query
if columnar is not None:
__body["columnar"] = columnar
if filter is not None:
__body["filter"] = filter
if locale is not None:
__body["locale"] = locale
if params is not None:
__body["params"] = params
__headers = {"accept": "application/json", "content-type": "application/json"}
return await self.perform_request( # type: ignore[return-value]
"POST", __path, params=__query, headers=__headers, body=__body
)
2 changes: 2 additions & 0 deletions elasticsearch_serverless/_sync/client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
from .cluster import ClusterClient
from .enrich import EnrichClient
from .eql import EqlClient
from .esql import EsqlClient
from .graph import GraphClient
from .indices import IndicesClient
from .inference import InferenceClient
Expand Down Expand Up @@ -286,6 +287,7 @@ def __init__(

self.enrich = EnrichClient(self)
self.eql = EqlClient(self)
self.esql = EsqlClient(self)
self.graph = GraphClient(self)
self.license = LicenseClient(self)
self.logstash = LogstashClient(self)
Expand Down
100 changes: 100 additions & 0 deletions elasticsearch_serverless/_sync/client/esql.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
# 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.

import typing as t

from elastic_transport import ObjectApiResponse

from ._base import NamespacedClient
from .utils import _rewrite_parameters


class EsqlClient(NamespacedClient):

@_rewrite_parameters(
body_fields=("query", "columnar", "filter", "locale", "params"),
ignore_deprecated_options={"params"},
)
def query(
self,
*,
query: t.Optional[str] = None,
columnar: t.Optional[bool] = None,
delimiter: t.Optional[str] = None,
error_trace: t.Optional[bool] = None,
filter: t.Optional[t.Mapping[str, t.Any]] = None,
filter_path: t.Optional[t.Union[str, t.Sequence[str]]] = None,
format: t.Optional[str] = None,
human: t.Optional[bool] = None,
locale: t.Optional[str] = None,
params: t.Optional[t.Sequence[t.Union[None, bool, float, int, str]]] = None,
pretty: t.Optional[bool] = None,
body: t.Optional[t.Dict[str, t.Any]] = None,
) -> ObjectApiResponse[t.Any]:
"""
Executes an ES|QL request

`<https://www.elastic.co/guide/en/elasticsearch/reference/master/esql-rest.html>`_

:param query: The ES|QL query API accepts an ES|QL query string in the query
parameter, runs it, and returns the results.
:param columnar: 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.
:param delimiter: The character to use between values within a CSV row. Only
valid for the CSV format.
:param filter: Specify a Query DSL query in the filter parameter to filter the
set of documents that an ES|QL query runs on.
:param format: A short version of the Accept header, e.g. json, yaml.
:param locale:
:param params: 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.
"""
if query is None and body is None:
raise ValueError("Empty value passed for parameter 'query'")
__path = "/_query"
__query: t.Dict[str, t.Any] = {}
__body: t.Dict[str, t.Any] = body if body is not None else {}
if delimiter is not None:
__query["delimiter"] = delimiter
if error_trace is not None:
__query["error_trace"] = error_trace
if filter_path is not None:
__query["filter_path"] = filter_path
if format is not None:
__query["format"] = format
if human is not None:
__query["human"] = human
if pretty is not None:
__query["pretty"] = pretty
if not __body:
if query is not None:
__body["query"] = query
if columnar is not None:
__body["columnar"] = columnar
if filter is not None:
__body["filter"] = filter
if locale is not None:
__body["locale"] = locale
if params is not None:
__body["params"] = params
__headers = {"accept": "application/json", "content-type": "application/json"}
return self.perform_request( # type: ignore[return-value]
"POST", __path, params=__query, headers=__headers, body=__body
)
1 change: 1 addition & 0 deletions elasticsearch_serverless/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from ._sync.client.cluster import ClusterClient as ClusterClient # noqa: F401
from ._sync.client.enrich import EnrichClient as EnrichClient # noqa: F401
from ._sync.client.eql import EqlClient as EqlClient # noqa: F401
from ._sync.client.esql import EsqlClient as EsqlClient # noqa: F401
from ._sync.client.graph import GraphClient as GraphClient # noqa: F401
from ._sync.client.indices import IndicesClient as IndicesClient # noqa: F401
from ._sync.client.inference import InferenceClient as InferenceClient # noqa: F401
Expand Down
Loading