index

class opensearchpy.helpers.index.Index(name, using='default')[source]

Bases: object

Parameters:
  • name (Any) – name of the index

  • using (Any) – connection alias to use, defaults to 'default'

  • name

  • using

aliases(**kwargs)[source]

Add aliases to the index definition:

i = Index('blog-v2')
i.aliases(blog={}, published={'filter': Q('term', published=True)})
Parameters:

kwargs (Any) –

Return type:

Any

analyze(using=None, **kwargs)[source]

Perform the analysis process on a text and return the tokens breakdown of the text.

Any additional keyword arguments will be passed to OpenSearch.indices.analyze unchanged.

Parameters:
Return type:

Any

analyzer(*args, **kwargs)[source]

Explicitly add an analyzer to an index. Note that all custom analyzers defined in mappings will also be created. This is useful for search analyzers.

Example:

from opensearchpy import analyzer, tokenizer

my_analyzer = analyzer('my_analyzer',
    tokenizer=tokenizer('trigram', 'nGram', min_gram=3, max_gram=3),
    filter=['lowercase']
)

i = Index('blog')
i.analyzer(my_analyzer)
Parameters:
  • args (Any) –

  • kwargs (Any) –

Return type:

Any

clear_cache(using=None, **kwargs)[source]

Clear all caches or specific cached associated with the index.

Any additional keyword arguments will be passed to OpenSearch.indices.clear_cache unchanged.

Parameters:
Return type:

Any

clone(name=None, using=None)[source]

Create a copy of the instance with another name or connection alias. Useful for creating multiple indices with shared configuration:

i = Index('base-index')
i.settings(number_of_shards=1)
i.create()

i2 = i.clone('other-index')
i2.create()
Parameters:
  • name (Any | None) – name of the index

  • using (Any | None) – connection alias to use, defaults to 'default'

  • name

  • using

Return type:

Any

close(using=None, **kwargs)[source]

Closes the index in opensearch.

Any additional keyword arguments will be passed to OpenSearch.indices.close unchanged.

Parameters:
Return type:

Any

create(using=None, **kwargs)[source]

Creates the index in opensearch.

Any additional keyword arguments will be passed to OpenSearch.indices.create unchanged.

Parameters:
Return type:

Any

delete(using=None, **kwargs)[source]

Deletes the index in opensearch.

Any additional keyword arguments will be passed to OpenSearch.indices.delete unchanged.

Parameters:
Return type:

Any

delete_alias(using=None, **kwargs)[source]

Delete specific alias.

Any additional keyword arguments will be passed to OpenSearch.indices.delete_alias unchanged.

Parameters:
Return type:

Any

document(document)[source]

Associate a Document subclass with an index. This means that, when this index is created, it will contain the mappings for the Document. If the Document class doesn’t have a default index yet (by defining class Index), this instance will be used. Can be used as a decorator:

i = Index('blog')

@i.document
class Post(Document):
    title = Text()

# create the index, including Post mappings
i.create()

# .search() will now return a Search object that will return
# properly deserialized Post instances
s = i.search()
Parameters:

document (Any) –

Return type:

Any

exists(using=None, **kwargs)[source]

Returns True if the index already exists in opensearch.

Any additional keyword arguments will be passed to OpenSearch.indices.exists unchanged.

Parameters:
Return type:

Any

exists_alias(using=None, **kwargs)[source]

Return a boolean indicating whether given alias exists for this index.

Any additional keyword arguments will be passed to OpenSearch.indices.exists_alias unchanged.

Parameters:
Return type:

Any

flush(using=None, **kwargs)[source]

Performs a flush operation on the index.

Any additional keyword arguments will be passed to OpenSearch.indices.flush unchanged.

Parameters:
Return type:

Any

forcemerge(using=None, **kwargs)[source]

The force merge API allows to force merging of the index through an API. The merge relates to the number of segments a Lucene index holds within each shard. The force merge operation allows to reduce the number of segments by merging them.

This call will block until the merge is complete. If the http connection is lost, the request will continue in the background, and any new requests will block until the previous force merge is complete.

Any additional keyword arguments will be passed to OpenSearch.indices.forcemerge unchanged.

Parameters:
Return type:

Any

get(using=None, **kwargs)[source]

The get index API allows to retrieve information about the index.

Any additional keyword arguments will be passed to OpenSearch.indices.get unchanged.

Parameters:
Return type:

Any

get_alias(using=None, **kwargs)[source]

Retrieve a specified alias.

Any additional keyword arguments will be passed to OpenSearch.indices.get_alias unchanged.

Parameters:
Return type:

Any

get_field_mapping(using=None, **kwargs)[source]

Retrieve mapping definition of a specific field.

Any additional keyword arguments will be passed to OpenSearch.indices.get_field_mapping unchanged.

Parameters:
Return type:

Any

get_mapping(using=None, **kwargs)[source]

Retrieve specific mapping definition for a specific type.

