1.. _api: 2 3API Documentation 4================= 5 6All the API calls map the raw REST api as closely as possible, including the 7distinction between required and optional arguments to the calls. This means 8that the code makes distinction between positional and keyword arguments; we, 9however, recommend that people **use keyword arguments for all calls for 10consistency and safety**. 11 12.. note:: 13 14 for compatibility with the Python ecosystem we use ``from_`` instead of 15 ``from`` and ``doc_type`` instead of ``type`` as parameter names. 16 17 18Global Options 19-------------- 20 21Some parameters are added by the client itself and can be used in all API 22calls. 23 24Ignore 25~~~~~~ 26 27An API call is considered successful (and will return a response) if 28elasticsearch returns a 2XX response. Otherwise an instance of 29:class:`~elasticsearch.TransportError` (or a more specific subclass) will be 30raised. You can see other exception and error states in :ref:`exceptions`. If 31you do not wish an exception to be raised you can always pass in an ``ignore`` 32parameter with either a single status code that should be ignored or a list of 33them: 34 35.. code-block:: python 36 37 from elasticsearch import Elasticsearch 38 es = Elasticsearch() 39 40 # ignore 400 cause by IndexAlreadyExistsException when creating an index 41 es.indices.create(index='test-index', ignore=400) 42 43 # ignore 404 and 400 44 es.indices.delete(index='test-index', ignore=[400, 404]) 45 46 47Timeout 48~~~~~~~ 49 50Global timeout can be set when constructing the client (see 51:class:`~elasticsearch.Connection`'s ``timeout`` parameter) or on a per-request 52basis using ``request_timeout`` (float value in seconds) as part of any API 53call, this value will get passed to the ``perform_request`` method of the 54connection class: 55 56.. code-block:: python 57 58 # only wait for 1 second, regardless of the client's default 59 es.cluster.health(wait_for_status='yellow', request_timeout=1) 60 61.. note:: 62 63 Some API calls also accept a ``timeout`` parameter that is passed to 64 Elasticsearch server. This timeout is internal and doesn't guarantee that the 65 request will end in the specified time. 66 67Tracking Requests with Opaque ID 68~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 69 70You can enrich your requests against Elasticsearch with an identifier string, that allows you to discover this identifier 71in `deprecation logs <https://www.elastic.co/guide/en/elasticsearch/reference/7.4/logging.html#deprecation-logging>`_, to support you with 72`identifying search slow log origin <https://www.elastic.co/guide/en/elasticsearch/reference/7.4/index-modules-slowlog.html#_identifying_search_slow_log_origin>`_ 73or to help with `identifying running tasks <https://www.elastic.co/guide/en/elasticsearch/reference/current/tasks.html#_identifying_running_tasks>`_. 74 75 .. code-block:: python 76 77 from elasticsearch import Elasticsearch 78 79 client = Elasticsearch() 80 81 # You can apply X-Opaque-Id in any API request via 'opaque_id': 82 resp = client.get(index="test", id="1", opaque_id="request-1") 83 84 85.. py:module:: elasticsearch 86 87Response Filtering 88~~~~~~~~~~~~~~~~~~ 89 90The ``filter_path`` parameter is used to reduce the response returned by 91elasticsearch. For example, to only return ``_id`` and ``_type``, do: 92 93.. code-block:: python 94 95 es.search(index='test-index', filter_path=['hits.hits._id', 'hits.hits._type']) 96 97It also supports the ``*`` wildcard character to match any field or part of a 98field's name: 99 100.. code-block:: python 101 102 es.search(index='test-index', filter_path=['hits.hits._*']) 103 104Elasticsearch 105------------- 106 107.. autoclass:: Elasticsearch 108 :members: 109 110.. py:module:: elasticsearch.client 111 112Async Search 113------------ 114 115.. autoclass:: AsyncSearchClient 116 :members: 117 118Autoscaling 119----------- 120 121.. autoclass:: AutoscalingClient 122 :members: 123 124Cat 125--- 126 127.. autoclass:: CatClient 128 :members: 129 130Cross-Cluster Replication (CCR) 131------------------------------- 132 133.. autoclass:: CcrClient 134 :members: 135 136Cluster 137------- 138 139.. autoclass:: ClusterClient 140 :members: 141 142Dangling Indices 143---------------- 144 145.. autoclass:: DanglingIndicesClient 146 :members: 147 148Enrich Policies 149--------------- 150 151.. autoclass:: EnrichClient 152 :members: 153 154Event Query Language (EQL) 155-------------------------- 156 157.. autoclass:: EqlClient 158 :members: 159 160Snapshottable Features 161---------------------- 162 163.. autoclass:: FeaturesClient 164 :members: 165 166Fleet 167----- 168 169.. autoclass:: FleetClient 170 :members: 171 172Graph Explore 173------------- 174 175.. autoclass:: GraphClient 176 :members: 177 178Index Lifecycle Management (ILM) 179-------------------------------- 180 181.. autoclass:: IlmClient 182 :members: 183 184Indices 185------- 186 187.. autoclass:: IndicesClient 188 :members: 189 190Ingest Pipelines 191---------------- 192 193.. autoclass:: IngestClient 194 :members: 195 196License 197------- 198 199.. autoclass:: LicenseClient 200 :members: 201 202Logstash 203-------- 204 205.. autoclass:: LogstashClient 206 :members: 207 208Migration 209--------- 210 211.. autoclass:: MigrationClient 212 :members: 213 214Machine Learning (ML) 215--------------------- 216 217.. autoclass:: MlClient 218 :members: 219 220Monitoring 221---------- 222 223.. autoclass:: MonitoringClient 224 :members: 225 226Nodes 227----- 228 229.. autoclass:: NodesClient 230 :members: 231 232Rollup Indices 233-------------- 234 235.. autoclass:: RollupClient 236 :members: 237 238Searchable Snapshots 239-------------------- 240 241.. autoclass:: SearchableSnapshotsClient 242 :members: 243 244Security 245-------- 246 247.. autoclass:: SecurityClient 248 :members: 249 250Shutdown 251-------- 252 253.. autoclass:: ShutdownClient 254 :members: 255 256Snapshot Lifecycle Management (SLM) 257----------------------------------- 258 259.. autoclass:: SlmClient 260 :members: 261 262Snapshots 263--------- 264 265.. autoclass:: SnapshotClient 266 :members: 267 268SQL 269--- 270 271.. autoclass:: SqlClient 272 :members: 273 274TLS/SSL 275------- 276 277.. autoclass:: SslClient 278 :members: 279 280Tasks 281----- 282 283.. autoclass:: TasksClient 284 :members: 285 286Text Structure 287-------------- 288 289.. autoclass:: TextStructureClient 290 :members: 291 292Transforms 293---------- 294 295.. autoclass:: TransformClient 296 :members: 297 298Watcher 299------- 300 301.. autoclass:: WatcherClient 302 :members: 303 304X-Pack 305------ 306 307.. autoclass:: XPackClient 308 :members: 309