index
- class opensearchpy.helpers.index.Index(name, using='default')[source]
Bases:
object
- Parameters:
- aliases(**kwargs)[source]
Add aliases to the index definition:
i = Index('blog-v2') i.aliases(blog={}, published={'filter': Q('term', published=True)})
- 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:
using (OpenSearch | None) –
kwargs (Any) –
- Return type:
- 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)
- 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:
using (OpenSearch | None) –
kwargs (Any) –
- Return type:
- 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()
- close(using=None, **kwargs)[source]
Closes the index in opensearch.
Any additional keyword arguments will be passed to
OpenSearch.indices.close
unchanged.- Parameters:
using (OpenSearch | None) –
kwargs (Any) –
- Return type:
- create(using=None, **kwargs)[source]
Creates the index in opensearch.
Any additional keyword arguments will be passed to
OpenSearch.indices.create
unchanged.- Parameters:
using (OpenSearch | None) –
kwargs (Any) –
- Return type:
- delete(using=None, **kwargs)[source]
Deletes the index in opensearch.
Any additional keyword arguments will be passed to
OpenSearch.indices.delete
unchanged.- Parameters:
using (OpenSearch | None) –
kwargs (Any) –
- Return type:
- delete_alias(using=None, **kwargs)[source]
Delete specific alias.
Any additional keyword arguments will be passed to
OpenSearch.indices.delete_alias
unchanged.- Parameters:
using (OpenSearch | None) –
kwargs (Any) –
- Return type:
- document(document)[source]
Associate a
Document
subclass with an index. This means that, when this index is created, it will contain the mappings for theDocument
. If theDocument
class doesn’t have a default index yet (by definingclass 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()
- 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:
using (OpenSearch | None) –
kwargs (Any) –
- Return type:
- 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:
using (OpenSearch | None) –
kwargs (Any) –
- Return type:
- 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:
using (OpenSearch | None) –
kwargs (Any) –
- Return type:
- 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:
using (OpenSearch | None) –
kwargs (Any) –
- Return type:
- 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:
using (OpenSearch | None) –
kwargs (Any) –
- Return type:
- get_alias(using=None, **kwargs)[source]
Retrieve a specified alias.
Any additional keyword arguments will be passed to
OpenSearch.indices.get_alias
unchanged.- Parameters:
using (OpenSearch | None) –
kwargs (Any) –
- Return type:
- 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:
using (OpenSearch | None) –
kwargs (Any) –
- Return type:
- 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:
using (OpenSearch | None) –
kwargs (Any) –
- Return type:
- 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:
using (OpenSearch | None) –
kwargs (Any) –
- Return type:
- 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:
using (OpenSearch | None) –
kwargs (Any) –
- Return type:
- 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.
- open(using=None, **kwargs)[source]
Opens the index in opensearch.
Any additional keyword arguments will be passed to
OpenSearch.indices.open
unchanged.- Parameters:
using (OpenSearch | None) –
kwargs (Any) –
- Return type:
- 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:
using (OpenSearch | None) –
kwargs (Any) –
- Return type:
- 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:
using (OpenSearch | None) –
kwargs (Any) –
- Return type:
- 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:
using (OpenSearch | None) –
kwargs (Any) –
- Return type:
- 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:
using (OpenSearch | None) –
kwargs (Any) –
- Return type:
- 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:
using (OpenSearch | None) –
kwargs (Any) –
- Return type:
- 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:
- search(using=None)[source]
Return a
Search
object searching over the index (or all the indices belonging to this template) and itsDocument
s.- Parameters:
using (OpenSearch | None) –
- Return type:
- 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:
using (OpenSearch | None) –
kwargs (Any) –
- Return type:
- 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.
- 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:
using (OpenSearch | None) –
kwargs (Any) –
- Return type:
- 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:
using (OpenSearch | None) –
kwargs (Any) –
- Return type:
- 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:
using (OpenSearch | None) –
kwargs (Any) –
- Return type:
- 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:
- 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:
using (OpenSearch | None) –
kwargs (Any) –
- Return type:
- 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:
using (OpenSearch | None) –
kwargs (Any) –
- Return type: