All the API calls map the raw REST api as closely as possible, including the distinction between required and optional arguments to the calls. This means that the code makes distinction between positional and keyword arguments; we, however, recommend that people use keyword arguments for all calls for consistency and safety.
Note
for compatibility with the Python ecosystem we use from_ instead of from and doc_type instead of type as parameter names.
Some parameters are added by the client itself and can be used in all API calls.
An API call is considered successful (and will return a response) if elasticsearch returns a 2XX response. Otherwise an instance of TransportError (or a more specific subclass) will be raised. You can see other exception and error states in Exceptions. If you do not wish an exception to be raised you can always pass in an ignore parameter with either a single status code that should be ignored or a list of them:
from elasticsearch import Elasticsearch
es = Elasticsearch()
# ignore 400 cause by IndexAlreadyExistsException when creating an index
es.indices.create(index='test-index', ignore=400)
# ignore 404 and 400
es.indices.delete(index='test-index', ignore=[400, 404])
Global timeout can be set when constructing the client (see Connection‘s timeout parameter) or on a per-request basis using request_timeout (float value in seconds) as part of any API call, this value will get passed to the perform_request method of the connection class:
# only wait for 1 second, regardless of the client's default
es.cluster.health(wait_for_status='yellow', request_timeout=1)
Note
Some API calls also accept a timeout parameter that is passed to Elasticsearch server. This timeout is internal and doesn’t guarantee that the request will end in the specified time.
Elasticsearch low-level client. Provides a straightforward mapping from Python to ES REST endpoints.
The instance has attributes cat, cluster, indices, nodes and snapshot that provide access to instances of CatClient, ClusterClient, IndicesClient, NodesClient and SnapshotClient respectively. This is the preferred (and only supported) way to get access to those classes and their methods.
You can specify your own connection class which should be used by providing the connection_class parameter:
# create connection to localhost using the ThriftConnection
es = Elasticsearch(connection_class=ThriftConnection)
If you want to turn on Sniffing you have several options (described in Transport):
# create connection that will automatically inspect the cluster to get
# the list of active nodes. Start with nodes running on 'esnode1' and
# 'esnode2'
es = Elasticsearch(
['esnode1', 'esnode2'],
# sniff before doing anything
sniff_on_start=True,
# refresh nodes after a node fails to respond
sniff_on_connection_fail=True,
# and also every 60 seconds
sniffer_timeout=60
)
Different hosts can have different parameters, use a dictionary per node to specify those:
# connect to localhost directly and another node using SSL on port 443
# and an url_prefix. Note that ``port`` needs to be an int.
es = Elasticsearch([
{'host': 'localhost'},
{'host': 'othernode', 'port': 443, 'url_prefix': 'es', 'use_ssl': True},
])
If using SSL, there are several parameters that control how we deal with certificates (see Urllib3HttpConnection for detailed description of the options):
es = Elasticsearch(
['localhost:443', 'other_host:443'],
# turn on SSL
use_ssl=True,
# make sure we verify SSL certificates (off by default)
verify_certs=True,
# provide a path to CA certs on disk
ca_certs='/path/to/CA_certs'
)
Alternatively you can use RFC-1738 formatted URLs, as long as they are not in conflict with other options:
es = Elasticsearch(
[
'http://user:secret@localhost:9200/',
'https://user:secret@other_host:443/production'
],
verify_certs=True
)
Parameters: |
|
---|
Aborts a running benchmark. http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/search-benchmark.html
Parameters: | name – A benchmark name |
---|
The benchmark API provides a standard mechanism for submitting queries and measuring their performance relative to one another. http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/search-benchmark.html
Parameters: |
|
---|
Perform many index/delete operations in a single API call. http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/docs-bulk.html
See the bulk() helper function for a more friendly API.
Parameters: |
|
---|
Clear the scroll request created by specifying the scroll parameter to search. http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-request-scroll.html
Parameters: |
|
---|
Execute a query and get the number of matches for that query. http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-count.html
Parameters: |
|
---|
The percolator allows to register queries against an index, and then send percolate requests which include a doc, and getting back the queries that match on that doc out of the set of registered queries. http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-percolate.html
Parameters: |
|
---|
Adds a typed JSON document in a specific index, making it searchable. Behind the scenes this method calls index(..., op_type=’create’) http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/docs-index_.html
Parameters: |
|
---|
Delete a typed JSON document from a specific index based on its id. http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/docs-delete.html
Parameters: |
|
---|
Delete documents from one or more indices and one or more types based on a query. http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/docs-delete-by-query.html
Parameters: |
|
---|
Remove a stored script from elasticsearch. http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/modules-scripting.html
Parameters: |
|
---|
Delete a search template. http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-template.html
Parameters: |
|
---|
Returns a boolean indicating whether or not given document exists in Elasticsearch. http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/docs-get.html
Parameters: |
|
---|
The explain api computes a score explanation for a query and a specific document. This can give useful feedback whether a document matches or didn’t match a specific query. http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-explain.html
Parameters: |
|
---|
Get a typed JSON document from the index based on its id. http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/docs-get.html
Parameters: |
|
---|
Retrieve a script from the API. http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/modules-scripting.html
Parameters: |
|
---|
Get the source of a document by it’s index, type and id. http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/docs-get.html
Parameters: |
|
---|
Retrieve a search template. http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-template.html
Parameters: |
|
---|
Adds or updates a typed JSON document in a specific index, making it searchable. http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/docs-index_.html
Parameters: |
|
---|
Get the basic info from the current cluster.
View the progress of long-running benchmarks. http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/search-benchmark.html
Parameters: |
|
---|
Get multiple documents based on an index, type (optional) and ids. http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/docs-multi-get.html
Parameters: |
|
---|
Get documents that are “like” a specified document. http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-more-like-this.html
Parameters: |
|
---|
The percolator allows to register queries against an index, and then send percolate requests which include a doc, and getting back the queries that match on that doc out of the set of registered queries. http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-percolate.html
Parameters: |
|
---|
Execute several search requests within the same API. http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-multi-search.html
Parameters: |
|
---|
Multi termvectors API allows to get multiple termvectors based on an index, type and id. http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/docs-multi-termvectors.html
Parameters: |
|
---|
The percolator allows to register queries against an index, and then send percolate requests which include a doc, and getting back the queries that match on that doc out of the set of registered queries. http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-percolate.html
Parameters: |
|
---|
Returns True if the cluster is up, False otherwise.
Create a script in given language with specified ID. http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/modules-scripting.html
Parameters: |
|
---|
Create a search template. http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-template.html
Parameters: |
|
---|
Scroll a search request created by specifying the scroll parameter. http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-request-scroll.html
Parameters: |
|
---|
Execute a search query and get back search hits that match the query. http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-search.html
Parameters: |
|
---|
http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-exists.html
Parameters: |
|
---|
The search shards api returns the indices and shards that a search request would be executed against. This can give useful feedback for working out issues or planning optimizations with routing and shard preferences. http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/search-shards.html
Parameters: |
|
---|
A query that accepts a query template and a map of key/value pairs to fill in template parameters. http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/query-dsl-template-query.html
Parameters: |
|
---|
The suggest feature suggests similar looking terms based on a provided text by using a suggester. http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-search.html
Parameters: |
|
---|
Returns information and statistics on terms in the fields of a particular document. The document could be stored in the index or artificially provided by the user (Added in 1.4). Note that for documents stored in the index, this is a near realtime API as the term vectors are not available until the next refresh. <http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/docs-termvectors.html>
Parameters: |
|
---|
Returns information and statistics on terms in the fields of a particular document. The document could be stored in the index or artificially provided by the user (Added in 1.4). Note that for documents stored in the index, this is a near realtime API as the term vectors are not available until the next refresh. <http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/docs-termvectors.html>
Parameters: |
|
---|
Update a document based on a script or partial data provided. http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/docs-update.html
Parameters: |
|
---|
Perform the analysis process on a text and return the tokens breakdown of the text. http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/indices-analyze.html
Parameters: |
|
---|
Clear either all caches or specific cached associated with one ore more indices. http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/indices-clearcache.html
Parameters: |
|
---|
Close an index to remove it’s overhead from the cluster. Closed index is blocked for read/write operations. http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/indices-open-close.html
Parameters: |
|
---|
Create an index in Elasticsearch. http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/indices-create-index.html
Parameters: |
|
---|
Delete an index in Elasticsearch http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/indices-delete-index.html
Parameters: |
|
---|
Delete specific alias. http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/indices-aliases.html
Parameters: |
|
---|
Delete a mapping (type) along with its data. http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/indices-delete-mapping.html
Parameters: |
|
---|
Delete an index template by its name. http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/indices-templates.html
Parameters: |
|
---|
Delete an index warmer. http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/indices-warmers.html
Parameters: |
|
---|
Return a boolean indicating whether given index exists. http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/indices-exists.html
Parameters: |
|
---|
Return a boolean indicating whether given alias exists. http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/indices-aliases.html
Parameters: |
|
---|
Return a boolean indicating whether given template exists. http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/indices-templates.html
Parameters: |
|
---|
Check if a type/types exists in an index/indices. http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/indices-types-exists.html
Parameters: |
|
---|
Explicitly flush one or more indices. http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/indices-flush.html
Parameters: |
|
---|
The get index API allows to retrieve information about one or more indexes. http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/indices-get-index.html
Parameters: |
|
---|
Retrieve a specified alias. http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/indices-aliases.html
Parameters: |
|
---|
Retrieve specified aliases http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/indices-aliases.html
Parameters: |
|
---|
Retrieve mapping definition of a specific field. http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/indices-get-field-mapping.html
Parameters: |
|
---|
Retrieve mapping definition of index or index/type. http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/indices-get-mapping.html
Parameters: |
|
---|
Retrieve settings for one or more (or all) indices. http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/indices-get-settings.html
Parameters: |
|
---|
Retrieve an index template by its name. http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/indices-templates.html
Parameters: |
|
---|
Monitor how much of one or more index is upgraded. http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/indices-upgrade.html
Parameters: |
|
---|
Retreieve an index warmer. http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/indices-warmers.html
Parameters: |
|
---|
Open a closed index to make it available for search. http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/indices-open-close.html
Parameters: |
|
---|
Explicitly optimize one or more indices through an API. http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/indices-optimize.html
Parameters: |
|
---|
Create an alias for a specific index/indices. http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/indices-aliases.html
Parameters: |
|
---|
Register specific mapping definition for a specific type. http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/indices-put-mapping.html
Parameters: |
|
---|
Change specific index level settings in real time. http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/indices-update-settings.html
Parameters: |
|
---|
Create an index template that will automatically be applied to new indices created. http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/indices-templates.html
Parameters: |
|
---|
Create an index warmer to run registered search requests to warm up the index before it is available for search. http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/indices-warmers.html
Parameters: |
|
---|
The indices recovery API provides insight into on-going shard recoveries. Recovery status may be reported for specific indices, or cluster-wide. http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/indices-recovery.html
Parameters: |
|
---|
Explicitly refresh one or more index, making all operations performed since the last refresh available for search. http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/indices-refresh.html
Parameters: |
|
---|
Provide low level segments information that a Lucene index (shard level) is built with. http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/indices-segments.html
Parameters: |
|
---|
Explicitly perform a snapshot through the gateway of one or more indices (backup them). http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/indices-gateway-snapshot.html
Parameters: |
|
---|
Retrieve statistics on different operations happening on an index. http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/indices-stats.html
Parameters: |
|
---|
Get a comprehensive status information of one or more indices. http://elasticsearch.org/guide/reference/api/admin-indices-_/
Parameters: |
|
---|
Update specified aliases. http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/indices-aliases.html
Parameters: |
|
---|
Upgrade one or more indices to the latest format through an API. http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/indices-upgrade.html
Parameters: |
|
---|
Validate a potentially expensive query without executing it. http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-validate.html
Parameters: |
|
---|
Get cluster settings. http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/cluster-update-settings.html
Parameters: |
|
---|
Get a very simple status on the health of the cluster. http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/cluster-health.html
Parameters: |
|
---|
The pending cluster tasks API returns a list of any cluster-level changes (e.g. create index, update mapping, allocate or fail shard) which have not yet been executed. http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/cluster-pending.html
Parameters: |
|
---|
Update cluster wide specific settings. http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/cluster-update-settings.html
Parameters: |
|
---|
Explicitly execute a cluster reroute allocation command including specific commands. http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/cluster-reroute.html
Parameters: |
|
---|
Get a comprehensive state information of the whole cluster. http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/cluster-state.html
Parameters: |
|
---|
The Cluster Stats API allows to retrieve statistics from a cluster wide perspective. The API returns basic index metrics and information about the current nodes that form the cluster. http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/cluster-stats.html
Parameters: |
|
---|
An API allowing to get the current hot threads on each node in the cluster. http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/cluster-nodes-hot-threads.html
Parameters: |
|
---|
The cluster nodes info API allows to retrieve one or more (or all) of the cluster nodes information. http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/cluster-nodes-info.html
Parameters: |
|
---|
The nodes shutdown API allows to shutdown one or more (or all) nodes in the cluster. http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/cluster-nodes-shutdown.html
Parameters: |
|
---|
The cluster nodes stats API allows to retrieve one or more (or all) of the cluster nodes statistics. http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/cluster-nodes-stats.html
Parameters: |
|
---|
http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/cat-alias.html
Parameters: |
|
---|
Allocation provides a snapshot of how shards have located around the cluster and the state of disk usage. http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/cat-allocation.html
Parameters: |
|
---|
Count provides quick access to the document count of the entire cluster, or individual indices. http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/cat-count.html
Parameters: |
|
---|
Shows information about currently loaded fielddata on a per-node basis. http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/cat-fielddata.html
Parameters: |
|
---|
health is a terse, one-line representation of the same information from health() API http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/cat-health.html
Parameters: |
|
---|
A simple help for the cat api. http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/cat.html
Parameters: | help – Return help information, default False |
---|
The indices command provides a cross-section of each index. http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/cat-indices.html
Parameters: |
|
---|
Displays the master’s node ID, bound IP address, and node name. http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/cat-master.html
Parameters: |
|
---|
The nodes command shows the cluster topology. http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/cat-nodes.html
Parameters: |
|
---|
pending_tasks provides the same information as the pending_tasks() API in a convenient tabular format. http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/cat-pending-tasks.html
Parameters: |
|
---|
http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/cat-plugins.html
Parameters: |
|
---|
recovery is a view of shard replication. http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/cat-recovery.html
Parameters: |
|
---|
The segments command is the detailed view of Lucene segments per index.
Parameters: |
|
---|
The shards command is the detailed view of what nodes contain which shards. http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/cat-shards.html
Parameters: |
|
---|
Get information about thread pools. http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/cat-thread-pool.html
Parameters: |
|
---|
Snapshot —
Create a snapshot in repository http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/modules-snapshots.html
Parameters: |
|
---|
Registers a shared file system repository. http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/modules-snapshots.html
Parameters: |
|
---|
Deletes a snapshot from a repository. http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/modules-snapshots.html
Parameters: |
|
---|
Removes a shared file system repository. http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/modules-snapshots.html
Parameters: |
|
---|
Retrieve information about a snapshot. http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/modules-snapshots.html
Parameters: |
|
---|
Return information about registered repositories. http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/modules-snapshots.html
Parameters: |
|
---|
Restore a snapshot. http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/modules-snapshots.html
Parameters: |
|
---|
Return information about all currently running snapshots. By specifying a repository name, it’s possible to limit the results to a particular repository. http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/modules-snapshots.html
Parameters: |
|
---|
Returns a list of nodes where repository was successfully verified or an error message if verification process failed. http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/modules-snapshots.html
Parameters: |
|
---|