Any additional keyword arguments will be passed to OpenSearch.indices.get_mapping unchanged.

Parameters:
Return type:

Any

get_settings(using=None, **kwargs)[source]

Retrieve settings for the index.

Any additional keyword arguments will be passed to OpenSearch.indices.get_settings unchanged.

Parameters:
Return type:

Any

get_upgrade(using=None, **kwargs)[source]

Monitor how much of the index is upgraded.

Any additional keyword arguments will be passed to OpenSearch.indices.get_upgrade unchanged.

Parameters:
Return type:

Any

mapping(mapping)[source]

Associate a mapping (an instance of Mapping) with this index. This means that, when this index is created, it will contain the mappings for the document type defined by those mappings.

Parameters:

mapping (Any) –

Return type:

Any

open(using=None, **kwargs)[source]

Opens the index in opensearch.

Any additional keyword arguments will be passed to OpenSearch.indices.open unchanged.

Parameters:
Return type:

Any

put_alias(using=None, **kwargs)[source]

Create an alias for the index.

Any additional keyword arguments will be passed to OpenSearch.indices.put_alias unchanged.

Parameters:
Return type:

Any

put_mapping(using=None, **kwargs)[source]

Register specific mapping definition for a specific type.

Any additional keyword arguments will be passed to OpenSearch.indices.put_mapping unchanged.

Parameters:
Return type:

Any

put_settings(using=None, **kwargs)[source]

Change specific index level settings in real time.

Any additional keyword arguments will be passed to OpenSearch.indices.put_settings unchanged.

Parameters:
Return type:

Any

recovery(using=None, **kwargs)[source]

The indices recovery API provides insight into on-going shard recoveries for the index.

Any additional keyword arguments will be passed to OpenSearch.indices.recovery unchanged.

Parameters:
Return type:

Any

refresh(using=None, **kwargs)[source]

Performs a refresh operation on the index.

Any additional keyword arguments will be passed to OpenSearch.indices.refresh unchanged.

Parameters:
Return type:

Any

save(using=None)[source]

Sync the index definition with opensearch, creating the index if it doesn’t exist and updating its settings and mappings if it does.

Note some settings and mapping changes cannot be done on an open index (or at all on an existing index) and for those this method will fail with the underlying exception.

Parameters:

using (OpenSearch | None) –

Return type:

Any

search(using=None)[source]

Return a Search object searching over the index (or all the indices belonging to this template) and its Documents.

Parameters:

using (OpenSearch | None) –

Return type:

Search

segments(using=None, **kwargs)[source]

Provide low level segments information that a Lucene index (shard level) is built with.

Any additional keyword arguments will be passed to OpenSearch.indices.segments unchanged.

Parameters:
Return type:

Any

settings(**kwargs)[source]

Add settings to the index:

i = Index('i')
i.settings(number_of_shards=1, number_of_replicas=0)

Multiple calls to settings will merge the keys, later overriding the earlier.

Parameters:

kwargs (Any) –

Return type:

Any

shard_stores(using=None, **kwargs)[source]

Provides store information for shard copies of the index. Store information reports on which nodes shard copies exist, the shard copy version, indicating how recent they are, and any exceptions encountered while opening the shard index or from earlier engine failure.

Any additional keyword arguments will be passed to OpenSearch.indices.shard_stores unchanged.

Parameters:
Return type:

Any

shrink(using=None, **kwargs)[source]

The shrink index API allows you to shrink an existing index into a new index with fewer primary shards. The number of primary shards in the target index must be a factor of the shards in the source index. For example an index with 8 primary shards can be shrunk into 4, 2 or 1 primary shards or an index with 15 primary shards can be shrunk into 5, 3 or 1. If the number of shards in the index is a prime number it can only be shrunk into a single primary shard. Before shrinking, a (primary or replica) copy of every shard in the index must be present on the same node.

Any additional keyword arguments will be passed to OpenSearch.indices.shrink unchanged.

Parameters:
Return type:

Any

stats(using=None, **kwargs)[source]

Retrieve statistics on different operations happening on the index.

Any additional keyword arguments will be passed to OpenSearch.indices.stats unchanged.

Parameters:
Return type:

Any

updateByQuery(using=None)[source]

Return a UpdateByQuery object searching over the index (or all the indices belonging to this template) and updating Documents that match the search criteria.

For more information, see here: https://opensearch.org/docs/latest/opensearch/rest-api/document-apis/update-by-query/

Parameters:

using (OpenSearch | None) –

Return type:

UpdateByQuery

upgrade(using=None, **kwargs)[source]

Upgrade the index to the latest format.

Any additional keyword arguments will be passed to OpenSearch.indices.upgrade unchanged.

Parameters:
Return type:

Any

validate_query(using=None, **kwargs)[source]

Validate a potentially expensive query without executing it.

Any additional keyword arguments will be passed to OpenSearch.indices.validate_query unchanged.

Parameters:
Return type:

Any