Skip to content

Commit

Permalink
Updated opensearch-py to reflect the latest OpenSearch API spec (2024…
Browse files Browse the repository at this point in the history
…-01-30)
  • Loading branch information
web-flow committed Jan 30, 2024
1 parent 455b903 commit d8fd622
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 12 deletions.
3 changes: 1 addition & 2 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def format(session: Any) -> None:
session.run("black", *SOURCE_FILES)
session.run("python", "utils/license_headers.py", "fix", *SOURCE_FILES)

#session.notify("lint")
# session.notify("lint")


@nox.session(python=["3.7"]) # type: ignore
Expand Down Expand Up @@ -147,4 +147,3 @@ def generate(session: Any) -> None:
session.install("-rdev-requirements.txt")
session.run("python", "utils/generate_api.py")
session.notify("format")

5 changes: 1 addition & 4 deletions opensearchpy/_async/client/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -530,10 +530,7 @@ async def delete_decommission_awareness(
"""
return await self.transport.perform_request(
"DELETE",
"/_cluster/decommission/awareness/",
params=params,
headers=headers,
"DELETE", "/_cluster/decommission/awareness", params=params, headers=headers
)

@query_params()
Expand Down
2 changes: 1 addition & 1 deletion opensearchpy/_async/client/security.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ async def get_action_groups(
"""
return await self.transport.perform_request(
"GET",
"/_plugins/_security/api/actiongroups/",
"/_plugins/_security/api/actiongroups",
params=params,
headers=headers,
)
Expand Down
66 changes: 66 additions & 0 deletions opensearchpy/client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,72 @@ def create(
"PUT", path, params=params, headers=headers, body=body
)

@query_params(
"if_primary_term",
"if_seq_no",
"op_type",
"pipeline",
"refresh",
"require_alias",
"routing",
"timeout",
"version",
"version_type",
"wait_for_active_shards",
)
def index(
self,
index: Any,
body: Any,
id: Any = None,
params: Any = None,
headers: Any = None,
) -> Any:
"""
Creates or updates a document in an index.
:arg index: Index name.
:arg body: The document
:arg id: Document ID.
:arg if_primary_term: only perform the operation if the last
operation that has changed the document has the specified primary term.
:arg if_seq_no: only perform the operation if the last operation
that has changed the document has the specified sequence number.
:arg op_type: Explicit operation type. Defaults to `index` for
requests with an explicit document ID, and to `create` for requests
without an explicit document ID. Valid choices are index, create.
:arg pipeline: The pipeline id to preprocess incoming documents
with.
:arg refresh: If `true` then refresh the affected shards to make
this operation visible to search, if `wait_for` then wait for a refresh
to make this operation visible to search, if `false` (the default) then
do nothing with refreshes. Valid choices are true, false, wait_for.
:arg require_alias: When true, requires destination to be an
alias. Default is false.
:arg routing: Routing value.
:arg timeout: Operation timeout.
:arg version: Explicit version number for concurrency control.
:arg version_type: Specific version type. Valid choices are
internal, external, external_gte, force.
:arg wait_for_active_shards: Sets the number of shard copies
that must be active before proceeding with the operation. Defaults to 1,
meaning the primary shard only. Set to `all` for all shard copies,
otherwise set to any non-negative value less than or equal to the total
number of copies for the shard (number of replicas + 1). Default is 1.
"""
for param in (index, body):
if param in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument.")

return self.transport.perform_request(
"POST" if id in SKIP_IN_PATH else "PUT",
_make_path(index, "_doc", id),
params=params,
headers=headers,
body=body,
)

@query_params(
"_source",
"_source_excludes",
Expand Down
5 changes: 1 addition & 4 deletions opensearchpy/client/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -530,10 +530,7 @@ def delete_decommission_awareness(
"""
return self.transport.perform_request(
"DELETE",
"/_cluster/decommission/awareness/",
params=params,
headers=headers,
"DELETE", "/_cluster/decommission/awareness", params=params, headers=headers
)

@query_params()
Expand Down
2 changes: 1 addition & 1 deletion opensearchpy/client/security.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def get_action_groups(
"""
return self.transport.perform_request(
"GET",
"/_plugins/_security/api/actiongroups/",
"/_plugins/_security/api/actiongroups",
params=params,
headers=headers,
)
Expand Down

0 comments on commit d8fd622

Please sign in to comment.