DataViewsClient¶
Client for the Kibana Data Views API.
Data views (formerly index patterns) tell Kibana which Elasticsearch indices, data streams, and aliases to query. This client covers the full Kibana 9.4 data views surface: data view CRUD, field metadata updates, runtime field management, the default data view, and saved object reference swapping.
All operations are space-aware: pass space_id to target a specific Kibana
space, or use client.space("my-space").data_views.
- class kibana._sync.client.data_views.DataViewsClient(client, default_space_id=None, validate_spaces=True)[source]¶
Bases:
NamespaceClientClient for the Kibana Data Views API.
Data views (formerly index patterns) tell Kibana which Elasticsearch indices, data streams, and aliases to query. This client covers the full Kibana 9.4.3 data views surface: data view CRUD, field metadata updates, runtime field management, the default data view, and saved object reference swapping.
All operations are space-aware: pass
space_idto target a specific Kibana space, or useclient.space("my-space").data_views.Example
>>> from kibana import Kibana >>> client = Kibana("http://localhost:5601", api_key="...") >>> >>> # Create a data view over an index >>> response = client.data_views.create( ... data_view={ ... "title": "my-logs-*", ... "name": "My Logs", ... "timeFieldName": "@timestamp", ... } ... ) >>> view_id = response["data_view"]["id"] >>> >>> # Add a runtime field >>> client.data_views.create_runtime_field( ... view_id=view_id, ... name="hour_of_day", ... runtime_field={ ... "type": "long", ... "script": { ... "source": "emit(doc['@timestamp'].value.getHour())" ... }, ... }, ... )
Creating Data Views
Create a data view with the
create()method:from kibana import Kibana client = Kibana("http://localhost:5601", api_key="your_api_key") # Create a data view over an index pattern response = client.data_views.create( data_view={ "title": "my-logs-*", "name": "My Logs", "timeFieldName": "@timestamp", } ) view_id = response["data_view"]["id"] print(f"Created data view: {view_id}")
Retrieving Data Views
# List all data views views = client.data_views.get_all() for view in views.body["data_view"]: print(view["id"], view.get("name") or view["title"]) # Get a single data view view = client.data_views.get(view_id=view_id) print(view.body["data_view"]["title"])
Runtime Fields
Manage runtime fields on a data view:
# Add a runtime field client.data_views.create_runtime_field( view_id=view_id, name="hour_of_day", runtime_field={ "type": "long", "script": { "source": "emit(doc['@timestamp'].value.getHour())" }, }, ) # Read it back field = client.data_views.get_runtime_field( view_id=view_id, name="hour_of_day" ) # Update or delete it client.data_views.update_runtime_field( view_id=view_id, name="hour_of_day", runtime_field={ "script": { "source": "emit(doc['@timestamp'].value.getHour() + 1)" } }, ) client.data_views.delete_runtime_field( view_id=view_id, name="hour_of_day" )
Default Data View
# Get the current default data view ID default = client.data_views.get_default() print(default.body["data_view_id"]) # Set the default data view client.data_views.set_default(data_view_id=view_id)
Deleting Data Views
client.data_views.delete(view_id=view_id)
Warning
Deleting a data view is a permanent operation and cannot be undone.
- get_all(*, space_id=None, validate_spaces=None)[source]¶
Get all data views.
Retrieves a list of all data views in the space, with their identifiers, titles, names, and namespaces.
- Parameters:
- Returns:
Response with a
data_viewarray of data view summaries.- Raises:
AuthenticationException – If authentication fails.
AuthorizationException – If insufficient privileges.
- Return type:
Example
>>> response = client.data_views.get_all() >>> for view in response["data_view"]: ... print(view["id"], view["title"])
- create(*, data_view, override=None, space_id=None, validate_spaces=None)[source]¶
Create a data view.
- Parameters:
data_view (dict[str, Any]) – The data view object. Requires
title(a comma-separated list of data streams, indices, and aliases to search). Optional keys includeid,name,timeFieldName,allowNoIndex,fieldAttrs,fieldFormats,namespaces,runtimeFieldMap,sourceFilters,type,typeMeta, andversion.override (bool | None) – Override an existing data view if one with the provided title already exists. Defaults to false.
space_id (str | None) – Optional space ID to scope the operation to.
validate_spaces (bool | None) – Override space-existence validation for this call.
- Returns:
Response with the created
data_viewobject.- Raises:
ValueError – If
data_viewis missing.BadRequestError – If the data view definition is invalid or a data view with the same title exists and
overrideis not set.
- Return type:
Example
>>> response = client.data_views.create( ... data_view={ ... "title": "my-logs-*", ... "timeFieldName": "@timestamp", ... } ... ) >>> print(response["data_view"]["id"])
- get(*, view_id, space_id=None, validate_spaces=None)[source]¶
Get a data view.
- Parameters:
- Returns:
Response with the full
data_viewobject, including fields.- Raises:
ValueError – If
view_idis missing.NotFoundError – If the data view does not exist.
- Return type:
Example
>>> response = client.data_views.get(view_id="my-view-id") >>> print(response["data_view"]["title"])
- update(*, view_id, data_view, refresh_fields=None, space_id=None, validate_spaces=None)[source]¶
Update a data view.
Only the properties present in
data_vieware updated; all other properties keep their current values.- Parameters:
view_id (str) – The data view identifier.
data_view (dict[str, Any]) – The data view properties to update, e.g.
title,name,timeFieldName,allowNoIndex,fieldFormats,runtimeFieldMap,sourceFilters,type, ortypeMeta.refresh_fields (bool | None) – Reload the data view fields after the update. Defaults to false.
space_id (str | None) – Optional space ID to scope the operation to.
validate_spaces (bool | None) – Override space-existence validation for this call.
- Returns:
Response with the updated
data_viewobject.- Raises:
ValueError – If
view_idordata_viewis missing.NotFoundError – If the data view does not exist.
BadRequestError – If the update payload is invalid.
- Return type:
Example
>>> client.data_views.update( ... view_id="my-view-id", ... data_view={"name": "Renamed view"}, ... refresh_fields=True, ... )
- delete(*, view_id, space_id=None, validate_spaces=None)[source]¶
Delete a data view.
WARNING: When you delete a data view, it cannot be recovered.
- Parameters:
- Returns:
Empty response on success.
- Raises:
ValueError – If
view_idis missing.NotFoundError – If the data view does not exist.
- Return type:
Example
>>> client.data_views.delete(view_id="my-view-id")
- update_fields_metadata(*, view_id, fields, space_id=None, validate_spaces=None)[source]¶
Update data view fields metadata.
Updates presentation metadata for fields, such as
count,customLabel,customDescription, andformat.- Parameters:
fields (dict[str, Any]) – Map of field names to the metadata to set, e.g.
{"my_field": {"customLabel": "My label", "count": 5}}.view_id (str) – The data view identifier.
space_id (str | None) – Optional space ID to scope the operation to.
validate_spaces (bool | None) – Override space-existence validation for this call.
- Returns:
Response with the updated
data_viewobject.- Raises:
ValueError – If
view_idorfieldsis missing.NotFoundError – If the data view does not exist.
BadRequestError – If the fields payload is invalid.
- Return type:
Example
>>> client.data_views.update_fields_metadata( ... view_id="my-view-id", ... fields={"response_code": {"customLabel": "Status"}}, ... )
- create_runtime_field(*, view_id, name, runtime_field, space_id=None, validate_spaces=None)[source]¶
Create a runtime field.
Fails if a runtime field with the same name already exists; use
create_or_update_runtime_field()for upsert semantics.- Parameters:
view_id (str) – The data view identifier.
name (str) – The name for the new runtime field.
runtime_field (dict[str, Any]) – The runtime field definition object, e.g.
{"type": "keyword", "script": {"source": "emit('a')"}}.space_id (str | None) – Optional space ID to scope the operation to.
validate_spaces (bool | None) – Override space-existence validation for this call.
- Returns:
Response with the created runtime
fieldsand the updateddata_viewobject.- Raises:
ValueError – If a required parameter is missing.
NotFoundError – If the data view does not exist.
BadRequestError – If the field already exists or the definition is invalid.
- Return type:
Example
>>> client.data_views.create_runtime_field( ... view_id="my-view-id", ... name="hour_of_day", ... runtime_field={ ... "type": "long", ... "script": { ... "source": "emit(doc['@timestamp'].value.getHour())" ... }, ... }, ... )
- create_or_update_runtime_field(*, view_id, name, runtime_field, space_id=None, validate_spaces=None)[source]¶
Create or update a runtime field.
Upsert semantics: creates the runtime field if it does not exist, or replaces its definition if it does.
- Parameters:
view_id (str) – The data view identifier.
name (str) – The name for the runtime field.
runtime_field (dict[str, Any]) – The runtime field definition object, e.g.
{"type": "keyword", "script": {"source": "emit('a')"}}.space_id (str | None) – Optional space ID to scope the operation to.
validate_spaces (bool | None) – Override space-existence validation for this call.
- Returns:
Response with the runtime
fieldsand the updateddata_viewobject.- Raises:
ValueError – If a required parameter is missing.
NotFoundError – If the data view does not exist.
BadRequestError – If the field definition is invalid.
- Return type:
Example
>>> client.data_views.create_or_update_runtime_field( ... view_id="my-view-id", ... name="hour_of_day", ... runtime_field={ ... "type": "long", ... "script": { ... "source": "emit(doc['@timestamp'].value.getHour())" ... }, ... }, ... )
- get_runtime_field(*, view_id, name, space_id=None, validate_spaces=None)[source]¶
Get a runtime field.
- Parameters:
- Returns:
Response with the runtime
fieldsand the owningdata_viewobject.- Raises:
ValueError – If
view_idornameis missing.NotFoundError – If the data view or runtime field does not exist.
- Return type:
Example
>>> response = client.data_views.get_runtime_field( ... view_id="my-view-id", name="hour_of_day" ... ) >>> print(response["fields"][0]["runtimeField"]["type"])
- update_runtime_field(*, view_id, name, runtime_field, space_id=None, validate_spaces=None)[source]¶
Update a runtime field.
Updates an existing runtime field definition. You can update the
typeandscriptof the runtime field.- Parameters:
view_id (str) – The data view identifier.
name (str) – The name of the runtime field to update.
runtime_field (dict[str, Any]) – The runtime field properties to update, e.g.
{"script": {"source": "emit('b')"}}.space_id (str | None) – Optional space ID to scope the operation to.
validate_spaces (bool | None) – Override space-existence validation for this call.
- Returns:
Response with the runtime
fieldsand the updateddata_viewobject.- Raises:
ValueError – If a required parameter is missing.
NotFoundError – If the data view or runtime field does not exist.
BadRequestError – If the field definition is invalid.
- Return type:
Example
>>> client.data_views.update_runtime_field( ... view_id="my-view-id", ... name="hour_of_day", ... runtime_field={"script": {"source": "emit(0)"}}, ... )
- delete_runtime_field(*, view_id, name, space_id=None, validate_spaces=None)[source]¶
Delete a runtime field from a data view.
- Parameters:
- Returns:
Empty response on success.
- Raises:
ValueError – If
view_idornameis missing.NotFoundError – If the data view or runtime field does not exist.
- Return type:
Example
>>> client.data_views.delete_runtime_field( ... view_id="my-view-id", name="hour_of_day" ... )
- get_default(*, space_id=None, validate_spaces=None)[source]¶
Get the default data view.
- Parameters:
- Returns:
Response with the default
data_view_id(an empty string when no default data view is set).- Raises:
AuthenticationException – If authentication fails.
AuthorizationException – If insufficient privileges.
- Return type:
Example
>>> response = client.data_views.get_default() >>> print(response["data_view_id"])
- set_default(*, data_view_id, force=None, space_id=None, validate_spaces=None)[source]¶
Set the default data view.
- Parameters:
data_view_id (str | None) – The data view identifier to set as default. NOTE: The API does not validate whether it is a valid identifier. Use
Noneto unset the default data view.force (bool | None) – Update the default even when one is already set. Defaults to false.
space_id (str | None) – Optional space ID to scope the operation to.
validate_spaces (bool | None) – Override space-existence validation for this call.
- Returns:
Response with
acknowledged: trueon success.- Raises:
BadRequestError – If the request payload is invalid.
- Return type:
Example
>>> client.data_views.set_default( ... data_view_id="my-view-id", force=True ... )
- swap_references(*, from_id, to_id, from_type=None, for_id=None, for_type=None, delete=None, space_id=None, validate_spaces=None)[source]¶
Swap saved object references.
Changes saved object references from one data view identifier to another. WARNING: Misuse can break large numbers of saved objects. Practicing with a backup is recommended; use
preview_swap_references()to dry-run the operation first.- Parameters:
from_id (str) – The saved object reference to change.
to_id (str) – New saved object reference value to replace the old value.
from_type (str | None) – The type of the saved object reference to alter. Defaults to
index-pattern(data views).for_id (str | list[str] | None) – Limit the affected saved objects to one or more by identifier (a single ID or a list of IDs).
for_type (str | None) – Limit the affected saved objects by type.
delete (bool | None) – Delete the referenced saved object (
from_id) if all its references are removed. Defaults to false.space_id (str | None) – Optional space ID to scope the operation to.
validate_spaces (bool | None) – Override space-existence validation for this call.
- Returns:
Response with a
resultarray of the changed saved objects and, whendeleteis used, adeleteStatusobject.- Raises:
ValueError – If
from_idorto_idis missing.BadRequestError – If the request payload is invalid.
- Return type:
Example
>>> response = client.data_views.swap_references( ... from_id="old-view-id", ... to_id="new-view-id", ... delete=True, ... ) >>> print(response["deleteStatus"]["deletePerformed"])
- preview_swap_references(*, from_id, to_id, from_type=None, for_id=None, for_type=None, delete=None, space_id=None, validate_spaces=None)[source]¶
Preview a saved object reference swap.
Dry-runs
swap_references()and reports which saved objects would be changed, without modifying anything.- Parameters:
from_id (str) – The saved object reference to change.
to_id (str) – New saved object reference value to replace the old value.
from_type (str | None) – The type of the saved object reference to alter. Defaults to
index-pattern(data views).for_id (str | list[str] | None) – Limit the affected saved objects to one or more by identifier (a single ID or a list of IDs).
for_type (str | None) – Limit the affected saved objects by type.
delete (bool | None) – Whether the swap would delete the referenced saved object once all its references are removed.
space_id (str | None) – Optional space ID to scope the operation to.
validate_spaces (bool | None) – Override space-existence validation for this call.
- Returns:
Response with a
resultarray of the saved objects that would be changed.- Raises:
ValueError – If
from_idorto_idis missing.BadRequestError – If the request payload is invalid.
- Return type:
Example
>>> response = client.data_views.preview_swap_references( ... from_id="old-view-id", to_id="new-view-id" ... ) >>> print(response["result"])
- __init__(client, default_space_id=None, validate_spaces=True)¶
Initialize NamespaceClient with optional space support.
AsyncDataViewsClient¶
Asynchronous version of the DataViewsClient for use with async/await syntax.
- class kibana._async.client.data_views.AsyncDataViewsClient(client, default_space_id=None, validate_spaces=True)[source]¶
Bases:
AsyncNamespaceClientAsync client for the Kibana Data Views API.
Data views (formerly index patterns) tell Kibana which Elasticsearch indices, data streams, and aliases to query. This client covers the full Kibana 9.4.3 data views surface: data view CRUD, field metadata updates, runtime field management, the default data view, and saved object reference swapping.
All operations are space-aware: pass
space_idto target a specific Kibana space, or useclient.space("my-space").data_views.Example
>>> from kibana import AsyncKibana >>> client = AsyncKibana("http://localhost:5601", api_key="...") >>> >>> # Create a data view over an index >>> response = await client.data_views.create( ... data_view={ ... "title": "my-logs-*", ... "name": "My Logs", ... "timeFieldName": "@timestamp", ... } ... ) >>> view_id = response["data_view"]["id"] >>> >>> # Add a runtime field >>> await client.data_views.create_runtime_field( ... view_id=view_id, ... name="hour_of_day", ... runtime_field={ ... "type": "long", ... "script": { ... "source": "emit(doc['@timestamp'].value.getHour())" ... }, ... }, ... )
Usage
The AsyncDataViewsClient provides the same methods as DataViewsClient but all methods are async and must be awaited:
from kibana import AsyncKibana import asyncio async def main(): async with AsyncKibana("http://localhost:5601") as client: # Create a data view (async) response = await client.data_views.create( data_view={ "title": "async-logs-*", "timeFieldName": "@timestamp", } ) view_id = response["data_view"]["id"] # List all data views (async) views = await client.data_views.get_all() # Delete (async) await client.data_views.delete(view_id=view_id) asyncio.run(main())
- async get_all(*, space_id=None, validate_spaces=None)[source]¶
Get all data views.
Retrieves a list of all data views in the space, with their identifiers, titles, names, and namespaces.
- Parameters:
- Returns:
Response with a
data_viewarray of data view summaries.- Raises:
AuthenticationException – If authentication fails.
AuthorizationException – If insufficient privileges.
- Return type:
Example
>>> response = await client.data_views.get_all() >>> for view in response["data_view"]: ... print(view["id"], view["title"])
- async create(*, data_view, override=None, space_id=None, validate_spaces=None)[source]¶
Create a data view.
- Parameters:
data_view (dict[str, Any]) – The data view object. Requires
title(a comma-separated list of data streams, indices, and aliases to search). Optional keys includeid,name,timeFieldName,allowNoIndex,fieldAttrs,fieldFormats,namespaces,runtimeFieldMap,sourceFilters,type,typeMeta, andversion.override (bool | None) – Override an existing data view if one with the provided title already exists. Defaults to false.
space_id (str | None) – Optional space ID to scope the operation to.
validate_spaces (bool | None) – Override space-existence validation for this call.
- Returns:
Response with the created
data_viewobject.- Raises:
ValueError – If
data_viewis missing.BadRequestError – If the data view definition is invalid or a data view with the same title exists and
overrideis not set.
- Return type:
Example
>>> response = await client.data_views.create( ... data_view={ ... "title": "my-logs-*", ... "timeFieldName": "@timestamp", ... } ... ) >>> print(response["data_view"]["id"])
- async get(*, view_id, space_id=None, validate_spaces=None)[source]¶
Get a data view.
- Parameters:
- Returns:
Response with the full
data_viewobject, including fields.- Raises:
ValueError – If
view_idis missing.NotFoundError – If the data view does not exist.
- Return type:
Example
>>> response = await client.data_views.get(view_id="my-view-id") >>> print(response["data_view"]["title"])
- async update(*, view_id, data_view, refresh_fields=None, space_id=None, validate_spaces=None)[source]¶
Update a data view.
Only the properties present in
data_vieware updated; all other properties keep their current values.- Parameters:
view_id (str) – The data view identifier.
data_view (dict[str, Any]) – The data view properties to update, e.g.
title,name,timeFieldName,allowNoIndex,fieldFormats,runtimeFieldMap,sourceFilters,type, ortypeMeta.refresh_fields (bool | None) – Reload the data view fields after the update. Defaults to false.
space_id (str | None) – Optional space ID to scope the operation to.
validate_spaces (bool | None) – Override space-existence validation for this call.
- Returns:
Response with the updated
data_viewobject.- Raises:
ValueError – If
view_idordata_viewis missing.NotFoundError – If the data view does not exist.
BadRequestError – If the update payload is invalid.
- Return type:
Example
>>> await client.data_views.update( ... view_id="my-view-id", ... data_view={"name": "Renamed view"}, ... refresh_fields=True, ... )
- async delete(*, view_id, space_id=None, validate_spaces=None)[source]¶
Delete a data view.
WARNING: When you delete a data view, it cannot be recovered.
- Parameters:
- Returns:
Empty response on success.
- Raises:
ValueError – If
view_idis missing.NotFoundError – If the data view does not exist.
- Return type:
Example
>>> await client.data_views.delete(view_id="my-view-id")
- async update_fields_metadata(*, view_id, fields, space_id=None, validate_spaces=None)[source]¶
Update data view fields metadata.
Updates presentation metadata for fields, such as
count,customLabel,customDescription, andformat.- Parameters:
fields (dict[str, Any]) – Map of field names to the metadata to set, e.g.
{"my_field": {"customLabel": "My label", "count": 5}}.view_id (str) – The data view identifier.
space_id (str | None) – Optional space ID to scope the operation to.
validate_spaces (bool | None) – Override space-existence validation for this call.
- Returns:
Response with the updated
data_viewobject.- Raises:
ValueError – If
view_idorfieldsis missing.NotFoundError – If the data view does not exist.
BadRequestError – If the fields payload is invalid.
- Return type:
Example
>>> await client.data_views.update_fields_metadata( ... view_id="my-view-id", ... fields={"response_code": {"customLabel": "Status"}}, ... )
- async create_runtime_field(*, view_id, name, runtime_field, space_id=None, validate_spaces=None)[source]¶
Create a runtime field.
Fails if a runtime field with the same name already exists; use
create_or_update_runtime_field()for upsert semantics.- Parameters:
view_id (str) – The data view identifier.
name (str) – The name for the new runtime field.
runtime_field (dict[str, Any]) – The runtime field definition object, e.g.
{"type": "keyword", "script": {"source": "emit('a')"}}.space_id (str | None) – Optional space ID to scope the operation to.
validate_spaces (bool | None) – Override space-existence validation for this call.
- Returns:
Response with the created runtime
fieldsand the updateddata_viewobject.- Raises:
ValueError – If a required parameter is missing.
NotFoundError – If the data view does not exist.
BadRequestError – If the field already exists or the definition is invalid.
- Return type:
Example
>>> await client.data_views.create_runtime_field( ... view_id="my-view-id", ... name="hour_of_day", ... runtime_field={ ... "type": "long", ... "script": { ... "source": "emit(doc['@timestamp'].value.getHour())" ... }, ... }, ... )
- async create_or_update_runtime_field(*, view_id, name, runtime_field, space_id=None, validate_spaces=None)[source]¶
Create or update a runtime field.
Upsert semantics: creates the runtime field if it does not exist, or replaces its definition if it does.
- Parameters:
view_id (str) – The data view identifier.
name (str) – The name for the runtime field.
runtime_field (dict[str, Any]) – The runtime field definition object, e.g.
{"type": "keyword", "script": {"source": "emit('a')"}}.space_id (str | None) – Optional space ID to scope the operation to.
validate_spaces (bool | None) – Override space-existence validation for this call.
- Returns:
Response with the runtime
fieldsand the updateddata_viewobject.- Raises:
ValueError – If a required parameter is missing.
NotFoundError – If the data view does not exist.
BadRequestError – If the field definition is invalid.
- Return type:
Example
>>> await client.data_views.create_or_update_runtime_field( ... view_id="my-view-id", ... name="hour_of_day", ... runtime_field={ ... "type": "long", ... "script": { ... "source": "emit(doc['@timestamp'].value.getHour())" ... }, ... }, ... )
- async get_runtime_field(*, view_id, name, space_id=None, validate_spaces=None)[source]¶
Get a runtime field.
- Parameters:
- Returns:
Response with the runtime
fieldsand the owningdata_viewobject.- Raises:
ValueError – If
view_idornameis missing.NotFoundError – If the data view or runtime field does not exist.
- Return type:
Example
>>> response = await client.data_views.get_runtime_field( ... view_id="my-view-id", name="hour_of_day" ... ) >>> print(response["fields"][0]["runtimeField"]["type"])
- async update_runtime_field(*, view_id, name, runtime_field, space_id=None, validate_spaces=None)[source]¶
Update a runtime field.
Updates an existing runtime field definition. You can update the
typeandscriptof the runtime field.- Parameters:
view_id (str) – The data view identifier.
name (str) – The name of the runtime field to update.
runtime_field (dict[str, Any]) – The runtime field properties to update, e.g.
{"script": {"source": "emit('b')"}}.space_id (str | None) – Optional space ID to scope the operation to.
validate_spaces (bool | None) – Override space-existence validation for this call.
- Returns:
Response with the runtime
fieldsand the updateddata_viewobject.- Raises:
ValueError – If a required parameter is missing.
NotFoundError – If the data view or runtime field does not exist.
BadRequestError – If the field definition is invalid.
- Return type:
Example
>>> await client.data_views.update_runtime_field( ... view_id="my-view-id", ... name="hour_of_day", ... runtime_field={"script": {"source": "emit(0)"}}, ... )
- async delete_runtime_field(*, view_id, name, space_id=None, validate_spaces=None)[source]¶
Delete a runtime field from a data view.
- Parameters:
- Returns:
Empty response on success.
- Raises:
ValueError – If
view_idornameis missing.NotFoundError – If the data view or runtime field does not exist.
- Return type:
Example
>>> await client.data_views.delete_runtime_field( ... view_id="my-view-id", name="hour_of_day" ... )
- async get_default(*, space_id=None, validate_spaces=None)[source]¶
Get the default data view.
- Parameters:
- Returns:
Response with the default
data_view_id(an empty string when no default data view is set).- Raises:
AuthenticationException – If authentication fails.
AuthorizationException – If insufficient privileges.
- Return type:
Example
>>> response = await client.data_views.get_default() >>> print(response["data_view_id"])
- async set_default(*, data_view_id, force=None, space_id=None, validate_spaces=None)[source]¶
Set the default data view.
- Parameters:
data_view_id (str | None) – The data view identifier to set as default. NOTE: The API does not validate whether it is a valid identifier. Use
Noneto unset the default data view.force (bool | None) – Update the default even when one is already set. Defaults to false.
space_id (str | None) – Optional space ID to scope the operation to.
validate_spaces (bool | None) – Override space-existence validation for this call.
- Returns:
Response with
acknowledged: trueon success.- Raises:
BadRequestError – If the request payload is invalid.
- Return type:
Example
>>> await client.data_views.set_default( ... data_view_id="my-view-id", force=True ... )
- async swap_references(*, from_id, to_id, from_type=None, for_id=None, for_type=None, delete=None, space_id=None, validate_spaces=None)[source]¶
Swap saved object references.
Changes saved object references from one data view identifier to another. WARNING: Misuse can break large numbers of saved objects. Practicing with a backup is recommended; use
preview_swap_references()to dry-run the operation first.- Parameters:
from_id (str) – The saved object reference to change.
to_id (str) – New saved object reference value to replace the old value.
from_type (str | None) – The type of the saved object reference to alter. Defaults to
index-pattern(data views).for_id (str | list[str] | None) – Limit the affected saved objects to one or more by identifier (a single ID or a list of IDs).
for_type (str | None) – Limit the affected saved objects by type.
delete (bool | None) – Delete the referenced saved object (
from_id) if all its references are removed. Defaults to false.space_id (str | None) – Optional space ID to scope the operation to.
validate_spaces (bool | None) – Override space-existence validation for this call.
- Returns:
Response with a
resultarray of the changed saved objects and, whendeleteis used, adeleteStatusobject.- Raises:
ValueError – If
from_idorto_idis missing.BadRequestError – If the request payload is invalid.
- Return type:
Example
>>> response = await client.data_views.swap_references( ... from_id="old-view-id", ... to_id="new-view-id", ... delete=True, ... ) >>> print(response["deleteStatus"]["deletePerformed"])
- async preview_swap_references(*, from_id, to_id, from_type=None, for_id=None, for_type=None, delete=None, space_id=None, validate_spaces=None)[source]¶
Preview a saved object reference swap.
Dry-runs
swap_references()and reports which saved objects would be changed, without modifying anything.- Parameters:
from_id (str) – The saved object reference to change.
to_id (str) – New saved object reference value to replace the old value.
from_type (str | None) – The type of the saved object reference to alter. Defaults to
index-pattern(data views).for_id (str | list[str] | None) – Limit the affected saved objects to one or more by identifier (a single ID or a list of IDs).
for_type (str | None) – Limit the affected saved objects by type.
delete (bool | None) – Whether the swap would delete the referenced saved object once all its references are removed.
space_id (str | None) – Optional space ID to scope the operation to.
validate_spaces (bool | None) – Override space-existence validation for this call.
- Returns:
Response with a
resultarray of the saved objects that would be changed.- Raises:
ValueError – If
from_idorto_idis missing.BadRequestError – If the request payload is invalid.
- Return type:
Example
>>> response = await client.data_views.preview_swap_references( ... from_id="old-view-id", to_id="new-view-id" ... ) >>> print(response["result"])
- __init__(client, default_space_id=None, validate_spaces=True)¶
Initialize AsyncNamespaceClient with optional space support.