elasticsearch 8.17.1__py3-none-any.whl → 8.18.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- elasticsearch/__init__.py +2 -2
- elasticsearch/_async/client/__init__.py +2146 -859
- elasticsearch/_async/client/_base.py +0 -1
- elasticsearch/_async/client/async_search.py +44 -29
- elasticsearch/_async/client/autoscaling.py +32 -26
- elasticsearch/_async/client/cat.py +244 -169
- elasticsearch/_async/client/ccr.py +268 -128
- elasticsearch/_async/client/cluster.py +191 -164
- elasticsearch/_async/client/connector.py +212 -116
- elasticsearch/_async/client/dangling_indices.py +22 -16
- elasticsearch/_async/client/enrich.py +51 -11
- elasticsearch/_async/client/eql.py +54 -13
- elasticsearch/_async/client/esql.py +352 -4
- elasticsearch/_async/client/features.py +37 -27
- elasticsearch/_async/client/fleet.py +22 -10
- elasticsearch/_async/client/graph.py +10 -9
- elasticsearch/_async/client/ilm.py +108 -77
- elasticsearch/_async/client/indices.py +1112 -677
- elasticsearch/_async/client/inference.py +1875 -133
- elasticsearch/_async/client/ingest.py +83 -50
- elasticsearch/_async/client/license.py +90 -38
- elasticsearch/_async/client/logstash.py +20 -9
- elasticsearch/_async/client/migration.py +26 -17
- elasticsearch/_async/client/ml.py +642 -365
- elasticsearch/_async/client/monitoring.py +6 -3
- elasticsearch/_async/client/nodes.py +51 -53
- elasticsearch/_async/client/query_rules.py +59 -33
- elasticsearch/_async/client/rollup.py +124 -86
- elasticsearch/_async/client/search_application.py +60 -32
- elasticsearch/_async/client/searchable_snapshots.py +25 -12
- elasticsearch/_async/client/security.py +896 -558
- elasticsearch/_async/client/shutdown.py +34 -36
- elasticsearch/_async/client/simulate.py +22 -28
- elasticsearch/_async/client/slm.py +65 -40
- elasticsearch/_async/client/snapshot.py +190 -213
- elasticsearch/_async/client/sql.py +43 -22
- elasticsearch/_async/client/ssl.py +17 -18
- elasticsearch/_async/client/synonyms.py +58 -37
- elasticsearch/_async/client/tasks.py +77 -48
- elasticsearch/_async/client/text_structure.py +65 -56
- elasticsearch/_async/client/transform.py +124 -93
- elasticsearch/_async/client/watcher.py +116 -72
- elasticsearch/_async/client/xpack.py +18 -9
- elasticsearch/_async/helpers.py +1 -2
- elasticsearch/_sync/client/__init__.py +2146 -859
- elasticsearch/_sync/client/_base.py +0 -1
- elasticsearch/_sync/client/async_search.py +44 -29
- elasticsearch/_sync/client/autoscaling.py +32 -26
- elasticsearch/_sync/client/cat.py +244 -169
- elasticsearch/_sync/client/ccr.py +268 -128
- elasticsearch/_sync/client/cluster.py +191 -164
- elasticsearch/_sync/client/connector.py +212 -116
- elasticsearch/_sync/client/dangling_indices.py +22 -16
- elasticsearch/_sync/client/enrich.py +51 -11
- elasticsearch/_sync/client/eql.py +54 -13
- elasticsearch/_sync/client/esql.py +352 -4
- elasticsearch/_sync/client/features.py +37 -27
- elasticsearch/_sync/client/fleet.py +22 -10
- elasticsearch/_sync/client/graph.py +10 -9
- elasticsearch/_sync/client/ilm.py +108 -77
- elasticsearch/_sync/client/indices.py +1112 -677
- elasticsearch/_sync/client/inference.py +1875 -133
- elasticsearch/_sync/client/ingest.py +83 -50
- elasticsearch/_sync/client/license.py +90 -38
- elasticsearch/_sync/client/logstash.py +20 -9
- elasticsearch/_sync/client/migration.py +26 -17
- elasticsearch/_sync/client/ml.py +642 -365
- elasticsearch/_sync/client/monitoring.py +6 -3
- elasticsearch/_sync/client/nodes.py +51 -53
- elasticsearch/_sync/client/query_rules.py +59 -33
- elasticsearch/_sync/client/rollup.py +124 -86
- elasticsearch/_sync/client/search_application.py +60 -32
- elasticsearch/_sync/client/searchable_snapshots.py +25 -12
- elasticsearch/_sync/client/security.py +896 -558
- elasticsearch/_sync/client/shutdown.py +34 -36
- elasticsearch/_sync/client/simulate.py +22 -28
- elasticsearch/_sync/client/slm.py +65 -40
- elasticsearch/_sync/client/snapshot.py +190 -213
- elasticsearch/_sync/client/sql.py +43 -22
- elasticsearch/_sync/client/ssl.py +17 -18
- elasticsearch/_sync/client/synonyms.py +58 -37
- elasticsearch/_sync/client/tasks.py +77 -48
- elasticsearch/_sync/client/text_structure.py +65 -56
- elasticsearch/_sync/client/transform.py +124 -93
- elasticsearch/_sync/client/utils.py +1 -4
- elasticsearch/_sync/client/watcher.py +116 -72
- elasticsearch/_sync/client/xpack.py +18 -9
- elasticsearch/_version.py +1 -1
- elasticsearch/client.py +2 -0
- elasticsearch/dsl/__init__.py +203 -0
- elasticsearch/dsl/_async/__init__.py +16 -0
- elasticsearch/dsl/_async/document.py +522 -0
- elasticsearch/dsl/_async/faceted_search.py +50 -0
- elasticsearch/dsl/_async/index.py +639 -0
- elasticsearch/dsl/_async/mapping.py +49 -0
- elasticsearch/dsl/_async/search.py +233 -0
- elasticsearch/dsl/_async/update_by_query.py +47 -0
- elasticsearch/dsl/_sync/__init__.py +16 -0
- elasticsearch/dsl/_sync/document.py +514 -0
- elasticsearch/dsl/_sync/faceted_search.py +50 -0
- elasticsearch/dsl/_sync/index.py +597 -0
- elasticsearch/dsl/_sync/mapping.py +49 -0
- elasticsearch/dsl/_sync/search.py +226 -0
- elasticsearch/dsl/_sync/update_by_query.py +45 -0
- elasticsearch/dsl/aggs.py +3730 -0
- elasticsearch/dsl/analysis.py +341 -0
- elasticsearch/dsl/async_connections.py +37 -0
- elasticsearch/dsl/connections.py +142 -0
- elasticsearch/dsl/document.py +20 -0
- elasticsearch/dsl/document_base.py +444 -0
- elasticsearch/dsl/exceptions.py +32 -0
- elasticsearch/dsl/faceted_search.py +28 -0
- elasticsearch/dsl/faceted_search_base.py +489 -0
- elasticsearch/dsl/field.py +4254 -0
- elasticsearch/dsl/function.py +180 -0
- elasticsearch/dsl/index.py +23 -0
- elasticsearch/dsl/index_base.py +178 -0
- elasticsearch/dsl/mapping.py +19 -0
- elasticsearch/dsl/mapping_base.py +219 -0
- elasticsearch/dsl/query.py +2816 -0
- elasticsearch/dsl/response/__init__.py +388 -0
- elasticsearch/dsl/response/aggs.py +100 -0
- elasticsearch/dsl/response/hit.py +53 -0
- elasticsearch/dsl/search.py +20 -0
- elasticsearch/dsl/search_base.py +1040 -0
- elasticsearch/dsl/serializer.py +34 -0
- elasticsearch/dsl/types.py +6471 -0
- elasticsearch/dsl/update_by_query.py +19 -0
- elasticsearch/dsl/update_by_query_base.py +149 -0
- elasticsearch/dsl/utils.py +687 -0
- elasticsearch/dsl/wrappers.py +119 -0
- elasticsearch/helpers/actions.py +1 -1
- elasticsearch/helpers/vectorstore/_sync/vectorstore.py +4 -1
- {elasticsearch-8.17.1.dist-info → elasticsearch-8.18.0.dist-info}/METADATA +12 -2
- elasticsearch-8.18.0.dist-info/RECORD +161 -0
- elasticsearch-8.17.1.dist-info/RECORD +0 -119
- {elasticsearch-8.17.1.dist-info → elasticsearch-8.18.0.dist-info}/WHEEL +0 -0
- {elasticsearch-8.17.1.dist-info → elasticsearch-8.18.0.dist-info}/licenses/LICENSE +0 -0
- {elasticsearch-8.17.1.dist-info → elasticsearch-8.18.0.dist-info}/licenses/NOTICE +0 -0
|
@@ -626,6 +626,7 @@ class Elasticsearch(BaseClient):
|
|
|
626
626
|
error_trace: t.Optional[bool] = None,
|
|
627
627
|
filter_path: t.Optional[t.Union[str, t.Sequence[str]]] = None,
|
|
628
628
|
human: t.Optional[bool] = None,
|
|
629
|
+
include_source_on_error: t.Optional[bool] = None,
|
|
629
630
|
list_executed_pipelines: t.Optional[bool] = None,
|
|
630
631
|
pipeline: t.Optional[str] = None,
|
|
631
632
|
pretty: t.Optional[bool] = None,
|
|
@@ -644,89 +645,97 @@ class Elasticsearch(BaseClient):
|
|
|
644
645
|
] = None,
|
|
645
646
|
) -> ObjectApiResponse[t.Any]:
|
|
646
647
|
"""
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
648
|
+
.. raw:: html
|
|
649
|
+
|
|
650
|
+
<p>Bulk index or delete documents.
|
|
651
|
+
Perform multiple <code>index</code>, <code>create</code>, <code>delete</code>, and <code>update</code> actions in a single request.
|
|
652
|
+
This reduces overhead and can greatly increase indexing speed.</p>
|
|
653
|
+
<p>If the Elasticsearch security features are enabled, you must have the following index privileges for the target data stream, index, or index alias:</p>
|
|
654
|
+
<ul>
|
|
655
|
+
<li>To use the <code>create</code> action, you must have the <code>create_doc</code>, <code>create</code>, <code>index</code>, or <code>write</code> index privilege. Data streams support only the <code>create</code> action.</li>
|
|
656
|
+
<li>To use the <code>index</code> action, you must have the <code>create</code>, <code>index</code>, or <code>write</code> index privilege.</li>
|
|
657
|
+
<li>To use the <code>delete</code> action, you must have the <code>delete</code> or <code>write</code> index privilege.</li>
|
|
658
|
+
<li>To use the <code>update</code> action, you must have the <code>index</code> or <code>write</code> index privilege.</li>
|
|
659
|
+
<li>To automatically create a data stream or index with a bulk API request, you must have the <code>auto_configure</code>, <code>create_index</code>, or <code>manage</code> index privilege.</li>
|
|
660
|
+
<li>To make the result of a bulk operation visible to search using the <code>refresh</code> parameter, you must have the <code>maintenance</code> or <code>manage</code> index privilege.</li>
|
|
661
|
+
</ul>
|
|
662
|
+
<p>Automatic data stream creation requires a matching index template with data stream enabled.</p>
|
|
663
|
+
<p>The actions are specified in the request body using a newline delimited JSON (NDJSON) structure:</p>
|
|
664
|
+
<pre><code>action_and_meta_data\\n
|
|
665
|
+
optional_source\\n
|
|
666
|
+
action_and_meta_data\\n
|
|
667
|
+
optional_source\\n
|
|
668
|
+
....
|
|
669
|
+
action_and_meta_data\\n
|
|
670
|
+
optional_source\\n
|
|
671
|
+
</code></pre>
|
|
672
|
+
<p>The <code>index</code> and <code>create</code> actions expect a source on the next line and have the same semantics as the <code>op_type</code> parameter in the standard index API.
|
|
673
|
+
A <code>create</code> action fails if a document with the same ID already exists in the target
|
|
674
|
+
An <code>index</code> action adds or replaces a document as necessary.</p>
|
|
675
|
+
<p>NOTE: Data streams support only the <code>create</code> action.
|
|
676
|
+
To update or delete a document in a data stream, you must target the backing index containing the document.</p>
|
|
677
|
+
<p>An <code>update</code> action expects that the partial doc, upsert, and script and its options are specified on the next line.</p>
|
|
678
|
+
<p>A <code>delete</code> action does not expect a source on the next line and has the same semantics as the standard delete API.</p>
|
|
679
|
+
<p>NOTE: The final line of data must end with a newline character (<code>\\n</code>).
|
|
680
|
+
Each newline character may be preceded by a carriage return (<code>\\r</code>).
|
|
681
|
+
When sending NDJSON data to the <code>_bulk</code> endpoint, use a <code>Content-Type</code> header of <code>application/json</code> or <code>application/x-ndjson</code>.
|
|
682
|
+
Because this format uses literal newline characters (<code>\\n</code>) as delimiters, make sure that the JSON actions and sources are not pretty printed.</p>
|
|
683
|
+
<p>If you provide a target in the request path, it is used for any actions that don't explicitly specify an <code>_index</code> argument.</p>
|
|
684
|
+
<p>A note on the format: the idea here is to make processing as fast as possible.
|
|
685
|
+
As some of the actions are redirected to other shards on other nodes, only <code>action_meta_data</code> is parsed on the receiving node side.</p>
|
|
686
|
+
<p>Client libraries using this protocol should try and strive to do something similar on the client side, and reduce buffering as much as possible.</p>
|
|
687
|
+
<p>There is no "correct" number of actions to perform in a single bulk request.
|
|
688
|
+
Experiment with different settings to find the optimal size for your particular workload.
|
|
689
|
+
Note that Elasticsearch limits the maximum size of a HTTP request to 100mb by default so clients must ensure that no request exceeds this size.
|
|
690
|
+
It is not possible to index a single document that exceeds the size limit, so you must pre-process any such documents into smaller pieces before sending them to Elasticsearch.
|
|
691
|
+
For instance, split documents into pages or chapters before indexing them, or store raw binary data in a system outside Elasticsearch and replace the raw data with a link to the external system in the documents that you send to Elasticsearch.</p>
|
|
692
|
+
<p><strong>Client suppport for bulk requests</strong></p>
|
|
693
|
+
<p>Some of the officially supported clients provide helpers to assist with bulk requests and reindexing:</p>
|
|
694
|
+
<ul>
|
|
695
|
+
<li>Go: Check out <code>esutil.BulkIndexer</code></li>
|
|
696
|
+
<li>Perl: Check out <code>Search::Elasticsearch::Client::5_0::Bulk</code> and <code>Search::Elasticsearch::Client::5_0::Scroll</code></li>
|
|
697
|
+
<li>Python: Check out <code>elasticsearch.helpers.*</code></li>
|
|
698
|
+
<li>JavaScript: Check out <code>client.helpers.*</code></li>
|
|
699
|
+
<li>.NET: Check out <code>BulkAllObservable</code></li>
|
|
700
|
+
<li>PHP: Check out bulk indexing.</li>
|
|
701
|
+
</ul>
|
|
702
|
+
<p><strong>Submitting bulk requests with cURL</strong></p>
|
|
703
|
+
<p>If you're providing text file input to <code>curl</code>, you must use the <code>--data-binary</code> flag instead of plain <code>-d</code>.
|
|
704
|
+
The latter doesn't preserve newlines. For example:</p>
|
|
705
|
+
<pre><code>$ cat requests
|
|
706
|
+
{ "index" : { "_index" : "test", "_id" : "1" } }
|
|
707
|
+
{ "field1" : "value1" }
|
|
708
|
+
$ curl -s -H "Content-Type: application/x-ndjson" -XPOST localhost:9200/_bulk --data-binary "@requests"; echo
|
|
709
|
+
{"took":7, "errors": false, "items":[{"index":{"_index":"test","_id":"1","_version":1,"result":"created","forced_refresh":false}}]}
|
|
710
|
+
</code></pre>
|
|
711
|
+
<p><strong>Optimistic concurrency control</strong></p>
|
|
712
|
+
<p>Each <code>index</code> and <code>delete</code> action within a bulk API call may include the <code>if_seq_no</code> and <code>if_primary_term</code> parameters in their respective action and meta data lines.
|
|
713
|
+
The <code>if_seq_no</code> and <code>if_primary_term</code> parameters control how operations are run, based on the last modification to existing documents. See Optimistic concurrency control for more details.</p>
|
|
714
|
+
<p><strong>Versioning</strong></p>
|
|
715
|
+
<p>Each bulk item can include the version value using the <code>version</code> field.
|
|
716
|
+
It automatically follows the behavior of the index or delete operation based on the <code>_version</code> mapping.
|
|
717
|
+
It also support the <code>version_type</code>.</p>
|
|
718
|
+
<p><strong>Routing</strong></p>
|
|
719
|
+
<p>Each bulk item can include the routing value using the <code>routing</code> field.
|
|
720
|
+
It automatically follows the behavior of the index or delete operation based on the <code>_routing</code> mapping.</p>
|
|
721
|
+
<p>NOTE: Data streams do not support custom routing unless they were created with the <code>allow_custom_routing</code> setting enabled in the template.</p>
|
|
722
|
+
<p><strong>Wait for active shards</strong></p>
|
|
723
|
+
<p>When making bulk calls, you can set the <code>wait_for_active_shards</code> parameter to require a minimum number of shard copies to be active before starting to process the bulk request.</p>
|
|
724
|
+
<p><strong>Refresh</strong></p>
|
|
725
|
+
<p>Control when the changes made by this request are visible to search.</p>
|
|
726
|
+
<p>NOTE: Only the shards that receive the bulk request will be affected by refresh.
|
|
727
|
+
Imagine a <code>_bulk?refresh=wait_for</code> request with three documents in it that happen to be routed to different shards in an index with five shards.
|
|
728
|
+
The request will only wait for those three shards to refresh.
|
|
729
|
+
The other two shards that make up the index do not participate in the <code>_bulk</code> request at all.</p>
|
|
730
|
+
|
|
731
|
+
|
|
732
|
+
`<https://www.elastic.co/guide/en/elasticsearch/reference/8.18/docs-bulk.html>`_
|
|
726
733
|
|
|
727
734
|
:param operations:
|
|
728
735
|
:param index: The name of the data stream, index, or index alias to perform bulk
|
|
729
736
|
actions on.
|
|
737
|
+
:param include_source_on_error: True or false if to include the document source
|
|
738
|
+
in the error message in case of parsing errors.
|
|
730
739
|
:param list_executed_pipelines: If `true`, the response will include the ingest
|
|
731
740
|
pipelines that were run for each index or create.
|
|
732
741
|
:param pipeline: The pipeline identifier to use to preprocess incoming documents.
|
|
@@ -784,6 +793,8 @@ class Elasticsearch(BaseClient):
|
|
|
784
793
|
__query["filter_path"] = filter_path
|
|
785
794
|
if human is not None:
|
|
786
795
|
__query["human"] = human
|
|
796
|
+
if include_source_on_error is not None:
|
|
797
|
+
__query["include_source_on_error"] = include_source_on_error
|
|
787
798
|
if list_executed_pipelines is not None:
|
|
788
799
|
__query["list_executed_pipelines"] = list_executed_pipelines
|
|
789
800
|
if pipeline is not None:
|
|
@@ -837,10 +848,13 @@ class Elasticsearch(BaseClient):
|
|
|
837
848
|
body: t.Optional[t.Dict[str, t.Any]] = None,
|
|
838
849
|
) -> ObjectApiResponse[t.Any]:
|
|
839
850
|
"""
|
|
840
|
-
|
|
841
|
-
search.
|
|
851
|
+
.. raw:: html
|
|
842
852
|
|
|
843
|
-
|
|
853
|
+
<p>Clear a scrolling search.
|
|
854
|
+
Clear the search context and results for a scrolling search.</p>
|
|
855
|
+
|
|
856
|
+
|
|
857
|
+
`<https://www.elastic.co/guide/en/elasticsearch/reference/8.18/clear-scroll-api.html>`_
|
|
844
858
|
|
|
845
859
|
:param scroll_id: The scroll IDs to clear. To clear all scroll IDs, use `_all`.
|
|
846
860
|
"""
|
|
@@ -888,13 +902,16 @@ class Elasticsearch(BaseClient):
|
|
|
888
902
|
body: t.Optional[t.Dict[str, t.Any]] = None,
|
|
889
903
|
) -> ObjectApiResponse[t.Any]:
|
|
890
904
|
"""
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
905
|
+
.. raw:: html
|
|
906
|
+
|
|
907
|
+
<p>Close a point in time.
|
|
908
|
+
A point in time must be opened explicitly before being used in search requests.
|
|
909
|
+
The <code>keep_alive</code> parameter tells Elasticsearch how long it should persist.
|
|
910
|
+
A point in time is automatically closed when the <code>keep_alive</code> period has elapsed.
|
|
911
|
+
However, keeping points in time has a cost; close them as soon as they are no longer required for search requests.</p>
|
|
912
|
+
|
|
896
913
|
|
|
897
|
-
`<https://www.elastic.co/guide/en/elasticsearch/reference/8.
|
|
914
|
+
`<https://www.elastic.co/guide/en/elasticsearch/reference/8.18/point-in-time-api.html>`_
|
|
898
915
|
|
|
899
916
|
:param id: The ID of the point-in-time.
|
|
900
917
|
"""
|
|
@@ -966,16 +983,19 @@ class Elasticsearch(BaseClient):
|
|
|
966
983
|
body: t.Optional[t.Dict[str, t.Any]] = None,
|
|
967
984
|
) -> ObjectApiResponse[t.Any]:
|
|
968
985
|
"""
|
|
969
|
-
|
|
970
|
-
can either be provided using a simple query string as a parameter or using the
|
|
971
|
-
Query DSL defined within the request body. The latter must be nested in a `query`
|
|
972
|
-
key, which is the same as the search API. The count API supports multi-target
|
|
973
|
-
syntax. You can run a single count API search across multiple data streams and
|
|
974
|
-
indices. The operation is broadcast across all shards. For each shard ID group,
|
|
975
|
-
a replica is chosen and the search is run against it. This means that replicas
|
|
976
|
-
increase the scalability of the count.
|
|
986
|
+
.. raw:: html
|
|
977
987
|
|
|
978
|
-
|
|
988
|
+
<p>Count search results.
|
|
989
|
+
Get the number of documents matching a query.</p>
|
|
990
|
+
<p>The query can be provided either by using a simple query string as a parameter, or by defining Query DSL within the request body.
|
|
991
|
+
The query is optional. When no query is provided, the API uses <code>match_all</code> to count all the documents.</p>
|
|
992
|
+
<p>The count API supports multi-target syntax. You can run a single count API search across multiple data streams and indices.</p>
|
|
993
|
+
<p>The operation is broadcast across all shards.
|
|
994
|
+
For each shard ID group, a replica is chosen and the search is run against it.
|
|
995
|
+
This means that replicas increase the scalability of the count.</p>
|
|
996
|
+
|
|
997
|
+
|
|
998
|
+
`<https://www.elastic.co/guide/en/elasticsearch/reference/8.18/search-count.html>`_
|
|
979
999
|
|
|
980
1000
|
:param index: A comma-separated list of data streams, indices, and aliases to
|
|
981
1001
|
search. It supports wildcards (`*`). To search all data streams and indices,
|
|
@@ -1010,10 +1030,10 @@ class Elasticsearch(BaseClient):
|
|
|
1010
1030
|
in the result.
|
|
1011
1031
|
:param preference: The node or shard the operation should be performed on. By
|
|
1012
1032
|
default, it is random.
|
|
1013
|
-
:param q: The query in Lucene query string syntax.
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1033
|
+
:param q: The query in Lucene query string syntax. This parameter cannot be used
|
|
1034
|
+
with a request body.
|
|
1035
|
+
:param query: Defines the search query using Query DSL. A request body query
|
|
1036
|
+
cannot be used with the `q` query string parameter.
|
|
1017
1037
|
:param routing: A custom value used to route operations to a specific shard.
|
|
1018
1038
|
:param terminate_after: The maximum number of documents to collect for each shard.
|
|
1019
1039
|
If a query reaches this limit, Elasticsearch terminates the query early.
|
|
@@ -1099,11 +1119,17 @@ class Elasticsearch(BaseClient):
|
|
|
1099
1119
|
error_trace: t.Optional[bool] = None,
|
|
1100
1120
|
filter_path: t.Optional[t.Union[str, t.Sequence[str]]] = None,
|
|
1101
1121
|
human: t.Optional[bool] = None,
|
|
1122
|
+
if_primary_term: t.Optional[int] = None,
|
|
1123
|
+
if_seq_no: t.Optional[int] = None,
|
|
1124
|
+
include_source_on_error: t.Optional[bool] = None,
|
|
1125
|
+
op_type: t.Optional[t.Union[str, t.Literal["create", "index"]]] = None,
|
|
1102
1126
|
pipeline: t.Optional[str] = None,
|
|
1103
1127
|
pretty: t.Optional[bool] = None,
|
|
1104
1128
|
refresh: t.Optional[
|
|
1105
1129
|
t.Union[bool, str, t.Literal["false", "true", "wait_for"]]
|
|
1106
1130
|
] = None,
|
|
1131
|
+
require_alias: t.Optional[bool] = None,
|
|
1132
|
+
require_data_stream: t.Optional[bool] = None,
|
|
1107
1133
|
routing: t.Optional[str] = None,
|
|
1108
1134
|
timeout: t.Optional[t.Union[str, t.Literal[-1], t.Literal[0]]] = None,
|
|
1109
1135
|
version: t.Optional[int] = None,
|
|
@@ -1115,38 +1141,115 @@ class Elasticsearch(BaseClient):
|
|
|
1115
1141
|
] = None,
|
|
1116
1142
|
) -> ObjectApiResponse[t.Any]:
|
|
1117
1143
|
"""
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1144
|
+
.. raw:: html
|
|
1145
|
+
|
|
1146
|
+
<p>Create a new document in the index.</p>
|
|
1147
|
+
<p>You can index a new JSON document with the <code>/<target>/_doc/</code> or <code>/<target>/_create/<_id></code> APIs
|
|
1148
|
+
Using <code>_create</code> guarantees that the document is indexed only if it does not already exist.
|
|
1149
|
+
It returns a 409 response when a document with a same ID already exists in the index.
|
|
1150
|
+
To update an existing document, you must use the <code>/<target>/_doc/</code> API.</p>
|
|
1151
|
+
<p>If the Elasticsearch security features are enabled, you must have the following index privileges for the target data stream, index, or index alias:</p>
|
|
1152
|
+
<ul>
|
|
1153
|
+
<li>To add a document using the <code>PUT /<target>/_create/<_id></code> or <code>POST /<target>/_create/<_id></code> request formats, you must have the <code>create_doc</code>, <code>create</code>, <code>index</code>, or <code>write</code> index privilege.</li>
|
|
1154
|
+
<li>To automatically create a data stream or index with this API request, you must have the <code>auto_configure</code>, <code>create_index</code>, or <code>manage</code> index privilege.</li>
|
|
1155
|
+
</ul>
|
|
1156
|
+
<p>Automatic data stream creation requires a matching index template with data stream enabled.</p>
|
|
1157
|
+
<p><strong>Automatically create data streams and indices</strong></p>
|
|
1158
|
+
<p>If the request's target doesn't exist and matches an index template with a <code>data_stream</code> definition, the index operation automatically creates the data stream.</p>
|
|
1159
|
+
<p>If the target doesn't exist and doesn't match a data stream template, the operation automatically creates the index and applies any matching index templates.</p>
|
|
1160
|
+
<p>NOTE: Elasticsearch includes several built-in index templates. To avoid naming collisions with these templates, refer to index pattern documentation.</p>
|
|
1161
|
+
<p>If no mapping exists, the index operation creates a dynamic mapping.
|
|
1162
|
+
By default, new fields and objects are automatically added to the mapping if needed.</p>
|
|
1163
|
+
<p>Automatic index creation is controlled by the <code>action.auto_create_index</code> setting.
|
|
1164
|
+
If it is <code>true</code>, any index can be created automatically.
|
|
1165
|
+
You can modify this setting to explicitly allow or block automatic creation of indices that match specified patterns or set it to <code>false</code> to turn off automatic index creation entirely.
|
|
1166
|
+
Specify a comma-separated list of patterns you want to allow or prefix each pattern with <code>+</code> or <code>-</code> to indicate whether it should be allowed or blocked.
|
|
1167
|
+
When a list is specified, the default behaviour is to disallow.</p>
|
|
1168
|
+
<p>NOTE: The <code>action.auto_create_index</code> setting affects the automatic creation of indices only.
|
|
1169
|
+
It does not affect the creation of data streams.</p>
|
|
1170
|
+
<p><strong>Routing</strong></p>
|
|
1171
|
+
<p>By default, shard placement — or routing — is controlled by using a hash of the document's ID value.
|
|
1172
|
+
For more explicit control, the value fed into the hash function used by the router can be directly specified on a per-operation basis using the <code>routing</code> parameter.</p>
|
|
1173
|
+
<p>When setting up explicit mapping, you can also use the <code>_routing</code> field to direct the index operation to extract the routing value from the document itself.
|
|
1174
|
+
This does come at the (very minimal) cost of an additional document parsing pass.
|
|
1175
|
+
If the <code>_routing</code> mapping is defined and set to be required, the index operation will fail if no routing value is provided or extracted.</p>
|
|
1176
|
+
<p>NOTE: Data streams do not support custom routing unless they were created with the <code>allow_custom_routing</code> setting enabled in the template.</p>
|
|
1177
|
+
<p><strong>Distributed</strong></p>
|
|
1178
|
+
<p>The index operation is directed to the primary shard based on its route and performed on the actual node containing this shard.
|
|
1179
|
+
After the primary shard completes the operation, if needed, the update is distributed to applicable replicas.</p>
|
|
1180
|
+
<p><strong>Active shards</strong></p>
|
|
1181
|
+
<p>To improve the resiliency of writes to the system, indexing operations can be configured to wait for a certain number of active shard copies before proceeding with the operation.
|
|
1182
|
+
If the requisite number of active shard copies are not available, then the write operation must wait and retry, until either the requisite shard copies have started or a timeout occurs.
|
|
1183
|
+
By default, write operations only wait for the primary shards to be active before proceeding (that is to say <code>wait_for_active_shards</code> is <code>1</code>).
|
|
1184
|
+
This default can be overridden in the index settings dynamically by setting <code>index.write.wait_for_active_shards</code>.
|
|
1185
|
+
To alter this behavior per operation, use the <code>wait_for_active_shards request</code> parameter.</p>
|
|
1186
|
+
<p>Valid values are all or any positive integer up to the total number of configured copies per shard in the index (which is <code>number_of_replicas</code>+1).
|
|
1187
|
+
Specifying a negative value or a number greater than the number of shard copies will throw an error.</p>
|
|
1188
|
+
<p>For example, suppose you have a cluster of three nodes, A, B, and C and you create an index index with the number of replicas set to 3 (resulting in 4 shard copies, one more copy than there are nodes).
|
|
1189
|
+
If you attempt an indexing operation, by default the operation will only ensure the primary copy of each shard is available before proceeding.
|
|
1190
|
+
This means that even if B and C went down and A hosted the primary shard copies, the indexing operation would still proceed with only one copy of the data.
|
|
1191
|
+
If <code>wait_for_active_shards</code> is set on the request to <code>3</code> (and all three nodes are up), the indexing operation will require 3 active shard copies before proceeding.
|
|
1192
|
+
This requirement should be met because there are 3 active nodes in the cluster, each one holding a copy of the shard.
|
|
1193
|
+
However, if you set <code>wait_for_active_shards</code> to <code>all</code> (or to <code>4</code>, which is the same in this situation), the indexing operation will not proceed as you do not have all 4 copies of each shard active in the index.
|
|
1194
|
+
The operation will timeout unless a new node is brought up in the cluster to host the fourth copy of the shard.</p>
|
|
1195
|
+
<p>It is important to note that this setting greatly reduces the chances of the write operation not writing to the requisite number of shard copies, but it does not completely eliminate the possibility, because this check occurs before the write operation starts.
|
|
1196
|
+
After the write operation is underway, it is still possible for replication to fail on any number of shard copies but still succeed on the primary.
|
|
1197
|
+
The <code>_shards</code> section of the API response reveals the number of shard copies on which replication succeeded and failed.</p>
|
|
1198
|
+
|
|
1199
|
+
|
|
1200
|
+
`<https://www.elastic.co/guide/en/elasticsearch/reference/8.18/docs-index_.html>`_
|
|
1201
|
+
|
|
1202
|
+
:param index: The name of the data stream or index to target. If the target doesn't
|
|
1125
1203
|
exist and matches the name or wildcard (`*`) pattern of an index template
|
|
1126
1204
|
with a `data_stream` definition, this request creates the data stream. If
|
|
1127
|
-
the target doesn
|
|
1205
|
+
the target doesn't exist and doesn’t match a data stream template, this request
|
|
1128
1206
|
creates the index.
|
|
1129
|
-
:param id:
|
|
1207
|
+
:param id: A unique identifier for the document. To automatically generate a
|
|
1208
|
+
document ID, use the `POST /<target>/_doc/` request format.
|
|
1130
1209
|
:param document:
|
|
1131
|
-
:param
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1210
|
+
:param if_primary_term: Only perform the operation if the document has this primary
|
|
1211
|
+
term.
|
|
1212
|
+
:param if_seq_no: Only perform the operation if the document has this sequence
|
|
1213
|
+
number.
|
|
1214
|
+
:param include_source_on_error: True or false if to include the document source
|
|
1215
|
+
in the error message in case of parsing errors.
|
|
1216
|
+
:param op_type: Set to `create` to only index the document if it does not already
|
|
1217
|
+
exist (put if absent). If a document with the specified `_id` already exists,
|
|
1218
|
+
the indexing operation will fail. The behavior is the same as using the `<index>/_create`
|
|
1219
|
+
endpoint. If a document ID is specified, this paramater defaults to `index`.
|
|
1220
|
+
Otherwise, it defaults to `create`. If the request targets a data stream,
|
|
1221
|
+
an `op_type` of `create` is required.
|
|
1222
|
+
:param pipeline: The ID of the pipeline to use to preprocess incoming documents.
|
|
1223
|
+
If the index has a default ingest pipeline specified, setting the value to
|
|
1224
|
+
`_none` turns off the default ingest pipeline for this request. If a final
|
|
1225
|
+
pipeline is configured, it will always run regardless of the value of this
|
|
1135
1226
|
parameter.
|
|
1136
1227
|
:param refresh: If `true`, Elasticsearch refreshes the affected shards to make
|
|
1137
|
-
this operation visible to search
|
|
1138
|
-
make this operation visible to search
|
|
1139
|
-
|
|
1140
|
-
:param
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1228
|
+
this operation visible to search. If `wait_for`, it waits for a refresh to
|
|
1229
|
+
make this operation visible to search. If `false`, it does nothing with refreshes.
|
|
1230
|
+
:param require_alias: If `true`, the destination must be an index alias.
|
|
1231
|
+
:param require_data_stream: If `true`, the request's actions must target a data
|
|
1232
|
+
stream (existing or to be created).
|
|
1233
|
+
:param routing: A custom value that is used to route operations to a specific
|
|
1234
|
+
shard.
|
|
1235
|
+
:param timeout: The period the request waits for the following operations: automatic
|
|
1236
|
+
index creation, dynamic mapping updates, waiting for active shards. Elasticsearch
|
|
1237
|
+
waits for at least the specified timeout period before failing. The actual
|
|
1238
|
+
wait time could be longer, particularly when multiple waits occur. This parameter
|
|
1239
|
+
is useful for situations where the primary shard assigned to perform the
|
|
1240
|
+
operation might not be available when the operation runs. Some reasons for
|
|
1241
|
+
this might be that the primary shard is currently recovering from a gateway
|
|
1242
|
+
or undergoing relocation. By default, the operation will wait on the primary
|
|
1243
|
+
shard to become available for at least 1 minute before failing and responding
|
|
1244
|
+
with an error. The actual wait time could be longer, particularly when multiple
|
|
1245
|
+
waits occur.
|
|
1246
|
+
:param version: The explicit version number for concurrency control. It must
|
|
1247
|
+
be a non-negative long number.
|
|
1248
|
+
:param version_type: The version type.
|
|
1147
1249
|
:param wait_for_active_shards: The number of shard copies that must be active
|
|
1148
|
-
before proceeding with the operation.
|
|
1149
|
-
up to the total number of shards in the index (`number_of_replicas+1`).
|
|
1250
|
+
before proceeding with the operation. You can set it to `all` or any positive
|
|
1251
|
+
integer up to the total number of shards in the index (`number_of_replicas+1`).
|
|
1252
|
+
The default value of `1` means it waits for each primary shard to be active.
|
|
1150
1253
|
"""
|
|
1151
1254
|
if index in SKIP_IN_PATH:
|
|
1152
1255
|
raise ValueError("Empty value passed for parameter 'index'")
|
|
@@ -1167,12 +1270,24 @@ class Elasticsearch(BaseClient):
|
|
|
1167
1270
|
__query["filter_path"] = filter_path
|
|
1168
1271
|
if human is not None:
|
|
1169
1272
|
__query["human"] = human
|
|
1273
|
+
if if_primary_term is not None:
|
|
1274
|
+
__query["if_primary_term"] = if_primary_term
|
|
1275
|
+
if if_seq_no is not None:
|
|
1276
|
+
__query["if_seq_no"] = if_seq_no
|
|
1277
|
+
if include_source_on_error is not None:
|
|
1278
|
+
__query["include_source_on_error"] = include_source_on_error
|
|
1279
|
+
if op_type is not None:
|
|
1280
|
+
__query["op_type"] = op_type
|
|
1170
1281
|
if pipeline is not None:
|
|
1171
1282
|
__query["pipeline"] = pipeline
|
|
1172
1283
|
if pretty is not None:
|
|
1173
1284
|
__query["pretty"] = pretty
|
|
1174
1285
|
if refresh is not None:
|
|
1175
1286
|
__query["refresh"] = refresh
|
|
1287
|
+
if require_alias is not None:
|
|
1288
|
+
__query["require_alias"] = require_alias
|
|
1289
|
+
if require_data_stream is not None:
|
|
1290
|
+
__query["require_data_stream"] = require_data_stream
|
|
1176
1291
|
if routing is not None:
|
|
1177
1292
|
__query["routing"] = routing
|
|
1178
1293
|
if timeout is not None:
|
|
@@ -1221,29 +1336,60 @@ class Elasticsearch(BaseClient):
|
|
|
1221
1336
|
] = None,
|
|
1222
1337
|
) -> ObjectApiResponse[t.Any]:
|
|
1223
1338
|
"""
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1339
|
+
.. raw:: html
|
|
1340
|
+
|
|
1341
|
+
<p>Delete a document.</p>
|
|
1342
|
+
<p>Remove a JSON document from the specified index.</p>
|
|
1343
|
+
<p>NOTE: You cannot send deletion requests directly to a data stream.
|
|
1344
|
+
To delete a document in a data stream, you must target the backing index containing the document.</p>
|
|
1345
|
+
<p><strong>Optimistic concurrency control</strong></p>
|
|
1346
|
+
<p>Delete operations can be made conditional and only be performed if the last modification to the document was assigned the sequence number and primary term specified by the <code>if_seq_no</code> and <code>if_primary_term</code> parameters.
|
|
1347
|
+
If a mismatch is detected, the operation will result in a <code>VersionConflictException</code> and a status code of <code>409</code>.</p>
|
|
1348
|
+
<p><strong>Versioning</strong></p>
|
|
1349
|
+
<p>Each document indexed is versioned.
|
|
1350
|
+
When deleting a document, the version can be specified to make sure the relevant document you are trying to delete is actually being deleted and it has not changed in the meantime.
|
|
1351
|
+
Every write operation run on a document, deletes included, causes its version to be incremented.
|
|
1352
|
+
The version number of a deleted document remains available for a short time after deletion to allow for control of concurrent operations.
|
|
1353
|
+
The length of time for which a deleted document's version remains available is determined by the <code>index.gc_deletes</code> index setting.</p>
|
|
1354
|
+
<p><strong>Routing</strong></p>
|
|
1355
|
+
<p>If routing is used during indexing, the routing value also needs to be specified to delete a document.</p>
|
|
1356
|
+
<p>If the <code>_routing</code> mapping is set to <code>required</code> and no routing value is specified, the delete API throws a <code>RoutingMissingException</code> and rejects the request.</p>
|
|
1357
|
+
<p>For example:</p>
|
|
1358
|
+
<pre><code>DELETE /my-index-000001/_doc/1?routing=shard-1
|
|
1359
|
+
</code></pre>
|
|
1360
|
+
<p>This request deletes the document with ID 1, but it is routed based on the user.
|
|
1361
|
+
The document is not deleted if the correct routing is not specified.</p>
|
|
1362
|
+
<p><strong>Distributed</strong></p>
|
|
1363
|
+
<p>The delete operation gets hashed into a specific shard ID.
|
|
1364
|
+
It then gets redirected into the primary shard within that ID group and replicated (if needed) to shard replicas within that ID group.</p>
|
|
1365
|
+
|
|
1366
|
+
|
|
1367
|
+
`<https://www.elastic.co/guide/en/elasticsearch/reference/8.18/docs-delete.html>`_
|
|
1368
|
+
|
|
1369
|
+
:param index: The name of the target index.
|
|
1370
|
+
:param id: A unique identifier for the document.
|
|
1230
1371
|
:param if_primary_term: Only perform the operation if the document has this primary
|
|
1231
1372
|
term.
|
|
1232
1373
|
:param if_seq_no: Only perform the operation if the document has this sequence
|
|
1233
1374
|
number.
|
|
1234
1375
|
:param refresh: If `true`, Elasticsearch refreshes the affected shards to make
|
|
1235
|
-
this operation visible to search
|
|
1236
|
-
make this operation visible to search
|
|
1237
|
-
|
|
1238
|
-
:param
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1376
|
+
this operation visible to search. If `wait_for`, it waits for a refresh to
|
|
1377
|
+
make this operation visible to search. If `false`, it does nothing with refreshes.
|
|
1378
|
+
:param routing: A custom value used to route operations to a specific shard.
|
|
1379
|
+
:param timeout: The period to wait for active shards. This parameter is useful
|
|
1380
|
+
for situations where the primary shard assigned to perform the delete operation
|
|
1381
|
+
might not be available when the delete operation runs. Some reasons for this
|
|
1382
|
+
might be that the primary shard is currently recovering from a store or undergoing
|
|
1383
|
+
relocation. By default, the delete operation will wait on the primary shard
|
|
1384
|
+
to become available for up to 1 minute before failing and responding with
|
|
1385
|
+
an error.
|
|
1386
|
+
:param version: An explicit version number for concurrency control. It must match
|
|
1387
|
+
the current version of the document for the request to succeed.
|
|
1388
|
+
:param version_type: The version type.
|
|
1389
|
+
:param wait_for_active_shards: The minimum number of shard copies that must be
|
|
1390
|
+
active before proceeding with the operation. You can set it to `all` or any
|
|
1391
|
+
positive integer up to the total number of shards in the index (`number_of_replicas+1`).
|
|
1392
|
+
The default value of `1` means it waits for each primary shard to be active.
|
|
1247
1393
|
"""
|
|
1248
1394
|
if index in SKIP_IN_PATH:
|
|
1249
1395
|
raise ValueError("Empty value passed for parameter 'index'")
|
|
@@ -1343,72 +1489,148 @@ class Elasticsearch(BaseClient):
|
|
|
1343
1489
|
body: t.Optional[t.Dict[str, t.Any]] = None,
|
|
1344
1490
|
) -> ObjectApiResponse[t.Any]:
|
|
1345
1491
|
"""
|
|
1346
|
-
|
|
1492
|
+
.. raw:: html
|
|
1493
|
+
|
|
1494
|
+
<p>Delete documents.</p>
|
|
1495
|
+
<p>Deletes documents that match the specified query.</p>
|
|
1496
|
+
<p>If the Elasticsearch security features are enabled, you must have the following index privileges for the target data stream, index, or alias:</p>
|
|
1497
|
+
<ul>
|
|
1498
|
+
<li><code>read</code></li>
|
|
1499
|
+
<li><code>delete</code> or <code>write</code></li>
|
|
1500
|
+
</ul>
|
|
1501
|
+
<p>You can specify the query criteria in the request URI or the request body using the same syntax as the search API.
|
|
1502
|
+
When you submit a delete by query request, Elasticsearch gets a snapshot of the data stream or index when it begins processing the request and deletes matching documents using internal versioning.
|
|
1503
|
+
If a document changes between the time that the snapshot is taken and the delete operation is processed, it results in a version conflict and the delete operation fails.</p>
|
|
1504
|
+
<p>NOTE: Documents with a version equal to 0 cannot be deleted using delete by query because internal versioning does not support 0 as a valid version number.</p>
|
|
1505
|
+
<p>While processing a delete by query request, Elasticsearch performs multiple search requests sequentially to find all of the matching documents to delete.
|
|
1506
|
+
A bulk delete request is performed for each batch of matching documents.
|
|
1507
|
+
If a search or bulk request is rejected, the requests are retried up to 10 times, with exponential back off.
|
|
1508
|
+
If the maximum retry limit is reached, processing halts and all failed requests are returned in the response.
|
|
1509
|
+
Any delete requests that completed successfully still stick, they are not rolled back.</p>
|
|
1510
|
+
<p>You can opt to count version conflicts instead of halting and returning by setting <code>conflicts</code> to <code>proceed</code>.
|
|
1511
|
+
Note that if you opt to count version conflicts the operation could attempt to delete more documents from the source than <code>max_docs</code> until it has successfully deleted <code>max_docs documents</code>, or it has gone through every document in the source query.</p>
|
|
1512
|
+
<p><strong>Throttling delete requests</strong></p>
|
|
1513
|
+
<p>To control the rate at which delete by query issues batches of delete operations, you can set <code>requests_per_second</code> to any positive decimal number.
|
|
1514
|
+
This pads each batch with a wait time to throttle the rate.
|
|
1515
|
+
Set <code>requests_per_second</code> to <code>-1</code> to disable throttling.</p>
|
|
1516
|
+
<p>Throttling uses a wait time between batches so that the internal scroll requests can be given a timeout that takes the request padding into account.
|
|
1517
|
+
The padding time is the difference between the batch size divided by the <code>requests_per_second</code> and the time spent writing.
|
|
1518
|
+
By default the batch size is <code>1000</code>, so if <code>requests_per_second</code> is set to <code>500</code>:</p>
|
|
1519
|
+
<pre><code>target_time = 1000 / 500 per second = 2 seconds
|
|
1520
|
+
wait_time = target_time - write_time = 2 seconds - .5 seconds = 1.5 seconds
|
|
1521
|
+
</code></pre>
|
|
1522
|
+
<p>Since the batch is issued as a single <code>_bulk</code> request, large batch sizes cause Elasticsearch to create many requests and wait before starting the next set.
|
|
1523
|
+
This is "bursty" instead of "smooth".</p>
|
|
1524
|
+
<p><strong>Slicing</strong></p>
|
|
1525
|
+
<p>Delete by query supports sliced scroll to parallelize the delete process.
|
|
1526
|
+
This can improve efficiency and provide a convenient way to break the request down into smaller parts.</p>
|
|
1527
|
+
<p>Setting <code>slices</code> to <code>auto</code> lets Elasticsearch choose the number of slices to use.
|
|
1528
|
+
This setting will use one slice per shard, up to a certain limit.
|
|
1529
|
+
If there are multiple source data streams or indices, it will choose the number of slices based on the index or backing index with the smallest number of shards.
|
|
1530
|
+
Adding slices to the delete by query operation creates sub-requests which means it has some quirks:</p>
|
|
1531
|
+
<ul>
|
|
1532
|
+
<li>You can see these requests in the tasks APIs. These sub-requests are "child" tasks of the task for the request with slices.</li>
|
|
1533
|
+
<li>Fetching the status of the task for the request with slices only contains the status of completed slices.</li>
|
|
1534
|
+
<li>These sub-requests are individually addressable for things like cancellation and rethrottling.</li>
|
|
1535
|
+
<li>Rethrottling the request with <code>slices</code> will rethrottle the unfinished sub-request proportionally.</li>
|
|
1536
|
+
<li>Canceling the request with <code>slices</code> will cancel each sub-request.</li>
|
|
1537
|
+
<li>Due to the nature of <code>slices</code> each sub-request won't get a perfectly even portion of the documents. All documents will be addressed, but some slices may be larger than others. Expect larger slices to have a more even distribution.</li>
|
|
1538
|
+
<li>Parameters like <code>requests_per_second</code> and <code>max_docs</code> on a request with <code>slices</code> are distributed proportionally to each sub-request. Combine that with the earlier point about distribution being uneven and you should conclude that using <code>max_docs</code> with <code>slices</code> might not result in exactly <code>max_docs</code> documents being deleted.</li>
|
|
1539
|
+
<li>Each sub-request gets a slightly different snapshot of the source data stream or index though these are all taken at approximately the same time.</li>
|
|
1540
|
+
</ul>
|
|
1541
|
+
<p>If you're slicing manually or otherwise tuning automatic slicing, keep in mind that:</p>
|
|
1542
|
+
<ul>
|
|
1543
|
+
<li>Query performance is most efficient when the number of slices is equal to the number of shards in the index or backing index. If that number is large (for example, 500), choose a lower number as too many <code>slices</code> hurts performance. Setting <code>slices</code> higher than the number of shards generally does not improve efficiency and adds overhead.</li>
|
|
1544
|
+
<li>Delete performance scales linearly across available resources with the number of slices.</li>
|
|
1545
|
+
</ul>
|
|
1546
|
+
<p>Whether query or delete performance dominates the runtime depends on the documents being reindexed and cluster resources.</p>
|
|
1547
|
+
<p><strong>Cancel a delete by query operation</strong></p>
|
|
1548
|
+
<p>Any delete by query can be canceled using the task cancel API. For example:</p>
|
|
1549
|
+
<pre><code>POST _tasks/r1A2WoRbTwKZ516z6NEs5A:36619/_cancel
|
|
1550
|
+
</code></pre>
|
|
1551
|
+
<p>The task ID can be found by using the get tasks API.</p>
|
|
1552
|
+
<p>Cancellation should happen quickly but might take a few seconds.
|
|
1553
|
+
The get task status API will continue to list the delete by query task until this task checks that it has been cancelled and terminates itself.</p>
|
|
1554
|
+
|
|
1555
|
+
|
|
1556
|
+
`<https://www.elastic.co/guide/en/elasticsearch/reference/8.18/docs-delete-by-query.html>`_
|
|
1347
1557
|
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
Supports wildcards (`*`). To search all data streams or indices, omit this
|
|
1352
|
-
parameter or use `*` or `_all`.
|
|
1558
|
+
:param index: A comma-separated list of data streams, indices, and aliases to
|
|
1559
|
+
search. It supports wildcards (`*`). To search all data streams or indices,
|
|
1560
|
+
omit this parameter or use `*` or `_all`.
|
|
1353
1561
|
:param allow_no_indices: If `false`, the request returns an error if any wildcard
|
|
1354
1562
|
expression, index alias, or `_all` value targets only missing or closed indices.
|
|
1355
1563
|
This behavior applies even if the request targets other open indices. For
|
|
1356
1564
|
example, a request targeting `foo*,bar*` returns an error if an index starts
|
|
1357
1565
|
with `foo` but no index starts with `bar`.
|
|
1358
1566
|
:param analyze_wildcard: If `true`, wildcard and prefix queries are analyzed.
|
|
1359
|
-
|
|
1567
|
+
This parameter can be used only when the `q` query string parameter is specified.
|
|
1568
|
+
:param analyzer: Analyzer to use for the query string. This parameter can be
|
|
1569
|
+
used only when the `q` query string parameter is specified.
|
|
1360
1570
|
:param conflicts: What to do if delete by query hits version conflicts: `abort`
|
|
1361
1571
|
or `proceed`.
|
|
1362
1572
|
:param default_operator: The default operator for query string query: `AND` or
|
|
1363
|
-
`OR`.
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1573
|
+
`OR`. This parameter can be used only when the `q` query string parameter
|
|
1574
|
+
is specified.
|
|
1575
|
+
:param df: The field to use as default where no field prefix is given in the
|
|
1576
|
+
query string. This parameter can be used only when the `q` query string parameter
|
|
1577
|
+
is specified.
|
|
1578
|
+
:param expand_wildcards: The type of index that wildcard patterns can match.
|
|
1579
|
+
If the request can target data streams, this argument determines whether
|
|
1580
|
+
wildcard expressions match hidden data streams. It supports comma-separated
|
|
1581
|
+
values, such as `open,hidden`.
|
|
1582
|
+
:param from_: Skips the specified number of documents.
|
|
1371
1583
|
:param ignore_unavailable: If `false`, the request returns an error if it targets
|
|
1372
1584
|
a missing or closed index.
|
|
1373
1585
|
:param lenient: If `true`, format-based query failures (such as providing text
|
|
1374
|
-
to a numeric field) in the query string will be ignored.
|
|
1586
|
+
to a numeric field) in the query string will be ignored. This parameter can
|
|
1587
|
+
be used only when the `q` query string parameter is specified.
|
|
1375
1588
|
:param max_docs: The maximum number of documents to delete.
|
|
1376
|
-
:param preference:
|
|
1377
|
-
|
|
1378
|
-
:param q:
|
|
1379
|
-
:param query:
|
|
1589
|
+
:param preference: The node or shard the operation should be performed on. It
|
|
1590
|
+
is random by default.
|
|
1591
|
+
:param q: A query in the Lucene query string syntax.
|
|
1592
|
+
:param query: The documents to delete specified with Query DSL.
|
|
1380
1593
|
:param refresh: If `true`, Elasticsearch refreshes all shards involved in the
|
|
1381
|
-
delete by query after the request completes.
|
|
1594
|
+
delete by query after the request completes. This is different than the delete
|
|
1595
|
+
API's `refresh` parameter, which causes just the shard that received the
|
|
1596
|
+
delete request to be refreshed. Unlike the delete API, it does not support
|
|
1597
|
+
`wait_for`.
|
|
1382
1598
|
:param request_cache: If `true`, the request cache is used for this request.
|
|
1383
1599
|
Defaults to the index-level setting.
|
|
1384
1600
|
:param requests_per_second: The throttle for this request in sub-requests per
|
|
1385
1601
|
second.
|
|
1386
|
-
:param routing:
|
|
1387
|
-
:param scroll:
|
|
1388
|
-
:param scroll_size:
|
|
1389
|
-
:param search_timeout:
|
|
1390
|
-
no timeout.
|
|
1391
|
-
:param search_type: The type of the search operation. Available options
|
|
1392
|
-
`dfs_query_then_fetch`.
|
|
1602
|
+
:param routing: A custom value used to route operations to a specific shard.
|
|
1603
|
+
:param scroll: The period to retain the search context for scrolling.
|
|
1604
|
+
:param scroll_size: The size of the scroll request that powers the operation.
|
|
1605
|
+
:param search_timeout: The explicit timeout for each search request. It defaults
|
|
1606
|
+
to no timeout.
|
|
1607
|
+
:param search_type: The type of the search operation. Available options include
|
|
1608
|
+
`query_then_fetch` and `dfs_query_then_fetch`.
|
|
1393
1609
|
:param slice: Slice the request manually using the provided slice ID and total
|
|
1394
1610
|
number of slices.
|
|
1395
1611
|
:param slices: The number of slices this task should be divided into.
|
|
1396
|
-
:param sort: A comma-separated list of
|
|
1397
|
-
:param stats:
|
|
1398
|
-
:param terminate_after:
|
|
1612
|
+
:param sort: A comma-separated list of `<field>:<direction>` pairs.
|
|
1613
|
+
:param stats: The specific `tag` of the request for logging and statistical purposes.
|
|
1614
|
+
:param terminate_after: The maximum number of documents to collect for each shard.
|
|
1399
1615
|
If a query reaches this limit, Elasticsearch terminates the query early.
|
|
1400
1616
|
Elasticsearch collects documents before sorting. Use with caution. Elasticsearch
|
|
1401
1617
|
applies this parameter to each shard handling the request. When possible,
|
|
1402
1618
|
let Elasticsearch perform early termination automatically. Avoid specifying
|
|
1403
1619
|
this parameter for requests that target data streams with backing indices
|
|
1404
1620
|
across multiple data tiers.
|
|
1405
|
-
:param timeout:
|
|
1621
|
+
:param timeout: The period each deletion request waits for active shards.
|
|
1406
1622
|
:param version: If `true`, returns the document version as part of a hit.
|
|
1407
1623
|
:param wait_for_active_shards: The number of shard copies that must be active
|
|
1408
|
-
before proceeding with the operation. Set to all or any positive integer
|
|
1409
|
-
up to the total number of shards in the index (`number_of_replicas+1`).
|
|
1624
|
+
before proceeding with the operation. Set to `all` or any positive integer
|
|
1625
|
+
up to the total number of shards in the index (`number_of_replicas+1`). The
|
|
1626
|
+
`timeout` value controls how long each write request waits for unavailable
|
|
1627
|
+
shards to become available.
|
|
1410
1628
|
:param wait_for_completion: If `true`, the request blocks until the operation
|
|
1411
|
-
is complete.
|
|
1629
|
+
is complete. If `false`, Elasticsearch performs some preflight checks, launches
|
|
1630
|
+
the request, and returns a task you can use to cancel or get the status of
|
|
1631
|
+
the task. Elasticsearch creates a record of this task as a document at `.tasks/task/${taskId}`.
|
|
1632
|
+
When you are done with a task, you should delete the task document so Elasticsearch
|
|
1633
|
+
can reclaim the space.
|
|
1412
1634
|
"""
|
|
1413
1635
|
if index in SKIP_IN_PATH:
|
|
1414
1636
|
raise ValueError("Empty value passed for parameter 'index'")
|
|
@@ -1521,16 +1743,18 @@ class Elasticsearch(BaseClient):
|
|
|
1521
1743
|
requests_per_second: t.Optional[float] = None,
|
|
1522
1744
|
) -> ObjectApiResponse[t.Any]:
|
|
1523
1745
|
"""
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1746
|
+
.. raw:: html
|
|
1747
|
+
|
|
1748
|
+
<p>Throttle a delete by query operation.</p>
|
|
1749
|
+
<p>Change the number of requests per second for a particular delete by query operation.
|
|
1750
|
+
Rethrottling that speeds up the query takes effect immediately but rethrotting that slows down the query takes effect after completing the current batch to prevent scroll timeouts.</p>
|
|
1528
1751
|
|
|
1529
|
-
|
|
1752
|
+
|
|
1753
|
+
`<https://www.elastic.co/guide/en/elasticsearch/reference/8.18/docs-delete-by-query.html#docs-delete-by-query-rethrottle>`_
|
|
1530
1754
|
|
|
1531
1755
|
:param task_id: The ID for the task.
|
|
1532
1756
|
:param requests_per_second: The throttle for this request in sub-requests per
|
|
1533
|
-
second.
|
|
1757
|
+
second. To disable throttling, set it to `-1`.
|
|
1534
1758
|
"""
|
|
1535
1759
|
if task_id in SKIP_IN_PATH:
|
|
1536
1760
|
raise ValueError("Empty value passed for parameter 'task_id'")
|
|
@@ -1570,16 +1794,22 @@ class Elasticsearch(BaseClient):
|
|
|
1570
1794
|
timeout: t.Optional[t.Union[str, t.Literal[-1], t.Literal[0]]] = None,
|
|
1571
1795
|
) -> ObjectApiResponse[t.Any]:
|
|
1572
1796
|
"""
|
|
1573
|
-
|
|
1797
|
+
.. raw:: html
|
|
1574
1798
|
|
|
1575
|
-
|
|
1799
|
+
<p>Delete a script or search template.
|
|
1800
|
+
Deletes a stored script or search template.</p>
|
|
1576
1801
|
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
:param
|
|
1582
|
-
the timeout expires, the request fails
|
|
1802
|
+
|
|
1803
|
+
`<https://www.elastic.co/guide/en/elasticsearch/reference/8.18/delete-stored-script-api.html>`_
|
|
1804
|
+
|
|
1805
|
+
:param id: The identifier for the stored script or search template.
|
|
1806
|
+
:param master_timeout: The period to wait for a connection to the master node.
|
|
1807
|
+
If no response is received before the timeout expires, the request fails
|
|
1808
|
+
and returns an error. It can also be set to `-1` to indicate that the request
|
|
1809
|
+
should never timeout.
|
|
1810
|
+
:param timeout: The period to wait for a response. If no response is received
|
|
1811
|
+
before the timeout expires, the request fails and returns an error. It can
|
|
1812
|
+
also be set to `-1` to indicate that the request should never timeout.
|
|
1583
1813
|
"""
|
|
1584
1814
|
if id in SKIP_IN_PATH:
|
|
1585
1815
|
raise ValueError("Empty value passed for parameter 'id'")
|
|
@@ -1638,32 +1868,60 @@ class Elasticsearch(BaseClient):
|
|
|
1638
1868
|
] = None,
|
|
1639
1869
|
) -> HeadApiResponse:
|
|
1640
1870
|
"""
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1871
|
+
.. raw:: html
|
|
1872
|
+
|
|
1873
|
+
<p>Check a document.</p>
|
|
1874
|
+
<p>Verify that a document exists.
|
|
1875
|
+
For example, check to see if a document with the <code>_id</code> 0 exists:</p>
|
|
1876
|
+
<pre><code>HEAD my-index-000001/_doc/0
|
|
1877
|
+
</code></pre>
|
|
1878
|
+
<p>If the document exists, the API returns a status code of <code>200 - OK</code>.
|
|
1879
|
+
If the document doesn’t exist, the API returns <code>404 - Not Found</code>.</p>
|
|
1880
|
+
<p><strong>Versioning support</strong></p>
|
|
1881
|
+
<p>You can use the <code>version</code> parameter to check the document only if its current version is equal to the specified one.</p>
|
|
1882
|
+
<p>Internally, Elasticsearch has marked the old document as deleted and added an entirely new document.
|
|
1883
|
+
The old version of the document doesn't disappear immediately, although you won't be able to access it.
|
|
1884
|
+
Elasticsearch cleans up deleted documents in the background as you continue to index more data.</p>
|
|
1885
|
+
|
|
1886
|
+
|
|
1887
|
+
`<https://www.elastic.co/guide/en/elasticsearch/reference/8.18/docs-get.html>`_
|
|
1888
|
+
|
|
1889
|
+
:param index: A comma-separated list of data streams, indices, and aliases. It
|
|
1890
|
+
supports wildcards (`*`).
|
|
1891
|
+
:param id: A unique document identifier.
|
|
1892
|
+
:param preference: The node or shard the operation should be performed on. By
|
|
1893
|
+
default, the operation is randomized between the shard replicas. If it is
|
|
1894
|
+
set to `_local`, the operation will prefer to be run on a local allocated
|
|
1895
|
+
shard when possible. If it is set to a custom value, the value is used to
|
|
1896
|
+
guarantee that the same shards will be used for the same custom value. This
|
|
1897
|
+
can help with "jumping values" when hitting different shards in different
|
|
1898
|
+
refresh states. A sample value can be something like the web session ID or
|
|
1899
|
+
the user name.
|
|
1650
1900
|
:param realtime: If `true`, the request is real-time as opposed to near-real-time.
|
|
1651
|
-
:param refresh: If `true`,
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
:param
|
|
1657
|
-
the
|
|
1901
|
+
:param refresh: If `true`, the request refreshes the relevant shards before retrieving
|
|
1902
|
+
the document. Setting it to `true` should be done after careful thought and
|
|
1903
|
+
verification that this does not cause a heavy load on the system (and slow
|
|
1904
|
+
down indexing).
|
|
1905
|
+
:param routing: A custom value used to route operations to a specific shard.
|
|
1906
|
+
:param source: Indicates whether to return the `_source` field (`true` or `false`)
|
|
1907
|
+
or lists the fields to return.
|
|
1908
|
+
:param source_excludes: A comma-separated list of source fields to exclude from
|
|
1909
|
+
the response. You can also use this parameter to exclude fields from the
|
|
1910
|
+
subset specified in `_source_includes` query parameter. If the `_source`
|
|
1911
|
+
parameter is `false`, this parameter is ignored.
|
|
1658
1912
|
:param source_includes: A comma-separated list of source fields to include in
|
|
1659
|
-
the response.
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1913
|
+
the response. If this parameter is specified, only these source fields are
|
|
1914
|
+
returned. You can exclude fields from this subset using the `_source_excludes`
|
|
1915
|
+
query parameter. If the `_source` parameter is `false`, this parameter is
|
|
1916
|
+
ignored.
|
|
1917
|
+
:param stored_fields: A comma-separated list of stored fields to return as part
|
|
1918
|
+
of a hit. If no fields are specified, no stored fields are included in the
|
|
1919
|
+
response. If this field is specified, the `_source` parameter defaults to
|
|
1920
|
+
`false`.
|
|
1663
1921
|
:param version: Explicit version number for concurrency control. The specified
|
|
1664
1922
|
version must match the current version of the document for the request to
|
|
1665
1923
|
succeed.
|
|
1666
|
-
:param version_type:
|
|
1924
|
+
:param version_type: The version type.
|
|
1667
1925
|
"""
|
|
1668
1926
|
if index in SKIP_IN_PATH:
|
|
1669
1927
|
raise ValueError("Empty value passed for parameter 'index'")
|
|
@@ -1739,29 +1997,38 @@ class Elasticsearch(BaseClient):
|
|
|
1739
1997
|
] = None,
|
|
1740
1998
|
) -> HeadApiResponse:
|
|
1741
1999
|
"""
|
|
1742
|
-
|
|
2000
|
+
.. raw:: html
|
|
1743
2001
|
|
|
1744
|
-
|
|
2002
|
+
<p>Check for a document source.</p>
|
|
2003
|
+
<p>Check whether a document source exists in an index.
|
|
2004
|
+
For example:</p>
|
|
2005
|
+
<pre><code>HEAD my-index-000001/_source/1
|
|
2006
|
+
</code></pre>
|
|
2007
|
+
<p>A document's source is not available if it is disabled in the mapping.</p>
|
|
1745
2008
|
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
:param
|
|
1750
|
-
|
|
1751
|
-
:param
|
|
1752
|
-
:param
|
|
1753
|
-
|
|
1754
|
-
:param
|
|
1755
|
-
:param
|
|
1756
|
-
|
|
2009
|
+
|
|
2010
|
+
`<https://www.elastic.co/guide/en/elasticsearch/reference/8.18/docs-get.html>`_
|
|
2011
|
+
|
|
2012
|
+
:param index: A comma-separated list of data streams, indices, and aliases. It
|
|
2013
|
+
supports wildcards (`*`).
|
|
2014
|
+
:param id: A unique identifier for the document.
|
|
2015
|
+
:param preference: The node or shard the operation should be performed on. By
|
|
2016
|
+
default, the operation is randomized between the shard replicas.
|
|
2017
|
+
:param realtime: If `true`, the request is real-time as opposed to near-real-time.
|
|
2018
|
+
:param refresh: If `true`, the request refreshes the relevant shards before retrieving
|
|
2019
|
+
the document. Setting it to `true` should be done after careful thought and
|
|
2020
|
+
verification that this does not cause a heavy load on the system (and slow
|
|
2021
|
+
down indexing).
|
|
2022
|
+
:param routing: A custom value used to route operations to a specific shard.
|
|
2023
|
+
:param source: Indicates whether to return the `_source` field (`true` or `false`)
|
|
2024
|
+
or lists the fields to return.
|
|
1757
2025
|
:param source_excludes: A comma-separated list of source fields to exclude in
|
|
1758
2026
|
the response.
|
|
1759
2027
|
:param source_includes: A comma-separated list of source fields to include in
|
|
1760
2028
|
the response.
|
|
1761
|
-
:param version:
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
:param version_type: Specific version type: `external`, `external_gte`.
|
|
2029
|
+
:param version: The version number for concurrency control. It must match the
|
|
2030
|
+
current version of the document for the request to succeed.
|
|
2031
|
+
:param version_type: The version type.
|
|
1765
2032
|
"""
|
|
1766
2033
|
if index in SKIP_IN_PATH:
|
|
1767
2034
|
raise ValueError("Empty value passed for parameter 'index'")
|
|
@@ -1839,34 +2106,47 @@ class Elasticsearch(BaseClient):
|
|
|
1839
2106
|
body: t.Optional[t.Dict[str, t.Any]] = None,
|
|
1840
2107
|
) -> ObjectApiResponse[t.Any]:
|
|
1841
2108
|
"""
|
|
1842
|
-
|
|
1843
|
-
|
|
2109
|
+
.. raw:: html
|
|
2110
|
+
|
|
2111
|
+
<p>Explain a document match result.
|
|
2112
|
+
Get information about why a specific document matches, or doesn't match, a query.
|
|
2113
|
+
It computes a score explanation for a query and a specific document.</p>
|
|
2114
|
+
|
|
1844
2115
|
|
|
1845
|
-
`<https://www.elastic.co/guide/en/elasticsearch/reference/8.
|
|
2116
|
+
`<https://www.elastic.co/guide/en/elasticsearch/reference/8.18/search-explain.html>`_
|
|
1846
2117
|
|
|
1847
|
-
:param index: Index names used to limit the request. Only a single index
|
|
1848
|
-
can be provided to this parameter.
|
|
1849
|
-
:param id:
|
|
2118
|
+
:param index: Index names that are used to limit the request. Only a single index
|
|
2119
|
+
name can be provided to this parameter.
|
|
2120
|
+
:param id: The document identifier.
|
|
1850
2121
|
:param analyze_wildcard: If `true`, wildcard and prefix queries are analyzed.
|
|
1851
|
-
|
|
1852
|
-
|
|
2122
|
+
This parameter can be used only when the `q` query string parameter is specified.
|
|
2123
|
+
:param analyzer: The analyzer to use for the query string. This parameter can
|
|
2124
|
+
be used only when the `q` query string parameter is specified.
|
|
1853
2125
|
:param default_operator: The default operator for query string query: `AND` or
|
|
1854
|
-
`OR`.
|
|
1855
|
-
|
|
1856
|
-
|
|
2126
|
+
`OR`. This parameter can be used only when the `q` query string parameter
|
|
2127
|
+
is specified.
|
|
2128
|
+
:param df: The field to use as default where no field prefix is given in the
|
|
2129
|
+
query string. This parameter can be used only when the `q` query string parameter
|
|
2130
|
+
is specified.
|
|
1857
2131
|
:param lenient: If `true`, format-based query failures (such as providing text
|
|
1858
|
-
to a numeric field) in the query string will be ignored.
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
2132
|
+
to a numeric field) in the query string will be ignored. This parameter can
|
|
2133
|
+
be used only when the `q` query string parameter is specified.
|
|
2134
|
+
:param preference: The node or shard the operation should be performed on. It
|
|
2135
|
+
is random by default.
|
|
2136
|
+
:param q: The query in the Lucene query string syntax.
|
|
1862
2137
|
:param query: Defines the search definition using the Query DSL.
|
|
1863
|
-
:param routing:
|
|
1864
|
-
:param source: True or false to return the `_source` field or not
|
|
2138
|
+
:param routing: A custom value used to route operations to a specific shard.
|
|
2139
|
+
:param source: `True` or `false` to return the `_source` field or not or a list
|
|
1865
2140
|
of fields to return.
|
|
1866
2141
|
:param source_excludes: A comma-separated list of source fields to exclude from
|
|
1867
|
-
the response.
|
|
2142
|
+
the response. You can also use this parameter to exclude fields from the
|
|
2143
|
+
subset specified in `_source_includes` query parameter. If the `_source`
|
|
2144
|
+
parameter is `false`, this parameter is ignored.
|
|
1868
2145
|
:param source_includes: A comma-separated list of source fields to include in
|
|
1869
|
-
the response.
|
|
2146
|
+
the response. If this parameter is specified, only these source fields are
|
|
2147
|
+
returned. You can exclude fields from this subset using the `_source_excludes`
|
|
2148
|
+
query parameter. If the `_source` parameter is `false`, this parameter is
|
|
2149
|
+
ignored.
|
|
1870
2150
|
:param stored_fields: A comma-separated list of stored fields to return in the
|
|
1871
2151
|
response.
|
|
1872
2152
|
"""
|
|
@@ -1959,15 +2239,18 @@ class Elasticsearch(BaseClient):
|
|
|
1959
2239
|
body: t.Optional[t.Dict[str, t.Any]] = None,
|
|
1960
2240
|
) -> ObjectApiResponse[t.Any]:
|
|
1961
2241
|
"""
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
2242
|
+
.. raw:: html
|
|
2243
|
+
|
|
2244
|
+
<p>Get the field capabilities.</p>
|
|
2245
|
+
<p>Get information about the capabilities of fields among multiple indices.</p>
|
|
2246
|
+
<p>For data streams, the API returns field capabilities among the stream’s backing indices.
|
|
2247
|
+
It returns runtime fields like any other field.
|
|
2248
|
+
For example, a runtime field with a type of keyword is returned the same as any other field that belongs to the <code>keyword</code> family.</p>
|
|
2249
|
+
|
|
1967
2250
|
|
|
1968
|
-
`<https://www.elastic.co/guide/en/elasticsearch/reference/8.
|
|
2251
|
+
`<https://www.elastic.co/guide/en/elasticsearch/reference/8.18/search-field-caps.html>`_
|
|
1969
2252
|
|
|
1970
|
-
:param index:
|
|
2253
|
+
:param index: A comma-separated list of data streams, indices, and aliases used
|
|
1971
2254
|
to limit the request. Supports wildcards (*). To target all data streams
|
|
1972
2255
|
and indices, omit this parameter or use * or _all.
|
|
1973
2256
|
:param allow_no_indices: If false, the request returns an error if any wildcard
|
|
@@ -1975,25 +2258,32 @@ class Elasticsearch(BaseClient):
|
|
|
1975
2258
|
This behavior applies even if the request targets other open indices. For
|
|
1976
2259
|
example, a request targeting `foo*,bar*` returns an error if an index starts
|
|
1977
2260
|
with foo but no index starts with bar.
|
|
1978
|
-
:param expand_wildcards:
|
|
1979
|
-
request can target data streams, this argument determines whether
|
|
1980
|
-
expressions match hidden data streams. Supports comma-separated
|
|
1981
|
-
as `open,hidden`.
|
|
1982
|
-
:param fields:
|
|
1983
|
-
are supported.
|
|
1984
|
-
:param filters:
|
|
2261
|
+
:param expand_wildcards: The type of index that wildcard patterns can match.
|
|
2262
|
+
If the request can target data streams, this argument determines whether
|
|
2263
|
+
wildcard expressions match hidden data streams. Supports comma-separated
|
|
2264
|
+
values, such as `open,hidden`.
|
|
2265
|
+
:param fields: A list of fields to retrieve capabilities for. Wildcard (`*`)
|
|
2266
|
+
expressions are supported.
|
|
2267
|
+
:param filters: A comma-separated list of filters to apply to the response.
|
|
1985
2268
|
:param ignore_unavailable: If `true`, missing or closed indices are not included
|
|
1986
2269
|
in the response.
|
|
1987
2270
|
:param include_empty_fields: If false, empty fields are not included in the response.
|
|
1988
2271
|
:param include_unmapped: If true, unmapped fields are included in the response.
|
|
1989
|
-
:param index_filter:
|
|
1990
|
-
|
|
1991
|
-
|
|
2272
|
+
:param index_filter: Filter indices if the provided query rewrites to `match_none`
|
|
2273
|
+
on every shard. IMPORTANT: The filtering is done on a best-effort basis,
|
|
2274
|
+
it uses index statistics and mappings to rewrite queries to `match_none`
|
|
2275
|
+
instead of fully running the request. For instance a range query over a date
|
|
2276
|
+
field can rewrite to `match_none` if all documents within a shard (including
|
|
2277
|
+
deleted documents) are outside of the provided range. However, not all queries
|
|
2278
|
+
can rewrite to `match_none` so this API may return an index even if the provided
|
|
2279
|
+
filter matches no document.
|
|
2280
|
+
:param runtime_mappings: Define ad-hoc runtime fields in the request similar
|
|
1992
2281
|
to the way it is done in search requests. These fields exist only as part
|
|
1993
2282
|
of the query and take precedence over fields defined with the same name in
|
|
1994
2283
|
the index mappings.
|
|
1995
|
-
:param types:
|
|
1996
|
-
|
|
2284
|
+
:param types: A comma-separated list of field types to include. Any fields that
|
|
2285
|
+
do not match one of these types will be excluded from the results. It defaults
|
|
2286
|
+
to empty, meaning that all field types are returned.
|
|
1997
2287
|
"""
|
|
1998
2288
|
__path_parts: t.Dict[str, str]
|
|
1999
2289
|
if index not in SKIP_IN_PATH:
|
|
@@ -2079,36 +2369,87 @@ class Elasticsearch(BaseClient):
|
|
|
2079
2369
|
] = None,
|
|
2080
2370
|
) -> ObjectApiResponse[t.Any]:
|
|
2081
2371
|
"""
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2372
|
+
.. raw:: html
|
|
2373
|
+
|
|
2374
|
+
<p>Get a document by its ID.</p>
|
|
2375
|
+
<p>Get a document and its source or stored fields from an index.</p>
|
|
2376
|
+
<p>By default, this API is realtime and is not affected by the refresh rate of the index (when data will become visible for search).
|
|
2377
|
+
In the case where stored fields are requested with the <code>stored_fields</code> parameter and the document has been updated but is not yet refreshed, the API will have to parse and analyze the source to extract the stored fields.
|
|
2378
|
+
To turn off realtime behavior, set the <code>realtime</code> parameter to false.</p>
|
|
2379
|
+
<p><strong>Source filtering</strong></p>
|
|
2380
|
+
<p>By default, the API returns the contents of the <code>_source</code> field unless you have used the <code>stored_fields</code> parameter or the <code>_source</code> field is turned off.
|
|
2381
|
+
You can turn off <code>_source</code> retrieval by using the <code>_source</code> parameter:</p>
|
|
2382
|
+
<pre><code>GET my-index-000001/_doc/0?_source=false
|
|
2383
|
+
</code></pre>
|
|
2384
|
+
<p>If you only need one or two fields from the <code>_source</code>, use the <code>_source_includes</code> or <code>_source_excludes</code> parameters to include or filter out particular fields.
|
|
2385
|
+
This can be helpful with large documents where partial retrieval can save on network overhead
|
|
2386
|
+
Both parameters take a comma separated list of fields or wildcard expressions.
|
|
2387
|
+
For example:</p>
|
|
2388
|
+
<pre><code>GET my-index-000001/_doc/0?_source_includes=*.id&_source_excludes=entities
|
|
2389
|
+
</code></pre>
|
|
2390
|
+
<p>If you only want to specify includes, you can use a shorter notation:</p>
|
|
2391
|
+
<pre><code>GET my-index-000001/_doc/0?_source=*.id
|
|
2392
|
+
</code></pre>
|
|
2393
|
+
<p><strong>Routing</strong></p>
|
|
2394
|
+
<p>If routing is used during indexing, the routing value also needs to be specified to retrieve a document.
|
|
2395
|
+
For example:</p>
|
|
2396
|
+
<pre><code>GET my-index-000001/_doc/2?routing=user1
|
|
2397
|
+
</code></pre>
|
|
2398
|
+
<p>This request gets the document with ID 2, but it is routed based on the user.
|
|
2399
|
+
The document is not fetched if the correct routing is not specified.</p>
|
|
2400
|
+
<p><strong>Distributed</strong></p>
|
|
2401
|
+
<p>The GET operation is hashed into a specific shard ID.
|
|
2402
|
+
It is then redirected to one of the replicas within that shard ID and returns the result.
|
|
2403
|
+
The replicas are the primary shard and its replicas within that shard ID group.
|
|
2404
|
+
This means that the more replicas you have, the better your GET scaling will be.</p>
|
|
2405
|
+
<p><strong>Versioning support</strong></p>
|
|
2406
|
+
<p>You can use the <code>version</code> parameter to retrieve the document only if its current version is equal to the specified one.</p>
|
|
2407
|
+
<p>Internally, Elasticsearch has marked the old document as deleted and added an entirely new document.
|
|
2408
|
+
The old version of the document doesn't disappear immediately, although you won't be able to access it.
|
|
2409
|
+
Elasticsearch cleans up deleted documents in the background as you continue to index more data.</p>
|
|
2410
|
+
|
|
2411
|
+
|
|
2412
|
+
`<https://www.elastic.co/guide/en/elasticsearch/reference/8.18/docs-get.html>`_
|
|
2413
|
+
|
|
2414
|
+
:param index: The name of the index that contains the document.
|
|
2415
|
+
:param id: A unique document identifier.
|
|
2416
|
+
:param force_synthetic_source: Indicates whether the request forces synthetic
|
|
2417
|
+
`_source`. Use this paramater to test if the mapping supports synthetic `_source`
|
|
2418
|
+
and to get a sense of the worst case performance. Fetches with this parameter
|
|
2419
|
+
enabled will be slower than enabling synthetic source natively in the index.
|
|
2420
|
+
:param preference: The node or shard the operation should be performed on. By
|
|
2421
|
+
default, the operation is randomized between the shard replicas. If it is
|
|
2422
|
+
set to `_local`, the operation will prefer to be run on a local allocated
|
|
2423
|
+
shard when possible. If it is set to a custom value, the value is used to
|
|
2424
|
+
guarantee that the same shards will be used for the same custom value. This
|
|
2425
|
+
can help with "jumping values" when hitting different shards in different
|
|
2426
|
+
refresh states. A sample value can be something like the web session ID or
|
|
2427
|
+
the user name.
|
|
2095
2428
|
:param realtime: If `true`, the request is real-time as opposed to near-real-time.
|
|
2096
|
-
:param refresh: If true
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
:param
|
|
2102
|
-
the
|
|
2429
|
+
:param refresh: If `true`, the request refreshes the relevant shards before retrieving
|
|
2430
|
+
the document. Setting it to `true` should be done after careful thought and
|
|
2431
|
+
verification that this does not cause a heavy load on the system (and slow
|
|
2432
|
+
down indexing).
|
|
2433
|
+
:param routing: A custom value used to route operations to a specific shard.
|
|
2434
|
+
:param source: Indicates whether to return the `_source` field (`true` or `false`)
|
|
2435
|
+
or lists the fields to return.
|
|
2436
|
+
:param source_excludes: A comma-separated list of source fields to exclude from
|
|
2437
|
+
the response. You can also use this parameter to exclude fields from the
|
|
2438
|
+
subset specified in `_source_includes` query parameter. If the `_source`
|
|
2439
|
+
parameter is `false`, this parameter is ignored.
|
|
2103
2440
|
:param source_includes: A comma-separated list of source fields to include in
|
|
2104
|
-
the response.
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
:param
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2441
|
+
the response. If this parameter is specified, only these source fields are
|
|
2442
|
+
returned. You can exclude fields from this subset using the `_source_excludes`
|
|
2443
|
+
query parameter. If the `_source` parameter is `false`, this parameter is
|
|
2444
|
+
ignored.
|
|
2445
|
+
:param stored_fields: A comma-separated list of stored fields to return as part
|
|
2446
|
+
of a hit. If no fields are specified, no stored fields are included in the
|
|
2447
|
+
response. If this field is specified, the `_source` parameter defaults to
|
|
2448
|
+
`false`. Only leaf fields can be retrieved with the `stored_field` option.
|
|
2449
|
+
Object fields can't be returned;if specified, the request fails.
|
|
2450
|
+
:param version: The version number for concurrency control. It must match the
|
|
2451
|
+
current version of the document for the request to succeed.
|
|
2452
|
+
:param version_type: The version type.
|
|
2112
2453
|
"""
|
|
2113
2454
|
if index in SKIP_IN_PATH:
|
|
2114
2455
|
raise ValueError("Empty value passed for parameter 'index'")
|
|
@@ -2169,12 +2510,19 @@ class Elasticsearch(BaseClient):
|
|
|
2169
2510
|
pretty: t.Optional[bool] = None,
|
|
2170
2511
|
) -> ObjectApiResponse[t.Any]:
|
|
2171
2512
|
"""
|
|
2172
|
-
|
|
2513
|
+
.. raw:: html
|
|
2514
|
+
|
|
2515
|
+
<p>Get a script or search template.
|
|
2516
|
+
Retrieves a stored script or search template.</p>
|
|
2173
2517
|
|
|
2174
|
-
`<https://www.elastic.co/guide/en/elasticsearch/reference/8.17/modules-scripting.html>`_
|
|
2175
2518
|
|
|
2176
|
-
|
|
2177
|
-
|
|
2519
|
+
`<https://www.elastic.co/guide/en/elasticsearch/reference/8.18/get-stored-script-api.html>`_
|
|
2520
|
+
|
|
2521
|
+
:param id: The identifier for the stored script or search template.
|
|
2522
|
+
:param master_timeout: The period to wait for the master node. If the master
|
|
2523
|
+
node is not available before the timeout expires, the request fails and returns
|
|
2524
|
+
an error. It can also be set to `-1` to indicate that the request should
|
|
2525
|
+
never timeout.
|
|
2178
2526
|
"""
|
|
2179
2527
|
if id in SKIP_IN_PATH:
|
|
2180
2528
|
raise ValueError("Empty value passed for parameter 'id'")
|
|
@@ -2211,9 +2559,13 @@ class Elasticsearch(BaseClient):
|
|
|
2211
2559
|
pretty: t.Optional[bool] = None,
|
|
2212
2560
|
) -> ObjectApiResponse[t.Any]:
|
|
2213
2561
|
"""
|
|
2214
|
-
|
|
2562
|
+
.. raw:: html
|
|
2563
|
+
|
|
2564
|
+
<p>Get script contexts.</p>
|
|
2565
|
+
<p>Get a list of supported script contexts and their methods.</p>
|
|
2215
2566
|
|
|
2216
|
-
|
|
2567
|
+
|
|
2568
|
+
`<https://www.elastic.co/guide/en/elasticsearch/reference/8.18/get-script-contexts-api.html>`_
|
|
2217
2569
|
"""
|
|
2218
2570
|
__path_parts: t.Dict[str, str] = {}
|
|
2219
2571
|
__path = "/_script_context"
|
|
@@ -2246,9 +2598,13 @@ class Elasticsearch(BaseClient):
|
|
|
2246
2598
|
pretty: t.Optional[bool] = None,
|
|
2247
2599
|
) -> ObjectApiResponse[t.Any]:
|
|
2248
2600
|
"""
|
|
2249
|
-
|
|
2601
|
+
.. raw:: html
|
|
2602
|
+
|
|
2603
|
+
<p>Get script languages.</p>
|
|
2604
|
+
<p>Get a list of available script types, languages, and contexts.</p>
|
|
2605
|
+
|
|
2250
2606
|
|
|
2251
|
-
`<https://www.elastic.co/guide/en/elasticsearch/reference/8.
|
|
2607
|
+
`<https://www.elastic.co/guide/en/elasticsearch/reference/8.18/get-script-languages-api.html>`_
|
|
2252
2608
|
"""
|
|
2253
2609
|
__path_parts: t.Dict[str, str] = {}
|
|
2254
2610
|
__path = "/_script_language"
|
|
@@ -2301,29 +2657,41 @@ class Elasticsearch(BaseClient):
|
|
|
2301
2657
|
] = None,
|
|
2302
2658
|
) -> ObjectApiResponse[t.Any]:
|
|
2303
2659
|
"""
|
|
2304
|
-
|
|
2660
|
+
.. raw:: html
|
|
2305
2661
|
|
|
2306
|
-
|
|
2662
|
+
<p>Get a document's source.</p>
|
|
2663
|
+
<p>Get the source of a document.
|
|
2664
|
+
For example:</p>
|
|
2665
|
+
<pre><code>GET my-index-000001/_source/1
|
|
2666
|
+
</code></pre>
|
|
2667
|
+
<p>You can use the source filtering parameters to control which parts of the <code>_source</code> are returned:</p>
|
|
2668
|
+
<pre><code>GET my-index-000001/_source/1/?_source_includes=*.id&_source_excludes=entities
|
|
2669
|
+
</code></pre>
|
|
2307
2670
|
|
|
2308
|
-
|
|
2309
|
-
|
|
2310
|
-
|
|
2311
|
-
|
|
2312
|
-
:param
|
|
2313
|
-
:param
|
|
2314
|
-
|
|
2315
|
-
:param
|
|
2316
|
-
:param
|
|
2317
|
-
|
|
2671
|
+
|
|
2672
|
+
`<https://www.elastic.co/guide/en/elasticsearch/reference/8.18/docs-get.html>`_
|
|
2673
|
+
|
|
2674
|
+
:param index: The name of the index that contains the document.
|
|
2675
|
+
:param id: A unique document identifier.
|
|
2676
|
+
:param preference: The node or shard the operation should be performed on. By
|
|
2677
|
+
default, the operation is randomized between the shard replicas.
|
|
2678
|
+
:param realtime: If `true`, the request is real-time as opposed to near-real-time.
|
|
2679
|
+
:param refresh: If `true`, the request refreshes the relevant shards before retrieving
|
|
2680
|
+
the document. Setting it to `true` should be done after careful thought and
|
|
2681
|
+
verification that this does not cause a heavy load on the system (and slow
|
|
2682
|
+
down indexing).
|
|
2683
|
+
:param routing: A custom value used to route operations to a specific shard.
|
|
2684
|
+
:param source: Indicates whether to return the `_source` field (`true` or `false`)
|
|
2685
|
+
or lists the fields to return.
|
|
2318
2686
|
:param source_excludes: A comma-separated list of source fields to exclude in
|
|
2319
2687
|
the response.
|
|
2320
2688
|
:param source_includes: A comma-separated list of source fields to include in
|
|
2321
2689
|
the response.
|
|
2322
|
-
:param stored_fields:
|
|
2323
|
-
|
|
2324
|
-
|
|
2325
|
-
succeed.
|
|
2326
|
-
:param version_type:
|
|
2690
|
+
:param stored_fields: A comma-separated list of stored fields to return as part
|
|
2691
|
+
of a hit.
|
|
2692
|
+
:param version: The version number for concurrency control. It must match the
|
|
2693
|
+
current version of the document for the request to succeed.
|
|
2694
|
+
:param version_type: The version type.
|
|
2327
2695
|
"""
|
|
2328
2696
|
if index in SKIP_IN_PATH:
|
|
2329
2697
|
raise ValueError("Empty value passed for parameter 'index'")
|
|
@@ -2384,28 +2752,24 @@ class Elasticsearch(BaseClient):
|
|
|
2384
2752
|
verbose: t.Optional[bool] = None,
|
|
2385
2753
|
) -> ObjectApiResponse[t.Any]:
|
|
2386
2754
|
"""
|
|
2387
|
-
|
|
2388
|
-
|
|
2389
|
-
|
|
2390
|
-
|
|
2391
|
-
|
|
2392
|
-
|
|
2393
|
-
|
|
2394
|
-
|
|
2395
|
-
|
|
2396
|
-
|
|
2397
|
-
|
|
2398
|
-
|
|
2399
|
-
|
|
2400
|
-
|
|
2401
|
-
|
|
2402
|
-
|
|
2403
|
-
|
|
2404
|
-
|
|
2405
|
-
for health status, set verbose to false to disable the more expensive analysis
|
|
2406
|
-
logic.
|
|
2407
|
-
|
|
2408
|
-
`<https://www.elastic.co/guide/en/elasticsearch/reference/8.17/health-api.html>`_
|
|
2755
|
+
.. raw:: html
|
|
2756
|
+
|
|
2757
|
+
<p>Get the cluster health.
|
|
2758
|
+
Get a report with the health status of an Elasticsearch cluster.
|
|
2759
|
+
The report contains a list of indicators that compose Elasticsearch functionality.</p>
|
|
2760
|
+
<p>Each indicator has a health status of: green, unknown, yellow or red.
|
|
2761
|
+
The indicator will provide an explanation and metadata describing the reason for its current health status.</p>
|
|
2762
|
+
<p>The cluster’s status is controlled by the worst indicator status.</p>
|
|
2763
|
+
<p>In the event that an indicator’s status is non-green, a list of impacts may be present in the indicator result which detail the functionalities that are negatively affected by the health issue.
|
|
2764
|
+
Each impact carries with it a severity level, an area of the system that is affected, and a simple description of the impact on the system.</p>
|
|
2765
|
+
<p>Some health indicators can determine the root cause of a health problem and prescribe a set of steps that can be performed in order to improve the health of the system.
|
|
2766
|
+
The root cause and remediation steps are encapsulated in a diagnosis.
|
|
2767
|
+
A diagnosis contains a cause detailing a root cause analysis, an action containing a brief description of the steps to take to fix the problem, the list of affected resources (if applicable), and a detailed step-by-step troubleshooting guide to fix the diagnosed problem.</p>
|
|
2768
|
+
<p>NOTE: The health indicators perform root cause analysis of non-green health statuses. This can be computationally expensive when called frequently.
|
|
2769
|
+
When setting up automated polling of the API for health status, set verbose to false to disable the more expensive analysis logic.</p>
|
|
2770
|
+
|
|
2771
|
+
|
|
2772
|
+
`<https://www.elastic.co/guide/en/elasticsearch/reference/8.18/health-api.html>`_
|
|
2409
2773
|
|
|
2410
2774
|
:param feature: A feature of the cluster, as returned by the top-level health
|
|
2411
2775
|
report API.
|
|
@@ -2460,6 +2824,7 @@ class Elasticsearch(BaseClient):
|
|
|
2460
2824
|
human: t.Optional[bool] = None,
|
|
2461
2825
|
if_primary_term: t.Optional[int] = None,
|
|
2462
2826
|
if_seq_no: t.Optional[int] = None,
|
|
2827
|
+
include_source_on_error: t.Optional[bool] = None,
|
|
2463
2828
|
op_type: t.Optional[t.Union[str, t.Literal["create", "index"]]] = None,
|
|
2464
2829
|
pipeline: t.Optional[str] = None,
|
|
2465
2830
|
pretty: t.Optional[bool] = None,
|
|
@@ -2478,44 +2843,148 @@ class Elasticsearch(BaseClient):
|
|
|
2478
2843
|
] = None,
|
|
2479
2844
|
) -> ObjectApiResponse[t.Any]:
|
|
2480
2845
|
"""
|
|
2481
|
-
|
|
2482
|
-
|
|
2483
|
-
|
|
2484
|
-
|
|
2485
|
-
|
|
2486
|
-
|
|
2487
|
-
|
|
2846
|
+
.. raw:: html
|
|
2847
|
+
|
|
2848
|
+
<p>Create or update a document in an index.</p>
|
|
2849
|
+
<p>Add a JSON document to the specified data stream or index and make it searchable.
|
|
2850
|
+
If the target is an index and the document already exists, the request updates the document and increments its version.</p>
|
|
2851
|
+
<p>NOTE: You cannot use this API to send update requests for existing documents in a data stream.</p>
|
|
2852
|
+
<p>If the Elasticsearch security features are enabled, you must have the following index privileges for the target data stream, index, or index alias:</p>
|
|
2853
|
+
<ul>
|
|
2854
|
+
<li>To add or overwrite a document using the <code>PUT /<target>/_doc/<_id></code> request format, you must have the <code>create</code>, <code>index</code>, or <code>write</code> index privilege.</li>
|
|
2855
|
+
<li>To add a document using the <code>POST /<target>/_doc/</code> request format, you must have the <code>create_doc</code>, <code>create</code>, <code>index</code>, or <code>write</code> index privilege.</li>
|
|
2856
|
+
<li>To automatically create a data stream or index with this API request, you must have the <code>auto_configure</code>, <code>create_index</code>, or <code>manage</code> index privilege.</li>
|
|
2857
|
+
</ul>
|
|
2858
|
+
<p>Automatic data stream creation requires a matching index template with data stream enabled.</p>
|
|
2859
|
+
<p>NOTE: Replica shards might not all be started when an indexing operation returns successfully.
|
|
2860
|
+
By default, only the primary is required. Set <code>wait_for_active_shards</code> to change this default behavior.</p>
|
|
2861
|
+
<p><strong>Automatically create data streams and indices</strong></p>
|
|
2862
|
+
<p>If the request's target doesn't exist and matches an index template with a <code>data_stream</code> definition, the index operation automatically creates the data stream.</p>
|
|
2863
|
+
<p>If the target doesn't exist and doesn't match a data stream template, the operation automatically creates the index and applies any matching index templates.</p>
|
|
2864
|
+
<p>NOTE: Elasticsearch includes several built-in index templates. To avoid naming collisions with these templates, refer to index pattern documentation.</p>
|
|
2865
|
+
<p>If no mapping exists, the index operation creates a dynamic mapping.
|
|
2866
|
+
By default, new fields and objects are automatically added to the mapping if needed.</p>
|
|
2867
|
+
<p>Automatic index creation is controlled by the <code>action.auto_create_index</code> setting.
|
|
2868
|
+
If it is <code>true</code>, any index can be created automatically.
|
|
2869
|
+
You can modify this setting to explicitly allow or block automatic creation of indices that match specified patterns or set it to <code>false</code> to turn off automatic index creation entirely.
|
|
2870
|
+
Specify a comma-separated list of patterns you want to allow or prefix each pattern with <code>+</code> or <code>-</code> to indicate whether it should be allowed or blocked.
|
|
2871
|
+
When a list is specified, the default behaviour is to disallow.</p>
|
|
2872
|
+
<p>NOTE: The <code>action.auto_create_index</code> setting affects the automatic creation of indices only.
|
|
2873
|
+
It does not affect the creation of data streams.</p>
|
|
2874
|
+
<p><strong>Optimistic concurrency control</strong></p>
|
|
2875
|
+
<p>Index operations can be made conditional and only be performed if the last modification to the document was assigned the sequence number and primary term specified by the <code>if_seq_no</code> and <code>if_primary_term</code> parameters.
|
|
2876
|
+
If a mismatch is detected, the operation will result in a <code>VersionConflictException</code> and a status code of <code>409</code>.</p>
|
|
2877
|
+
<p><strong>Routing</strong></p>
|
|
2878
|
+
<p>By default, shard placement — or routing — is controlled by using a hash of the document's ID value.
|
|
2879
|
+
For more explicit control, the value fed into the hash function used by the router can be directly specified on a per-operation basis using the <code>routing</code> parameter.</p>
|
|
2880
|
+
<p>When setting up explicit mapping, you can also use the <code>_routing</code> field to direct the index operation to extract the routing value from the document itself.
|
|
2881
|
+
This does come at the (very minimal) cost of an additional document parsing pass.
|
|
2882
|
+
If the <code>_routing</code> mapping is defined and set to be required, the index operation will fail if no routing value is provided or extracted.</p>
|
|
2883
|
+
<p>NOTE: Data streams do not support custom routing unless they were created with the <code>allow_custom_routing</code> setting enabled in the template.</p>
|
|
2884
|
+
<p><strong>Distributed</strong></p>
|
|
2885
|
+
<p>The index operation is directed to the primary shard based on its route and performed on the actual node containing this shard.
|
|
2886
|
+
After the primary shard completes the operation, if needed, the update is distributed to applicable replicas.</p>
|
|
2887
|
+
<p><strong>Active shards</strong></p>
|
|
2888
|
+
<p>To improve the resiliency of writes to the system, indexing operations can be configured to wait for a certain number of active shard copies before proceeding with the operation.
|
|
2889
|
+
If the requisite number of active shard copies are not available, then the write operation must wait and retry, until either the requisite shard copies have started or a timeout occurs.
|
|
2890
|
+
By default, write operations only wait for the primary shards to be active before proceeding (that is to say <code>wait_for_active_shards</code> is <code>1</code>).
|
|
2891
|
+
This default can be overridden in the index settings dynamically by setting <code>index.write.wait_for_active_shards</code>.
|
|
2892
|
+
To alter this behavior per operation, use the <code>wait_for_active_shards request</code> parameter.</p>
|
|
2893
|
+
<p>Valid values are all or any positive integer up to the total number of configured copies per shard in the index (which is <code>number_of_replicas</code>+1).
|
|
2894
|
+
Specifying a negative value or a number greater than the number of shard copies will throw an error.</p>
|
|
2895
|
+
<p>For example, suppose you have a cluster of three nodes, A, B, and C and you create an index index with the number of replicas set to 3 (resulting in 4 shard copies, one more copy than there are nodes).
|
|
2896
|
+
If you attempt an indexing operation, by default the operation will only ensure the primary copy of each shard is available before proceeding.
|
|
2897
|
+
This means that even if B and C went down and A hosted the primary shard copies, the indexing operation would still proceed with only one copy of the data.
|
|
2898
|
+
If <code>wait_for_active_shards</code> is set on the request to <code>3</code> (and all three nodes are up), the indexing operation will require 3 active shard copies before proceeding.
|
|
2899
|
+
This requirement should be met because there are 3 active nodes in the cluster, each one holding a copy of the shard.
|
|
2900
|
+
However, if you set <code>wait_for_active_shards</code> to <code>all</code> (or to <code>4</code>, which is the same in this situation), the indexing operation will not proceed as you do not have all 4 copies of each shard active in the index.
|
|
2901
|
+
The operation will timeout unless a new node is brought up in the cluster to host the fourth copy of the shard.</p>
|
|
2902
|
+
<p>It is important to note that this setting greatly reduces the chances of the write operation not writing to the requisite number of shard copies, but it does not completely eliminate the possibility, because this check occurs before the write operation starts.
|
|
2903
|
+
After the write operation is underway, it is still possible for replication to fail on any number of shard copies but still succeed on the primary.
|
|
2904
|
+
The <code>_shards</code> section of the API response reveals the number of shard copies on which replication succeeded and failed.</p>
|
|
2905
|
+
<p><strong>No operation (noop) updates</strong></p>
|
|
2906
|
+
<p>When updating a document by using this API, a new version of the document is always created even if the document hasn't changed.
|
|
2907
|
+
If this isn't acceptable use the <code>_update</code> API with <code>detect_noop</code> set to <code>true</code>.
|
|
2908
|
+
The <code>detect_noop</code> option isn't available on this API because it doesn’t fetch the old source and isn't able to compare it against the new source.</p>
|
|
2909
|
+
<p>There isn't a definitive rule for when noop updates aren't acceptable.
|
|
2910
|
+
It's a combination of lots of factors like how frequently your data source sends updates that are actually noops and how many queries per second Elasticsearch runs on the shard receiving the updates.</p>
|
|
2911
|
+
<p><strong>Versioning</strong></p>
|
|
2912
|
+
<p>Each indexed document is given a version number.
|
|
2913
|
+
By default, internal versioning is used that starts at 1 and increments with each update, deletes included.
|
|
2914
|
+
Optionally, the version number can be set to an external value (for example, if maintained in a database).
|
|
2915
|
+
To enable this functionality, <code>version_type</code> should be set to <code>external</code>.
|
|
2916
|
+
The value provided must be a numeric, long value greater than or equal to 0, and less than around <code>9.2e+18</code>.</p>
|
|
2917
|
+
<p>NOTE: Versioning is completely real time, and is not affected by the near real time aspects of search operations.
|
|
2918
|
+
If no version is provided, the operation runs without any version checks.</p>
|
|
2919
|
+
<p>When using the external version type, the system checks to see if the version number passed to the index request is greater than the version of the currently stored document.
|
|
2920
|
+
If true, the document will be indexed and the new version number used.
|
|
2921
|
+
If the value provided is less than or equal to the stored document's version number, a version conflict will occur and the index operation will fail. For example:</p>
|
|
2922
|
+
<pre><code>PUT my-index-000001/_doc/1?version=2&version_type=external
|
|
2923
|
+
{
|
|
2924
|
+
"user": {
|
|
2925
|
+
"id": "elkbee"
|
|
2926
|
+
}
|
|
2927
|
+
}
|
|
2928
|
+
|
|
2929
|
+
In this example, the operation will succeed since the supplied version of 2 is higher than the current document version of 1.
|
|
2930
|
+
If the document was already updated and its version was set to 2 or higher, the indexing command will fail and result in a conflict (409 HTTP status code).
|
|
2931
|
+
|
|
2932
|
+
A nice side effect is that there is no need to maintain strict ordering of async indexing operations run as a result of changes to a source database, as long as version numbers from the source database are used.
|
|
2933
|
+
Even the simple case of updating the Elasticsearch index using data from a database is simplified if external versioning is used, as only the latest version will be used if the index operations arrive out of order.
|
|
2934
|
+
</code></pre>
|
|
2935
|
+
|
|
2936
|
+
|
|
2937
|
+
`<https://www.elastic.co/guide/en/elasticsearch/reference/8.18/docs-index_.html>`_
|
|
2938
|
+
|
|
2939
|
+
:param index: The name of the data stream or index to target. If the target doesn't
|
|
2940
|
+
exist and matches the name or wildcard (`*`) pattern of an index template
|
|
2941
|
+
with a `data_stream` definition, this request creates the data stream. If
|
|
2942
|
+
the target doesn't exist and doesn't match a data stream template, this request
|
|
2943
|
+
creates the index. You can check for existing targets with the resolve index
|
|
2944
|
+
API.
|
|
2488
2945
|
:param document:
|
|
2489
|
-
:param id:
|
|
2946
|
+
:param id: A unique identifier for the document. To automatically generate a
|
|
2947
|
+
document ID, use the `POST /<target>/_doc/` request format and omit this
|
|
2948
|
+
parameter.
|
|
2490
2949
|
:param if_primary_term: Only perform the operation if the document has this primary
|
|
2491
2950
|
term.
|
|
2492
2951
|
:param if_seq_no: Only perform the operation if the document has this sequence
|
|
2493
2952
|
number.
|
|
2494
|
-
:param
|
|
2953
|
+
:param include_source_on_error: True or false if to include the document source
|
|
2954
|
+
in the error message in case of parsing errors.
|
|
2955
|
+
:param op_type: Set to `create` to only index the document if it does not already
|
|
2495
2956
|
exist (put if absent). If a document with the specified `_id` already exists,
|
|
2496
|
-
the indexing operation will fail.
|
|
2497
|
-
|
|
2498
|
-
|
|
2499
|
-
|
|
2957
|
+
the indexing operation will fail. The behavior is the same as using the `<index>/_create`
|
|
2958
|
+
endpoint. If a document ID is specified, this paramater defaults to `index`.
|
|
2959
|
+
Otherwise, it defaults to `create`. If the request targets a data stream,
|
|
2960
|
+
an `op_type` of `create` is required.
|
|
2961
|
+
:param pipeline: The ID of the pipeline to use to preprocess incoming documents.
|
|
2500
2962
|
If the index has a default ingest pipeline specified, then setting the value
|
|
2501
2963
|
to `_none` disables the default ingest pipeline for this request. If a final
|
|
2502
2964
|
pipeline is configured it will always run, regardless of the value of this
|
|
2503
2965
|
parameter.
|
|
2504
2966
|
:param refresh: If `true`, Elasticsearch refreshes the affected shards to make
|
|
2505
|
-
this operation visible to search
|
|
2506
|
-
make this operation visible to search
|
|
2507
|
-
Valid values: `true`, `false`, `wait_for`.
|
|
2967
|
+
this operation visible to search. If `wait_for`, it waits for a refresh to
|
|
2968
|
+
make this operation visible to search. If `false`, it does nothing with refreshes.
|
|
2508
2969
|
:param require_alias: If `true`, the destination must be an index alias.
|
|
2509
|
-
:param routing:
|
|
2510
|
-
|
|
2511
|
-
|
|
2512
|
-
|
|
2513
|
-
|
|
2514
|
-
|
|
2515
|
-
|
|
2970
|
+
:param routing: A custom value that is used to route operations to a specific
|
|
2971
|
+
shard.
|
|
2972
|
+
:param timeout: The period the request waits for the following operations: automatic
|
|
2973
|
+
index creation, dynamic mapping updates, waiting for active shards. This
|
|
2974
|
+
parameter is useful for situations where the primary shard assigned to perform
|
|
2975
|
+
the operation might not be available when the operation runs. Some reasons
|
|
2976
|
+
for this might be that the primary shard is currently recovering from a gateway
|
|
2977
|
+
or undergoing relocation. By default, the operation will wait on the primary
|
|
2978
|
+
shard to become available for at least 1 minute before failing and responding
|
|
2979
|
+
with an error. The actual wait time could be longer, particularly when multiple
|
|
2980
|
+
waits occur.
|
|
2981
|
+
:param version: An explicit version number for concurrency control. It must be
|
|
2982
|
+
a non-negative long number.
|
|
2983
|
+
:param version_type: The version type.
|
|
2516
2984
|
:param wait_for_active_shards: The number of shard copies that must be active
|
|
2517
|
-
before proceeding with the operation.
|
|
2518
|
-
up to the total number of shards in the index (`number_of_replicas+1`).
|
|
2985
|
+
before proceeding with the operation. You can set it to `all` or any positive
|
|
2986
|
+
integer up to the total number of shards in the index (`number_of_replicas+1`).
|
|
2987
|
+
The default value of `1` means it waits for each primary shard to be active.
|
|
2519
2988
|
"""
|
|
2520
2989
|
if index in SKIP_IN_PATH:
|
|
2521
2990
|
raise ValueError("Empty value passed for parameter 'index'")
|
|
@@ -2547,6 +3016,8 @@ class Elasticsearch(BaseClient):
|
|
|
2547
3016
|
__query["if_primary_term"] = if_primary_term
|
|
2548
3017
|
if if_seq_no is not None:
|
|
2549
3018
|
__query["if_seq_no"] = if_seq_no
|
|
3019
|
+
if include_source_on_error is not None:
|
|
3020
|
+
__query["include_source_on_error"] = include_source_on_error
|
|
2550
3021
|
if op_type is not None:
|
|
2551
3022
|
__query["op_type"] = op_type
|
|
2552
3023
|
if pipeline is not None:
|
|
@@ -2589,9 +3060,13 @@ class Elasticsearch(BaseClient):
|
|
|
2589
3060
|
pretty: t.Optional[bool] = None,
|
|
2590
3061
|
) -> ObjectApiResponse[t.Any]:
|
|
2591
3062
|
"""
|
|
2592
|
-
|
|
3063
|
+
.. raw:: html
|
|
3064
|
+
|
|
3065
|
+
<p>Get cluster info.
|
|
3066
|
+
Get basic build, version, and cluster information.</p>
|
|
3067
|
+
|
|
2593
3068
|
|
|
2594
|
-
`<https://www.elastic.co/guide/en/elasticsearch/reference/8.
|
|
3069
|
+
`<https://www.elastic.co/guide/en/elasticsearch/reference/8.18/rest-api-root.html>`_
|
|
2595
3070
|
"""
|
|
2596
3071
|
__path_parts: t.Dict[str, str] = {}
|
|
2597
3072
|
__path = "/"
|
|
@@ -2646,38 +3121,48 @@ class Elasticsearch(BaseClient):
|
|
|
2646
3121
|
body: t.Optional[t.Dict[str, t.Any]] = None,
|
|
2647
3122
|
) -> ObjectApiResponse[t.Any]:
|
|
2648
3123
|
"""
|
|
2649
|
-
|
|
2650
|
-
|
|
2651
|
-
|
|
2652
|
-
|
|
2653
|
-
|
|
2654
|
-
|
|
2655
|
-
|
|
2656
|
-
|
|
2657
|
-
|
|
2658
|
-
|
|
2659
|
-
|
|
3124
|
+
.. raw:: html
|
|
3125
|
+
|
|
3126
|
+
<p>Run a knn search.</p>
|
|
3127
|
+
<p>NOTE: The kNN search API has been replaced by the <code>knn</code> option in the search API.</p>
|
|
3128
|
+
<p>Perform a k-nearest neighbor (kNN) search on a dense_vector field and return the matching documents.
|
|
3129
|
+
Given a query vector, the API finds the k closest vectors and returns those documents as search hits.</p>
|
|
3130
|
+
<p>Elasticsearch uses the HNSW algorithm to support efficient kNN search.
|
|
3131
|
+
Like most kNN algorithms, HNSW is an approximate method that sacrifices result accuracy for improved search speed.
|
|
3132
|
+
This means the results returned are not always the true k closest neighbors.</p>
|
|
3133
|
+
<p>The kNN search API supports restricting the search using a filter.
|
|
3134
|
+
The search will return the top k documents that also match the filter query.</p>
|
|
3135
|
+
<p>A kNN search response has the exact same structure as a search API response.
|
|
3136
|
+
However, certain sections have a meaning specific to kNN search:</p>
|
|
3137
|
+
<ul>
|
|
3138
|
+
<li>The document <code>_score</code> is determined by the similarity between the query and document vector.</li>
|
|
3139
|
+
<li>The <code>hits.total</code> object contains the total number of nearest neighbor candidates considered, which is <code>num_candidates * num_shards</code>. The <code>hits.total.relation</code> will always be <code>eq</code>, indicating an exact value.</li>
|
|
3140
|
+
</ul>
|
|
3141
|
+
|
|
3142
|
+
|
|
3143
|
+
`<https://www.elastic.co/guide/en/elasticsearch/reference/8.18/knn-search-api.html>`_
|
|
2660
3144
|
|
|
2661
3145
|
:param index: A comma-separated list of index names to search; use `_all` or
|
|
2662
|
-
to perform the operation on all indices
|
|
2663
|
-
:param knn: kNN query to
|
|
3146
|
+
to perform the operation on all indices.
|
|
3147
|
+
:param knn: The kNN query to run.
|
|
2664
3148
|
:param docvalue_fields: The request returns doc values for field names matching
|
|
2665
|
-
these patterns in the hits.fields property of the response.
|
|
2666
|
-
(
|
|
3149
|
+
these patterns in the `hits.fields` property of the response. It accepts
|
|
3150
|
+
wildcard (`*`) patterns.
|
|
2667
3151
|
:param fields: The request returns values for field names matching these patterns
|
|
2668
|
-
in the hits.fields property of the response.
|
|
2669
|
-
|
|
2670
|
-
|
|
2671
|
-
|
|
2672
|
-
|
|
2673
|
-
|
|
3152
|
+
in the `hits.fields` property of the response. It accepts wildcard (`*`)
|
|
3153
|
+
patterns.
|
|
3154
|
+
:param filter: A query to filter the documents that can match. The kNN search
|
|
3155
|
+
will return the top `k` documents that also match this filter. The value
|
|
3156
|
+
can be a single query or a list of queries. If `filter` isn't provided, all
|
|
3157
|
+
documents are allowed to match.
|
|
3158
|
+
:param routing: A comma-separated list of specific routing values.
|
|
2674
3159
|
:param source: Indicates which source fields are returned for matching documents.
|
|
2675
|
-
These fields are returned in the hits._source property of the search response.
|
|
2676
|
-
:param stored_fields:
|
|
2677
|
-
fields are specified, no stored fields are included in the response. If
|
|
2678
|
-
field is specified, the _source parameter defaults to false
|
|
2679
|
-
_source: true to return both source fields and stored fields in
|
|
2680
|
-
response.
|
|
3160
|
+
These fields are returned in the `hits._source` property of the search response.
|
|
3161
|
+
:param stored_fields: A list of stored fields to return as part of a hit. If
|
|
3162
|
+
no fields are specified, no stored fields are included in the response. If
|
|
3163
|
+
this field is specified, the `_source` parameter defaults to `false`. You
|
|
3164
|
+
can pass `_source: true` to return both source fields and stored fields in
|
|
3165
|
+
the search response.
|
|
2681
3166
|
"""
|
|
2682
3167
|
if index in SKIP_IN_PATH:
|
|
2683
3168
|
raise ValueError("Empty value passed for parameter 'index'")
|
|
@@ -2755,12 +3240,23 @@ class Elasticsearch(BaseClient):
|
|
|
2755
3240
|
body: t.Optional[t.Dict[str, t.Any]] = None,
|
|
2756
3241
|
) -> ObjectApiResponse[t.Any]:
|
|
2757
3242
|
"""
|
|
2758
|
-
|
|
2759
|
-
|
|
2760
|
-
|
|
2761
|
-
|
|
3243
|
+
.. raw:: html
|
|
3244
|
+
|
|
3245
|
+
<p>Get multiple documents.</p>
|
|
3246
|
+
<p>Get multiple JSON documents by ID from one or more indices.
|
|
3247
|
+
If you specify an index in the request URI, you only need to specify the document IDs in the request body.
|
|
3248
|
+
To ensure fast responses, this multi get (mget) API responds with partial results if one or more shards fail.</p>
|
|
3249
|
+
<p><strong>Filter source fields</strong></p>
|
|
3250
|
+
<p>By default, the <code>_source</code> field is returned for every document (if stored).
|
|
3251
|
+
Use the <code>_source</code> and <code>_source_include</code> or <code>source_exclude</code> attributes to filter what fields are returned for a particular document.
|
|
3252
|
+
You can include the <code>_source</code>, <code>_source_includes</code>, and <code>_source_excludes</code> query parameters in the request URI to specify the defaults to use when there are no per-document instructions.</p>
|
|
3253
|
+
<p><strong>Get stored fields</strong></p>
|
|
3254
|
+
<p>Use the <code>stored_fields</code> attribute to specify the set of stored fields you want to retrieve.
|
|
3255
|
+
Any requested fields that are not stored are ignored.
|
|
3256
|
+
You can include the <code>stored_fields</code> query parameter in the request URI to specify the defaults to use when there are no per-document instructions.</p>
|
|
3257
|
+
|
|
2762
3258
|
|
|
2763
|
-
`<https://www.elastic.co/guide/en/elasticsearch/reference/8.
|
|
3259
|
+
`<https://www.elastic.co/guide/en/elasticsearch/reference/8.18/docs-multi-get.html>`_
|
|
2764
3260
|
|
|
2765
3261
|
:param index: Name of the index to retrieve documents from when `ids` are specified,
|
|
2766
3262
|
or when a document in the `docs` array does not specify an index.
|
|
@@ -2879,15 +3375,23 @@ class Elasticsearch(BaseClient):
|
|
|
2879
3375
|
typed_keys: t.Optional[bool] = None,
|
|
2880
3376
|
) -> ObjectApiResponse[t.Any]:
|
|
2881
3377
|
"""
|
|
2882
|
-
|
|
2883
|
-
and makes use of the newline delimited JSON (NDJSON) format. The structure is
|
|
2884
|
-
as follows: ``` header\\n body\\n header\\n body\\n ``` This structure is specifically
|
|
2885
|
-
optimized to reduce parsing if a specific search ends up redirected to another
|
|
2886
|
-
node. IMPORTANT: The final line of data must end with a newline character `\\n`.
|
|
2887
|
-
Each newline character may be preceded by a carriage return `\\r`. When sending
|
|
2888
|
-
requests to this endpoint the `Content-Type` header should be set to `application/x-ndjson`.
|
|
3378
|
+
.. raw:: html
|
|
2889
3379
|
|
|
2890
|
-
|
|
3380
|
+
<p>Run multiple searches.</p>
|
|
3381
|
+
<p>The format of the request is similar to the bulk API format and makes use of the newline delimited JSON (NDJSON) format.
|
|
3382
|
+
The structure is as follows:</p>
|
|
3383
|
+
<pre><code>header\\n
|
|
3384
|
+
body\\n
|
|
3385
|
+
header\\n
|
|
3386
|
+
body\\n
|
|
3387
|
+
</code></pre>
|
|
3388
|
+
<p>This structure is specifically optimized to reduce parsing if a specific search ends up redirected to another node.</p>
|
|
3389
|
+
<p>IMPORTANT: The final line of data must end with a newline character <code>\\n</code>.
|
|
3390
|
+
Each newline character may be preceded by a carriage return <code>\\r</code>.
|
|
3391
|
+
When sending requests to this endpoint the <code>Content-Type</code> header should be set to <code>application/x-ndjson</code>.</p>
|
|
3392
|
+
|
|
3393
|
+
|
|
3394
|
+
`<https://www.elastic.co/guide/en/elasticsearch/reference/8.18/search-multi-search.html>`_
|
|
2891
3395
|
|
|
2892
3396
|
:param searches:
|
|
2893
3397
|
:param index: Comma-separated list of data streams, indices, and index aliases
|
|
@@ -3017,22 +3521,35 @@ class Elasticsearch(BaseClient):
|
|
|
3017
3521
|
typed_keys: t.Optional[bool] = None,
|
|
3018
3522
|
) -> ObjectApiResponse[t.Any]:
|
|
3019
3523
|
"""
|
|
3020
|
-
|
|
3524
|
+
.. raw:: html
|
|
3525
|
+
|
|
3526
|
+
<p>Run multiple templated searches.</p>
|
|
3527
|
+
<p>Run multiple templated searches with a single request.
|
|
3528
|
+
If you are providing a text file or text input to <code>curl</code>, use the <code>--data-binary</code> flag instead of <code>-d</code> to preserve newlines.
|
|
3529
|
+
For example:</p>
|
|
3530
|
+
<pre><code>$ cat requests
|
|
3531
|
+
{ "index": "my-index" }
|
|
3532
|
+
{ "id": "my-search-template", "params": { "query_string": "hello world", "from": 0, "size": 10 }}
|
|
3533
|
+
{ "index": "my-other-index" }
|
|
3534
|
+
{ "id": "my-other-search-template", "params": { "query_type": "match_all" }}
|
|
3021
3535
|
|
|
3022
|
-
|
|
3536
|
+
$ curl -H "Content-Type: application/x-ndjson" -XGET localhost:9200/_msearch/template --data-binary "@requests"; echo
|
|
3537
|
+
</code></pre>
|
|
3538
|
+
|
|
3539
|
+
|
|
3540
|
+
`<https://www.elastic.co/guide/en/elasticsearch/reference/8.18/multi-search-template.html>`_
|
|
3023
3541
|
|
|
3024
3542
|
:param search_templates:
|
|
3025
|
-
:param index:
|
|
3026
|
-
|
|
3027
|
-
parameter or use `*`.
|
|
3543
|
+
:param index: A comma-separated list of data streams, indices, and aliases to
|
|
3544
|
+
search. It supports wildcards (`*`). To search all data streams and indices,
|
|
3545
|
+
omit this parameter or use `*`.
|
|
3028
3546
|
:param ccs_minimize_roundtrips: If `true`, network round-trips are minimized
|
|
3029
3547
|
for cross-cluster search requests.
|
|
3030
|
-
:param max_concurrent_searches:
|
|
3031
|
-
can run.
|
|
3548
|
+
:param max_concurrent_searches: The maximum number of concurrent searches the
|
|
3549
|
+
API can run.
|
|
3032
3550
|
:param rest_total_hits_as_int: If `true`, the response returns `hits.total` as
|
|
3033
3551
|
an integer. If `false`, it returns `hits.total` as an object.
|
|
3034
|
-
:param search_type: The type of the search operation.
|
|
3035
|
-
`dfs_query_then_fetch`.
|
|
3552
|
+
:param search_type: The type of the search operation.
|
|
3036
3553
|
:param typed_keys: If `true`, the response prefixes aggregation and suggester
|
|
3037
3554
|
names with their respective types.
|
|
3038
3555
|
"""
|
|
@@ -3112,34 +3629,41 @@ class Elasticsearch(BaseClient):
|
|
|
3112
3629
|
body: t.Optional[t.Dict[str, t.Any]] = None,
|
|
3113
3630
|
) -> ObjectApiResponse[t.Any]:
|
|
3114
3631
|
"""
|
|
3115
|
-
|
|
3116
|
-
|
|
3117
|
-
|
|
3118
|
-
|
|
3119
|
-
|
|
3632
|
+
.. raw:: html
|
|
3633
|
+
|
|
3634
|
+
<p>Get multiple term vectors.</p>
|
|
3635
|
+
<p>Get multiple term vectors with a single request.
|
|
3636
|
+
You can specify existing documents by index and ID or provide artificial documents in the body of the request.
|
|
3637
|
+
You can specify the index in the request body or request URI.
|
|
3638
|
+
The response contains a <code>docs</code> array with all the fetched termvectors.
|
|
3639
|
+
Each element has the structure provided by the termvectors API.</p>
|
|
3640
|
+
<p><strong>Artificial documents</strong></p>
|
|
3641
|
+
<p>You can also use <code>mtermvectors</code> to generate term vectors for artificial documents provided in the body of the request.
|
|
3642
|
+
The mapping used is determined by the specified <code>_index</code>.</p>
|
|
3643
|
+
|
|
3120
3644
|
|
|
3121
|
-
`<https://www.elastic.co/guide/en/elasticsearch/reference/8.
|
|
3645
|
+
`<https://www.elastic.co/guide/en/elasticsearch/reference/8.18/docs-multi-termvectors.html>`_
|
|
3122
3646
|
|
|
3123
|
-
:param index:
|
|
3124
|
-
:param docs:
|
|
3647
|
+
:param index: The name of the index that contains the documents.
|
|
3648
|
+
:param docs: An array of existing or artificial documents.
|
|
3125
3649
|
:param field_statistics: If `true`, the response includes the document count,
|
|
3126
3650
|
sum of document frequencies, and sum of total term frequencies.
|
|
3127
|
-
:param fields:
|
|
3128
|
-
in the statistics.
|
|
3129
|
-
is provided in the `completion_fields` or `fielddata_fields` parameters.
|
|
3130
|
-
:param ids:
|
|
3651
|
+
:param fields: A comma-separated list or wildcard expressions of fields to include
|
|
3652
|
+
in the statistics. It is used as the default list unless a specific field
|
|
3653
|
+
list is provided in the `completion_fields` or `fielddata_fields` parameters.
|
|
3654
|
+
:param ids: A simplified syntax to specify documents by their ID if they're in
|
|
3131
3655
|
the same index.
|
|
3132
3656
|
:param offsets: If `true`, the response includes term offsets.
|
|
3133
3657
|
:param payloads: If `true`, the response includes term payloads.
|
|
3134
3658
|
:param positions: If `true`, the response includes term positions.
|
|
3135
|
-
:param preference:
|
|
3136
|
-
|
|
3659
|
+
:param preference: The node or shard the operation should be performed on. It
|
|
3660
|
+
is random by default.
|
|
3137
3661
|
:param realtime: If true, the request is real-time as opposed to near-real-time.
|
|
3138
|
-
:param routing:
|
|
3662
|
+
:param routing: A custom value used to route operations to a specific shard.
|
|
3139
3663
|
:param term_statistics: If true, the response includes term frequency and document
|
|
3140
3664
|
frequency.
|
|
3141
3665
|
:param version: If `true`, returns the document version as part of a hit.
|
|
3142
|
-
:param version_type:
|
|
3666
|
+
:param version_type: The version type.
|
|
3143
3667
|
"""
|
|
3144
3668
|
__path_parts: t.Dict[str, str]
|
|
3145
3669
|
if index not in SKIP_IN_PATH:
|
|
@@ -3222,42 +3746,68 @@ class Elasticsearch(BaseClient):
|
|
|
3222
3746
|
human: t.Optional[bool] = None,
|
|
3223
3747
|
ignore_unavailable: t.Optional[bool] = None,
|
|
3224
3748
|
index_filter: t.Optional[t.Mapping[str, t.Any]] = None,
|
|
3749
|
+
max_concurrent_shard_requests: t.Optional[int] = None,
|
|
3225
3750
|
preference: t.Optional[str] = None,
|
|
3226
3751
|
pretty: t.Optional[bool] = None,
|
|
3227
3752
|
routing: t.Optional[str] = None,
|
|
3228
3753
|
body: t.Optional[t.Dict[str, t.Any]] = None,
|
|
3229
3754
|
) -> ObjectApiResponse[t.Any]:
|
|
3230
3755
|
"""
|
|
3231
|
-
|
|
3232
|
-
|
|
3233
|
-
|
|
3234
|
-
|
|
3235
|
-
|
|
3236
|
-
|
|
3237
|
-
|
|
3238
|
-
|
|
3239
|
-
|
|
3240
|
-
|
|
3241
|
-
|
|
3756
|
+
.. raw:: html
|
|
3757
|
+
|
|
3758
|
+
<p>Open a point in time.</p>
|
|
3759
|
+
<p>A search request by default runs against the most recent visible data of the target indices,
|
|
3760
|
+
which is called point in time. Elasticsearch pit (point in time) is a lightweight view into the
|
|
3761
|
+
state of the data as it existed when initiated. In some cases, it’s preferred to perform multiple
|
|
3762
|
+
search requests using the same point in time. For example, if refreshes happen between
|
|
3763
|
+
<code>search_after</code> requests, then the results of those requests might not be consistent as changes happening
|
|
3764
|
+
between searches are only visible to the more recent point in time.</p>
|
|
3765
|
+
<p>A point in time must be opened explicitly before being used in search requests.</p>
|
|
3766
|
+
<p>A subsequent search request with the <code>pit</code> parameter must not specify <code>index</code>, <code>routing</code>, or <code>preference</code> values as these parameters are copied from the point in time.</p>
|
|
3767
|
+
<p>Just like regular searches, you can use <code>from</code> and <code>size</code> to page through point in time search results, up to the first 10,000 hits.
|
|
3768
|
+
If you want to retrieve more hits, use PIT with <code>search_after</code>.</p>
|
|
3769
|
+
<p>IMPORTANT: The open point in time request and each subsequent search request can return different identifiers; always use the most recently received ID for the next search request.</p>
|
|
3770
|
+
<p>When a PIT that contains shard failures is used in a search request, the missing are always reported in the search response as a <code>NoShardAvailableActionException</code> exception.
|
|
3771
|
+
To get rid of these exceptions, a new PIT needs to be created so that shards missing from the previous PIT can be handled, assuming they become available in the meantime.</p>
|
|
3772
|
+
<p><strong>Keeping point in time alive</strong></p>
|
|
3773
|
+
<p>The <code>keep_alive</code> parameter, which is passed to a open point in time request and search request, extends the time to live of the corresponding point in time.
|
|
3774
|
+
The value does not need to be long enough to process all data — it just needs to be long enough for the next request.</p>
|
|
3775
|
+
<p>Normally, the background merge process optimizes the index by merging together smaller segments to create new, bigger segments.
|
|
3776
|
+
Once the smaller segments are no longer needed they are deleted.
|
|
3777
|
+
However, open point-in-times prevent the old segments from being deleted since they are still in use.</p>
|
|
3778
|
+
<p>TIP: Keeping older segments alive means that more disk space and file handles are needed.
|
|
3779
|
+
Ensure that you have configured your nodes to have ample free file handles.</p>
|
|
3780
|
+
<p>Additionally, if a segment contains deleted or updated documents then the point in time must keep track of whether each document in the segment was live at the time of the initial search request.
|
|
3781
|
+
Ensure that your nodes have sufficient heap space if you have many open point-in-times on an index that is subject to ongoing deletes or updates.
|
|
3782
|
+
Note that a point-in-time doesn't prevent its associated indices from being deleted.
|
|
3783
|
+
You can check how many point-in-times (that is, search contexts) are open with the nodes stats API.</p>
|
|
3784
|
+
|
|
3785
|
+
|
|
3786
|
+
`<https://www.elastic.co/guide/en/elasticsearch/reference/8.18/point-in-time-api.html>`_
|
|
3242
3787
|
|
|
3243
3788
|
:param index: A comma-separated list of index names to open point in time; use
|
|
3244
3789
|
`_all` or empty string to perform the operation on all indices
|
|
3245
|
-
:param keep_alive:
|
|
3246
|
-
:param allow_partial_search_results:
|
|
3247
|
-
|
|
3248
|
-
|
|
3249
|
-
|
|
3250
|
-
|
|
3251
|
-
|
|
3252
|
-
|
|
3253
|
-
|
|
3790
|
+
:param keep_alive: Extend the length of time that the point in time persists.
|
|
3791
|
+
:param allow_partial_search_results: Indicates whether the point in time tolerates
|
|
3792
|
+
unavailable shards or shard failures when initially creating the PIT. If
|
|
3793
|
+
`false`, creating a point in time request when a shard is missing or unavailable
|
|
3794
|
+
will throw an exception. If `true`, the point in time will contain all the
|
|
3795
|
+
shards that are available at the time of the request.
|
|
3796
|
+
:param expand_wildcards: The type of index that wildcard patterns can match.
|
|
3797
|
+
If the request can target data streams, this argument determines whether
|
|
3798
|
+
wildcard expressions match hidden data streams. It supports comma-separated
|
|
3799
|
+
values, such as `open,hidden`. Valid values are: `all`, `open`, `closed`,
|
|
3800
|
+
`hidden`, `none`.
|
|
3254
3801
|
:param ignore_unavailable: If `false`, the request returns an error if it targets
|
|
3255
3802
|
a missing or closed index.
|
|
3256
|
-
:param index_filter:
|
|
3257
|
-
|
|
3258
|
-
:param
|
|
3259
|
-
|
|
3260
|
-
:param
|
|
3803
|
+
:param index_filter: Filter indices if the provided query rewrites to `match_none`
|
|
3804
|
+
on every shard.
|
|
3805
|
+
:param max_concurrent_shard_requests: Maximum number of concurrent shard requests
|
|
3806
|
+
that each sub-search request executes per node.
|
|
3807
|
+
:param preference: The node or shard the operation should be performed on. By
|
|
3808
|
+
default, it is random.
|
|
3809
|
+
:param routing: A custom value that is used to route operations to a specific
|
|
3810
|
+
shard.
|
|
3261
3811
|
"""
|
|
3262
3812
|
if index in SKIP_IN_PATH:
|
|
3263
3813
|
raise ValueError("Empty value passed for parameter 'index'")
|
|
@@ -3281,6 +3831,8 @@ class Elasticsearch(BaseClient):
|
|
|
3281
3831
|
__query["human"] = human
|
|
3282
3832
|
if ignore_unavailable is not None:
|
|
3283
3833
|
__query["ignore_unavailable"] = ignore_unavailable
|
|
3834
|
+
if max_concurrent_shard_requests is not None:
|
|
3835
|
+
__query["max_concurrent_shard_requests"] = max_concurrent_shard_requests
|
|
3284
3836
|
if preference is not None:
|
|
3285
3837
|
__query["preference"] = preference
|
|
3286
3838
|
if pretty is not None:
|
|
@@ -3323,23 +3875,27 @@ class Elasticsearch(BaseClient):
|
|
|
3323
3875
|
body: t.Optional[t.Dict[str, t.Any]] = None,
|
|
3324
3876
|
) -> ObjectApiResponse[t.Any]:
|
|
3325
3877
|
"""
|
|
3326
|
-
|
|
3327
|
-
|
|
3328
|
-
|
|
3329
|
-
|
|
3330
|
-
|
|
3331
|
-
|
|
3332
|
-
|
|
3333
|
-
|
|
3334
|
-
|
|
3335
|
-
|
|
3336
|
-
|
|
3337
|
-
|
|
3338
|
-
|
|
3339
|
-
|
|
3340
|
-
|
|
3341
|
-
|
|
3342
|
-
|
|
3878
|
+
.. raw:: html
|
|
3879
|
+
|
|
3880
|
+
<p>Create or update a script or search template.
|
|
3881
|
+
Creates or updates a stored script or search template.</p>
|
|
3882
|
+
|
|
3883
|
+
|
|
3884
|
+
`<https://www.elastic.co/guide/en/elasticsearch/reference/8.18/create-stored-script-api.html>`_
|
|
3885
|
+
|
|
3886
|
+
:param id: The identifier for the stored script or search template. It must be
|
|
3887
|
+
unique within the cluster.
|
|
3888
|
+
:param script: The script or search template, its parameters, and its language.
|
|
3889
|
+
:param context: The context in which the script or search template should run.
|
|
3890
|
+
To prevent errors, the API immediately compiles the script or template in
|
|
3891
|
+
this context.
|
|
3892
|
+
:param master_timeout: The period to wait for a connection to the master node.
|
|
3893
|
+
If no response is received before the timeout expires, the request fails
|
|
3894
|
+
and returns an error. It can also be set to `-1` to indicate that the request
|
|
3895
|
+
should never timeout.
|
|
3896
|
+
:param timeout: The period to wait for a response. If no response is received
|
|
3897
|
+
before the timeout expires, the request fails and returns an error. It can
|
|
3898
|
+
also be set to `-1` to indicate that the request should never timeout.
|
|
3343
3899
|
"""
|
|
3344
3900
|
if id in SKIP_IN_PATH:
|
|
3345
3901
|
raise ValueError("Empty value passed for parameter 'id'")
|
|
@@ -3409,14 +3965,17 @@ class Elasticsearch(BaseClient):
|
|
|
3409
3965
|
body: t.Optional[t.Dict[str, t.Any]] = None,
|
|
3410
3966
|
) -> ObjectApiResponse[t.Any]:
|
|
3411
3967
|
"""
|
|
3412
|
-
|
|
3413
|
-
|
|
3968
|
+
.. raw:: html
|
|
3969
|
+
|
|
3970
|
+
<p>Evaluate ranked search results.</p>
|
|
3971
|
+
<p>Evaluate the quality of ranked search results over a set of typical search queries.</p>
|
|
3414
3972
|
|
|
3415
|
-
|
|
3973
|
+
|
|
3974
|
+
`<https://www.elastic.co/guide/en/elasticsearch/reference/8.18/search-rank-eval.html>`_
|
|
3416
3975
|
|
|
3417
3976
|
:param requests: A set of typical search requests, together with their provided
|
|
3418
3977
|
ratings.
|
|
3419
|
-
:param index:
|
|
3978
|
+
:param index: A comma-separated list of data streams, indices, and index aliases
|
|
3420
3979
|
used to limit the request. Wildcard (`*`) expressions are supported. To target
|
|
3421
3980
|
all data streams and indices in a cluster, omit this parameter or use `_all`
|
|
3422
3981
|
or `*`.
|
|
@@ -3504,33 +4063,187 @@ class Elasticsearch(BaseClient):
|
|
|
3504
4063
|
body: t.Optional[t.Dict[str, t.Any]] = None,
|
|
3505
4064
|
) -> ObjectApiResponse[t.Any]:
|
|
3506
4065
|
"""
|
|
3507
|
-
|
|
3508
|
-
|
|
3509
|
-
|
|
3510
|
-
|
|
3511
|
-
|
|
4066
|
+
.. raw:: html
|
|
4067
|
+
|
|
4068
|
+
<p>Reindex documents.</p>
|
|
4069
|
+
<p>Copy documents from a source to a destination.
|
|
4070
|
+
You can copy all documents to the destination index or reindex a subset of the documents.
|
|
4071
|
+
The source can be any existing index, alias, or data stream.
|
|
4072
|
+
The destination must differ from the source.
|
|
4073
|
+
For example, you cannot reindex a data stream into itself.</p>
|
|
4074
|
+
<p>IMPORTANT: Reindex requires <code>_source</code> to be enabled for all documents in the source.
|
|
4075
|
+
The destination should be configured as wanted before calling the reindex API.
|
|
4076
|
+
Reindex does not copy the settings from the source or its associated template.
|
|
4077
|
+
Mappings, shard counts, and replicas, for example, must be configured ahead of time.</p>
|
|
4078
|
+
<p>If the Elasticsearch security features are enabled, you must have the following security privileges:</p>
|
|
4079
|
+
<ul>
|
|
4080
|
+
<li>The <code>read</code> index privilege for the source data stream, index, or alias.</li>
|
|
4081
|
+
<li>The <code>write</code> index privilege for the destination data stream, index, or index alias.</li>
|
|
4082
|
+
<li>To automatically create a data stream or index with a reindex API request, you must have the <code>auto_configure</code>, <code>create_index</code>, or <code>manage</code> index privilege for the destination data stream, index, or alias.</li>
|
|
4083
|
+
<li>If reindexing from a remote cluster, the <code>source.remote.user</code> must have the <code>monitor</code> cluster privilege and the <code>read</code> index privilege for the source data stream, index, or alias.</li>
|
|
4084
|
+
</ul>
|
|
4085
|
+
<p>If reindexing from a remote cluster, you must explicitly allow the remote host in the <code>reindex.remote.whitelist</code> setting.
|
|
4086
|
+
Automatic data stream creation requires a matching index template with data stream enabled.</p>
|
|
4087
|
+
<p>The <code>dest</code> element can be configured like the index API to control optimistic concurrency control.
|
|
4088
|
+
Omitting <code>version_type</code> or setting it to <code>internal</code> causes Elasticsearch to blindly dump documents into the destination, overwriting any that happen to have the same ID.</p>
|
|
4089
|
+
<p>Setting <code>version_type</code> to <code>external</code> causes Elasticsearch to preserve the <code>version</code> from the source, create any documents that are missing, and update any documents that have an older version in the destination than they do in the source.</p>
|
|
4090
|
+
<p>Setting <code>op_type</code> to <code>create</code> causes the reindex API to create only missing documents in the destination.
|
|
4091
|
+
All existing documents will cause a version conflict.</p>
|
|
4092
|
+
<p>IMPORTANT: Because data streams are append-only, any reindex request to a destination data stream must have an <code>op_type</code> of <code>create</code>.
|
|
4093
|
+
A reindex can only add new documents to a destination data stream.
|
|
4094
|
+
It cannot update existing documents in a destination data stream.</p>
|
|
4095
|
+
<p>By default, version conflicts abort the reindex process.
|
|
4096
|
+
To continue reindexing if there are conflicts, set the <code>conflicts</code> request body property to <code>proceed</code>.
|
|
4097
|
+
In this case, the response includes a count of the version conflicts that were encountered.
|
|
4098
|
+
Note that the handling of other error types is unaffected by the <code>conflicts</code> property.
|
|
4099
|
+
Additionally, if you opt to count version conflicts, the operation could attempt to reindex more documents from the source than <code>max_docs</code> until it has successfully indexed <code>max_docs</code> documents into the target or it has gone through every document in the source query.</p>
|
|
4100
|
+
<p>NOTE: The reindex API makes no effort to handle ID collisions.
|
|
4101
|
+
The last document written will "win" but the order isn't usually predictable so it is not a good idea to rely on this behavior.
|
|
4102
|
+
Instead, make sure that IDs are unique by using a script.</p>
|
|
4103
|
+
<p><strong>Running reindex asynchronously</strong></p>
|
|
4104
|
+
<p>If the request contains <code>wait_for_completion=false</code>, Elasticsearch performs some preflight checks, launches the request, and returns a task you can use to cancel or get the status of the task.
|
|
4105
|
+
Elasticsearch creates a record of this task as a document at <code>_tasks/<task_id></code>.</p>
|
|
4106
|
+
<p><strong>Reindex from multiple sources</strong></p>
|
|
4107
|
+
<p>If you have many sources to reindex it is generally better to reindex them one at a time rather than using a glob pattern to pick up multiple sources.
|
|
4108
|
+
That way you can resume the process if there are any errors by removing the partially completed source and starting over.
|
|
4109
|
+
It also makes parallelizing the process fairly simple: split the list of sources to reindex and run each list in parallel.</p>
|
|
4110
|
+
<p>For example, you can use a bash script like this:</p>
|
|
4111
|
+
<pre><code>for index in i1 i2 i3 i4 i5; do
|
|
4112
|
+
curl -HContent-Type:application/json -XPOST localhost:9200/_reindex?pretty -d'{
|
|
4113
|
+
"source": {
|
|
4114
|
+
"index": "'$index'"
|
|
4115
|
+
},
|
|
4116
|
+
"dest": {
|
|
4117
|
+
"index": "'$index'-reindexed"
|
|
4118
|
+
}
|
|
4119
|
+
}'
|
|
4120
|
+
done
|
|
4121
|
+
</code></pre>
|
|
4122
|
+
<p><strong>Throttling</strong></p>
|
|
4123
|
+
<p>Set <code>requests_per_second</code> to any positive decimal number (<code>1.4</code>, <code>6</code>, <code>1000</code>, for example) to throttle the rate at which reindex issues batches of index operations.
|
|
4124
|
+
Requests are throttled by padding each batch with a wait time.
|
|
4125
|
+
To turn off throttling, set <code>requests_per_second</code> to <code>-1</code>.</p>
|
|
4126
|
+
<p>The throttling is done by waiting between batches so that the scroll that reindex uses internally can be given a timeout that takes into account the padding.
|
|
4127
|
+
The padding time is the difference between the batch size divided by the <code>requests_per_second</code> and the time spent writing.
|
|
4128
|
+
By default the batch size is <code>1000</code>, so if <code>requests_per_second</code> is set to <code>500</code>:</p>
|
|
4129
|
+
<pre><code>target_time = 1000 / 500 per second = 2 seconds
|
|
4130
|
+
wait_time = target_time - write_time = 2 seconds - .5 seconds = 1.5 seconds
|
|
4131
|
+
</code></pre>
|
|
4132
|
+
<p>Since the batch is issued as a single bulk request, large batch sizes cause Elasticsearch to create many requests and then wait for a while before starting the next set.
|
|
4133
|
+
This is "bursty" instead of "smooth".</p>
|
|
4134
|
+
<p><strong>Slicing</strong></p>
|
|
4135
|
+
<p>Reindex supports sliced scroll to parallelize the reindexing process.
|
|
4136
|
+
This parallelization can improve efficiency and provide a convenient way to break the request down into smaller parts.</p>
|
|
4137
|
+
<p>NOTE: Reindexing from remote clusters does not support manual or automatic slicing.</p>
|
|
4138
|
+
<p>You can slice a reindex request manually by providing a slice ID and total number of slices to each request.
|
|
4139
|
+
You can also let reindex automatically parallelize by using sliced scroll to slice on <code>_id</code>.
|
|
4140
|
+
The <code>slices</code> parameter specifies the number of slices to use.</p>
|
|
4141
|
+
<p>Adding <code>slices</code> to the reindex request just automates the manual process, creating sub-requests which means it has some quirks:</p>
|
|
4142
|
+
<ul>
|
|
4143
|
+
<li>You can see these requests in the tasks API. These sub-requests are "child" tasks of the task for the request with slices.</li>
|
|
4144
|
+
<li>Fetching the status of the task for the request with <code>slices</code> only contains the status of completed slices.</li>
|
|
4145
|
+
<li>These sub-requests are individually addressable for things like cancellation and rethrottling.</li>
|
|
4146
|
+
<li>Rethrottling the request with <code>slices</code> will rethrottle the unfinished sub-request proportionally.</li>
|
|
4147
|
+
<li>Canceling the request with <code>slices</code> will cancel each sub-request.</li>
|
|
4148
|
+
<li>Due to the nature of <code>slices</code>, each sub-request won't get a perfectly even portion of the documents. All documents will be addressed, but some slices may be larger than others. Expect larger slices to have a more even distribution.</li>
|
|
4149
|
+
<li>Parameters like <code>requests_per_second</code> and <code>max_docs</code> on a request with <code>slices</code> are distributed proportionally to each sub-request. Combine that with the previous point about distribution being uneven and you should conclude that using <code>max_docs</code> with <code>slices</code> might not result in exactly <code>max_docs</code> documents being reindexed.</li>
|
|
4150
|
+
<li>Each sub-request gets a slightly different snapshot of the source, though these are all taken at approximately the same time.</li>
|
|
4151
|
+
</ul>
|
|
4152
|
+
<p>If slicing automatically, setting <code>slices</code> to <code>auto</code> will choose a reasonable number for most indices.
|
|
4153
|
+
If slicing manually or otherwise tuning automatic slicing, use the following guidelines.</p>
|
|
4154
|
+
<p>Query performance is most efficient when the number of slices is equal to the number of shards in the index.
|
|
4155
|
+
If that number is large (for example, <code>500</code>), choose a lower number as too many slices will hurt performance.
|
|
4156
|
+
Setting slices higher than the number of shards generally does not improve efficiency and adds overhead.</p>
|
|
4157
|
+
<p>Indexing performance scales linearly across available resources with the number of slices.</p>
|
|
4158
|
+
<p>Whether query or indexing performance dominates the runtime depends on the documents being reindexed and cluster resources.</p>
|
|
4159
|
+
<p><strong>Modify documents during reindexing</strong></p>
|
|
4160
|
+
<p>Like <code>_update_by_query</code>, reindex operations support a script that modifies the document.
|
|
4161
|
+
Unlike <code>_update_by_query</code>, the script is allowed to modify the document's metadata.</p>
|
|
4162
|
+
<p>Just as in <code>_update_by_query</code>, you can set <code>ctx.op</code> to change the operation that is run on the destination.
|
|
4163
|
+
For example, set <code>ctx.op</code> to <code>noop</code> if your script decides that the document doesn’t have to be indexed in the destination. This "no operation" will be reported in the <code>noop</code> counter in the response body.
|
|
4164
|
+
Set <code>ctx.op</code> to <code>delete</code> if your script decides that the document must be deleted from the destination.
|
|
4165
|
+
The deletion will be reported in the <code>deleted</code> counter in the response body.
|
|
4166
|
+
Setting <code>ctx.op</code> to anything else will return an error, as will setting any other field in <code>ctx</code>.</p>
|
|
4167
|
+
<p>Think of the possibilities! Just be careful; you are able to change:</p>
|
|
4168
|
+
<ul>
|
|
4169
|
+
<li><code>_id</code></li>
|
|
4170
|
+
<li><code>_index</code></li>
|
|
4171
|
+
<li><code>_version</code></li>
|
|
4172
|
+
<li><code>_routing</code></li>
|
|
4173
|
+
</ul>
|
|
4174
|
+
<p>Setting <code>_version</code> to <code>null</code> or clearing it from the <code>ctx</code> map is just like not sending the version in an indexing request.
|
|
4175
|
+
It will cause the document to be overwritten in the destination regardless of the version on the target or the version type you use in the reindex API.</p>
|
|
4176
|
+
<p><strong>Reindex from remote</strong></p>
|
|
4177
|
+
<p>Reindex supports reindexing from a remote Elasticsearch cluster.
|
|
4178
|
+
The <code>host</code> parameter must contain a scheme, host, port, and optional path.
|
|
4179
|
+
The <code>username</code> and <code>password</code> parameters are optional and when they are present the reindex operation will connect to the remote Elasticsearch node using basic authentication.
|
|
4180
|
+
Be sure to use HTTPS when using basic authentication or the password will be sent in plain text.
|
|
4181
|
+
There are a range of settings available to configure the behavior of the HTTPS connection.</p>
|
|
4182
|
+
<p>When using Elastic Cloud, it is also possible to authenticate against the remote cluster through the use of a valid API key.
|
|
4183
|
+
Remote hosts must be explicitly allowed with the <code>reindex.remote.whitelist</code> setting.
|
|
4184
|
+
It can be set to a comma delimited list of allowed remote host and port combinations.
|
|
4185
|
+
Scheme is ignored; only the host and port are used.
|
|
4186
|
+
For example:</p>
|
|
4187
|
+
<pre><code>reindex.remote.whitelist: [otherhost:9200, another:9200, 127.0.10.*:9200, localhost:*"]
|
|
4188
|
+
</code></pre>
|
|
4189
|
+
<p>The list of allowed hosts must be configured on any nodes that will coordinate the reindex.
|
|
4190
|
+
This feature should work with remote clusters of any version of Elasticsearch.
|
|
4191
|
+
This should enable you to upgrade from any version of Elasticsearch to the current version by reindexing from a cluster of the old version.</p>
|
|
4192
|
+
<p>WARNING: Elasticsearch does not support forward compatibility across major versions.
|
|
4193
|
+
For example, you cannot reindex from a 7.x cluster into a 6.x cluster.</p>
|
|
4194
|
+
<p>To enable queries sent to older versions of Elasticsearch, the <code>query</code> parameter is sent directly to the remote host without validation or modification.</p>
|
|
4195
|
+
<p>NOTE: Reindexing from remote clusters does not support manual or automatic slicing.</p>
|
|
4196
|
+
<p>Reindexing from a remote server uses an on-heap buffer that defaults to a maximum size of 100mb.
|
|
4197
|
+
If the remote index includes very large documents you'll need to use a smaller batch size.
|
|
4198
|
+
It is also possible to set the socket read timeout on the remote connection with the <code>socket_timeout</code> field and the connection timeout with the <code>connect_timeout</code> field.
|
|
4199
|
+
Both default to 30 seconds.</p>
|
|
4200
|
+
<p><strong>Configuring SSL parameters</strong></p>
|
|
4201
|
+
<p>Reindex from remote supports configurable SSL settings.
|
|
4202
|
+
These must be specified in the <code>elasticsearch.yml</code> file, with the exception of the secure settings, which you add in the Elasticsearch keystore.
|
|
4203
|
+
It is not possible to configure SSL in the body of the reindex request.</p>
|
|
4204
|
+
|
|
4205
|
+
|
|
4206
|
+
`<https://www.elastic.co/guide/en/elasticsearch/reference/8.18/docs-reindex.html>`_
|
|
3512
4207
|
|
|
3513
4208
|
:param dest: The destination you are copying to.
|
|
3514
4209
|
:param source: The source you are copying from.
|
|
3515
|
-
:param conflicts:
|
|
3516
|
-
|
|
4210
|
+
:param conflicts: Indicates whether to continue reindexing even when there are
|
|
4211
|
+
conflicts.
|
|
4212
|
+
:param max_docs: The maximum number of documents to reindex. By default, all
|
|
4213
|
+
documents are reindexed. If it is a value less then or equal to `scroll_size`,
|
|
4214
|
+
a scroll will not be used to retrieve the results for the operation. If `conflicts`
|
|
4215
|
+
is set to `proceed`, the reindex operation could attempt to reindex more
|
|
4216
|
+
documents from the source than `max_docs` until it has successfully indexed
|
|
4217
|
+
`max_docs` documents into the target or it has gone through every document
|
|
4218
|
+
in the source query.
|
|
3517
4219
|
:param refresh: If `true`, the request refreshes affected shards to make this
|
|
3518
4220
|
operation visible to search.
|
|
3519
4221
|
:param requests_per_second: The throttle for this request in sub-requests per
|
|
3520
|
-
second.
|
|
4222
|
+
second. By default, there is no throttle.
|
|
3521
4223
|
:param require_alias: If `true`, the destination must be an index alias.
|
|
3522
4224
|
:param script: The script to run to update the document source or metadata when
|
|
3523
4225
|
reindexing.
|
|
3524
|
-
:param scroll:
|
|
3525
|
-
for scrolled search.
|
|
4226
|
+
:param scroll: The period of time that a consistent view of the index should
|
|
4227
|
+
be maintained for scrolled search.
|
|
3526
4228
|
:param size:
|
|
3527
|
-
:param slices: The number of slices this task should be divided into.
|
|
3528
|
-
to
|
|
3529
|
-
|
|
3530
|
-
|
|
4229
|
+
:param slices: The number of slices this task should be divided into. It defaults
|
|
4230
|
+
to one slice, which means the task isn't sliced into subtasks. Reindex supports
|
|
4231
|
+
sliced scroll to parallelize the reindexing process. This parallelization
|
|
4232
|
+
can improve efficiency and provide a convenient way to break the request
|
|
4233
|
+
down into smaller parts. NOTE: Reindexing from remote clusters does not support
|
|
4234
|
+
manual or automatic slicing. If set to `auto`, Elasticsearch chooses the
|
|
4235
|
+
number of slices to use. This setting will use one slice per shard, up to
|
|
4236
|
+
a certain limit. If there are multiple sources, it will choose the number
|
|
4237
|
+
of slices based on the index or backing index with the smallest number of
|
|
4238
|
+
shards.
|
|
4239
|
+
:param timeout: The period each indexing waits for automatic index creation,
|
|
4240
|
+
dynamic mapping updates, and waiting for active shards. By default, Elasticsearch
|
|
4241
|
+
waits for at least one minute before failing. The actual wait time could
|
|
4242
|
+
be longer, particularly when multiple waits occur.
|
|
3531
4243
|
:param wait_for_active_shards: The number of shard copies that must be active
|
|
3532
|
-
before proceeding with the operation. Set to `all` or any positive integer
|
|
3533
|
-
up to the total number of shards in the index (`number_of_replicas+1`).
|
|
4244
|
+
before proceeding with the operation. Set it to `all` or any positive integer
|
|
4245
|
+
up to the total number of shards in the index (`number_of_replicas+1`). The
|
|
4246
|
+
default value is one, which means it waits for each primary shard to be active.
|
|
3534
4247
|
:param wait_for_completion: If `true`, the request blocks until the operation
|
|
3535
4248
|
is complete.
|
|
3536
4249
|
"""
|
|
@@ -3602,14 +4315,24 @@ class Elasticsearch(BaseClient):
|
|
|
3602
4315
|
requests_per_second: t.Optional[float] = None,
|
|
3603
4316
|
) -> ObjectApiResponse[t.Any]:
|
|
3604
4317
|
"""
|
|
3605
|
-
|
|
3606
|
-
particular reindex operation.
|
|
4318
|
+
.. raw:: html
|
|
3607
4319
|
|
|
3608
|
-
|
|
4320
|
+
<p>Throttle a reindex operation.</p>
|
|
4321
|
+
<p>Change the number of requests per second for a particular reindex operation.
|
|
4322
|
+
For example:</p>
|
|
4323
|
+
<pre><code>POST _reindex/r1A2WoRbTwKZ516z6NEs5A:36619/_rethrottle?requests_per_second=-1
|
|
4324
|
+
</code></pre>
|
|
4325
|
+
<p>Rethrottling that speeds up the query takes effect immediately.
|
|
4326
|
+
Rethrottling that slows down the query will take effect after completing the current batch.
|
|
4327
|
+
This behavior prevents scroll timeouts.</p>
|
|
3609
4328
|
|
|
3610
|
-
|
|
4329
|
+
|
|
4330
|
+
`<https://www.elastic.co/guide/en/elasticsearch/reference/8.18/docs-reindex.html>`_
|
|
4331
|
+
|
|
4332
|
+
:param task_id: The task identifier, which can be found by using the tasks API.
|
|
3611
4333
|
:param requests_per_second: The throttle for this request in sub-requests per
|
|
3612
|
-
second.
|
|
4334
|
+
second. It can be either `-1` to turn off throttling or any decimal number
|
|
4335
|
+
like `1.7` or `12` to throttle to that level.
|
|
3613
4336
|
"""
|
|
3614
4337
|
if task_id in SKIP_IN_PATH:
|
|
3615
4338
|
raise ValueError("Empty value passed for parameter 'task_id'")
|
|
@@ -3654,17 +4377,21 @@ class Elasticsearch(BaseClient):
|
|
|
3654
4377
|
body: t.Optional[t.Dict[str, t.Any]] = None,
|
|
3655
4378
|
) -> ObjectApiResponse[t.Any]:
|
|
3656
4379
|
"""
|
|
3657
|
-
|
|
4380
|
+
.. raw:: html
|
|
3658
4381
|
|
|
3659
|
-
|
|
4382
|
+
<p>Render a search template.</p>
|
|
4383
|
+
<p>Render a search template as a search request body.</p>
|
|
3660
4384
|
|
|
3661
|
-
|
|
4385
|
+
|
|
4386
|
+
`<https://www.elastic.co/guide/en/elasticsearch/reference/8.18/render-search-template-api.html>`_
|
|
4387
|
+
|
|
4388
|
+
:param id: The ID of the search template to render. If no `source` is specified,
|
|
3662
4389
|
this or the `id` request body parameter is required.
|
|
3663
4390
|
:param file:
|
|
3664
4391
|
:param params: Key-value pairs used to replace Mustache variables in the template.
|
|
3665
4392
|
The key is the variable name. The value is the variable value.
|
|
3666
|
-
:param source: An inline search template.
|
|
3667
|
-
search API's request body. These parameters also support Mustache variables.
|
|
4393
|
+
:param source: An inline search template. It supports the same parameters as
|
|
4394
|
+
the search API's request body. These parameters also support Mustache variables.
|
|
3668
4395
|
If no `id` or `<templated-id>` is specified, this parameter is required.
|
|
3669
4396
|
"""
|
|
3670
4397
|
__path_parts: t.Dict[str, str]
|
|
@@ -3713,7 +4440,24 @@ class Elasticsearch(BaseClient):
|
|
|
3713
4440
|
def scripts_painless_execute(
|
|
3714
4441
|
self,
|
|
3715
4442
|
*,
|
|
3716
|
-
context: t.Optional[
|
|
4443
|
+
context: t.Optional[
|
|
4444
|
+
t.Union[
|
|
4445
|
+
str,
|
|
4446
|
+
t.Literal[
|
|
4447
|
+
"boolean_field",
|
|
4448
|
+
"composite_field",
|
|
4449
|
+
"date_field",
|
|
4450
|
+
"double_field",
|
|
4451
|
+
"filter",
|
|
4452
|
+
"geo_point_field",
|
|
4453
|
+
"ip_field",
|
|
4454
|
+
"keyword_field",
|
|
4455
|
+
"long_field",
|
|
4456
|
+
"painless_test",
|
|
4457
|
+
"score",
|
|
4458
|
+
],
|
|
4459
|
+
]
|
|
4460
|
+
] = None,
|
|
3717
4461
|
context_setup: t.Optional[t.Mapping[str, t.Any]] = None,
|
|
3718
4462
|
error_trace: t.Optional[bool] = None,
|
|
3719
4463
|
filter_path: t.Optional[t.Union[str, t.Sequence[str]]] = None,
|
|
@@ -3723,13 +4467,24 @@ class Elasticsearch(BaseClient):
|
|
|
3723
4467
|
body: t.Optional[t.Dict[str, t.Any]] = None,
|
|
3724
4468
|
) -> ObjectApiResponse[t.Any]:
|
|
3725
4469
|
"""
|
|
3726
|
-
|
|
4470
|
+
.. raw:: html
|
|
4471
|
+
|
|
4472
|
+
<p>Run a script.</p>
|
|
4473
|
+
<p>Runs a script and returns a result.
|
|
4474
|
+
Use this API to build and test scripts, such as when defining a script for a runtime field.
|
|
4475
|
+
This API requires very few dependencies and is especially useful if you don't have permissions to write documents on a cluster.</p>
|
|
4476
|
+
<p>The API uses several <em>contexts</em>, which control how scripts are run, what variables are available at runtime, and what the return type is.</p>
|
|
4477
|
+
<p>Each context requires a script, but additional parameters depend on the context you're using for that script.</p>
|
|
4478
|
+
|
|
3727
4479
|
|
|
3728
|
-
`<https://www.elastic.co/guide/en/elasticsearch/painless/8.
|
|
4480
|
+
`<https://www.elastic.co/guide/en/elasticsearch/painless/8.18/painless-execute-api.html>`_
|
|
3729
4481
|
|
|
3730
|
-
:param context: The context that the script should run in.
|
|
3731
|
-
|
|
3732
|
-
:param
|
|
4482
|
+
:param context: The context that the script should run in. NOTE: Result ordering
|
|
4483
|
+
in the field contexts is not guaranteed.
|
|
4484
|
+
:param context_setup: Additional parameters for the `context`. NOTE: This parameter
|
|
4485
|
+
is required for all contexts except `painless_test`, which is the default
|
|
4486
|
+
if no value is provided for `context`.
|
|
4487
|
+
:param script: The Painless script to run.
|
|
3733
4488
|
"""
|
|
3734
4489
|
__path_parts: t.Dict[str, str] = {}
|
|
3735
4490
|
__path = "/_scripts/painless/_execute"
|
|
@@ -3781,30 +4536,27 @@ class Elasticsearch(BaseClient):
|
|
|
3781
4536
|
body: t.Optional[t.Dict[str, t.Any]] = None,
|
|
3782
4537
|
) -> ObjectApiResponse[t.Any]:
|
|
3783
4538
|
"""
|
|
3784
|
-
|
|
3785
|
-
|
|
3786
|
-
|
|
3787
|
-
|
|
3788
|
-
|
|
3789
|
-
|
|
3790
|
-
|
|
3791
|
-
|
|
3792
|
-
|
|
3793
|
-
|
|
3794
|
-
|
|
3795
|
-
|
|
3796
|
-
|
|
3797
|
-
|
|
3798
|
-
|
|
3799
|
-
|
|
3800
|
-
|
|
3801
|
-
`<https://www.elastic.co/guide/en/elasticsearch/reference/8.17/search-request-body.html#request-body-search-scroll>`_
|
|
3802
|
-
|
|
3803
|
-
:param scroll_id: Scroll ID of the search.
|
|
4539
|
+
.. raw:: html
|
|
4540
|
+
|
|
4541
|
+
<p>Run a scrolling search.</p>
|
|
4542
|
+
<p>IMPORTANT: The scroll API is no longer recommend for deep pagination. If you need to preserve the index state while paging through more than 10,000 hits, use the <code>search_after</code> parameter with a point in time (PIT).</p>
|
|
4543
|
+
<p>The scroll API gets large sets of results from a single scrolling search request.
|
|
4544
|
+
To get the necessary scroll ID, submit a search API request that includes an argument for the <code>scroll</code> query parameter.
|
|
4545
|
+
The <code>scroll</code> parameter indicates how long Elasticsearch should retain the search context for the request.
|
|
4546
|
+
The search response returns a scroll ID in the <code>_scroll_id</code> response body parameter.
|
|
4547
|
+
You can then use the scroll ID with the scroll API to retrieve the next batch of results for the request.
|
|
4548
|
+
If the Elasticsearch security features are enabled, the access to the results of a specific scroll ID is restricted to the user or API key that submitted the search.</p>
|
|
4549
|
+
<p>You can also use the scroll API to specify a new scroll parameter that extends or shortens the retention period for the search context.</p>
|
|
4550
|
+
<p>IMPORTANT: Results from a scrolling search reflect the state of the index at the time of the initial search request. Subsequent indexing or document changes only affect later search and scroll requests.</p>
|
|
4551
|
+
|
|
4552
|
+
|
|
4553
|
+
`<https://www.elastic.co/guide/en/elasticsearch/reference/8.18/scroll-api.html>`_
|
|
4554
|
+
|
|
4555
|
+
:param scroll_id: The scroll ID of the search.
|
|
3804
4556
|
:param rest_total_hits_as_int: If true, the API response’s hit.total property
|
|
3805
4557
|
is returned as an integer. If false, the API response’s hit.total property
|
|
3806
4558
|
is returned as an object.
|
|
3807
|
-
:param scroll:
|
|
4559
|
+
:param scroll: The period to retain the search context for scrolling.
|
|
3808
4560
|
"""
|
|
3809
4561
|
if scroll_id is None and body is None:
|
|
3810
4562
|
raise ValueError("Empty value passed for parameter 'scroll_id'")
|
|
@@ -3986,15 +4738,29 @@ class Elasticsearch(BaseClient):
|
|
|
3986
4738
|
body: t.Optional[t.Dict[str, t.Any]] = None,
|
|
3987
4739
|
) -> ObjectApiResponse[t.Any]:
|
|
3988
4740
|
"""
|
|
3989
|
-
|
|
3990
|
-
|
|
3991
|
-
|
|
3992
|
-
|
|
3993
|
-
|
|
4741
|
+
.. raw:: html
|
|
4742
|
+
|
|
4743
|
+
<p>Run a search.</p>
|
|
4744
|
+
<p>Get search hits that match the query defined in the request.
|
|
4745
|
+
You can provide search queries using the <code>q</code> query string parameter or the request body.
|
|
4746
|
+
If both are specified, only the query parameter is used.</p>
|
|
4747
|
+
<p>If the Elasticsearch security features are enabled, you must have the read index privilege for the target data stream, index, or alias. For cross-cluster search, refer to the documentation about configuring CCS privileges.
|
|
4748
|
+
To search a point in time (PIT) for an alias, you must have the <code>read</code> index privilege for the alias's data streams or indices.</p>
|
|
4749
|
+
<p><strong>Search slicing</strong></p>
|
|
4750
|
+
<p>When paging through a large number of documents, it can be helpful to split the search into multiple slices to consume them independently with the <code>slice</code> and <code>pit</code> properties.
|
|
4751
|
+
By default the splitting is done first on the shards, then locally on each shard.
|
|
4752
|
+
The local splitting partitions the shard into contiguous ranges based on Lucene document IDs.</p>
|
|
4753
|
+
<p>For instance if the number of shards is equal to 2 and you request 4 slices, the slices 0 and 2 are assigned to the first shard and the slices 1 and 3 are assigned to the second shard.</p>
|
|
4754
|
+
<p>IMPORTANT: The same point-in-time ID should be used for all slices.
|
|
4755
|
+
If different PIT IDs are used, slices can overlap and miss documents.
|
|
4756
|
+
This situation can occur because the splitting criterion is based on Lucene document IDs, which are not stable across changes to the index.</p>
|
|
4757
|
+
|
|
4758
|
+
|
|
4759
|
+
`<https://www.elastic.co/guide/en/elasticsearch/reference/8.18/search-search.html>`_
|
|
3994
4760
|
|
|
3995
|
-
:param index:
|
|
3996
|
-
|
|
3997
|
-
parameter or use `*` or `_all`.
|
|
4761
|
+
:param index: A comma-separated list of data streams, indices, and aliases to
|
|
4762
|
+
search. It supports wildcards (`*`). To search all data streams and indices,
|
|
4763
|
+
omit this parameter or use `*` or `_all`.
|
|
3998
4764
|
:param aggregations: Defines the aggregations that are run as part of the search
|
|
3999
4765
|
request.
|
|
4000
4766
|
:param aggs: Defines the aggregations that are run as part of the search request.
|
|
@@ -4003,45 +4769,46 @@ class Elasticsearch(BaseClient):
|
|
|
4003
4769
|
This behavior applies even if the request targets other open indices. For
|
|
4004
4770
|
example, a request targeting `foo*,bar*` returns an error if an index starts
|
|
4005
4771
|
with `foo` but no index starts with `bar`.
|
|
4006
|
-
:param allow_partial_search_results: If true
|
|
4007
|
-
|
|
4008
|
-
with no partial results.
|
|
4009
|
-
|
|
4010
|
-
|
|
4011
|
-
|
|
4012
|
-
|
|
4772
|
+
:param allow_partial_search_results: If `true` and there are shard request timeouts
|
|
4773
|
+
or shard failures, the request returns partial results. If `false`, it returns
|
|
4774
|
+
an error with no partial results. To override the default behavior, you can
|
|
4775
|
+
set the `search.default_allow_partial_results` cluster setting to `false`.
|
|
4776
|
+
:param analyze_wildcard: If `true`, wildcard and prefix queries are analyzed.
|
|
4777
|
+
This parameter can be used only when the `q` query string parameter is specified.
|
|
4778
|
+
:param analyzer: The analyzer to use for the query string. This parameter can
|
|
4779
|
+
be used only when the `q` query string parameter is specified.
|
|
4013
4780
|
:param batched_reduce_size: The number of shard results that should be reduced
|
|
4014
|
-
at once on the coordinating node.
|
|
4015
|
-
|
|
4016
|
-
|
|
4017
|
-
:param ccs_minimize_roundtrips: If true
|
|
4018
|
-
node and the remote clusters are minimized when
|
|
4781
|
+
at once on the coordinating node. If the potential number of shards in the
|
|
4782
|
+
request can be large, this value should be used as a protection mechanism
|
|
4783
|
+
to reduce the memory overhead per search request.
|
|
4784
|
+
:param ccs_minimize_roundtrips: If `true`, network round-trips between the coordinating
|
|
4785
|
+
node and the remote clusters are minimized when running cross-cluster search
|
|
4019
4786
|
(CCS) requests.
|
|
4020
4787
|
:param collapse: Collapses search results the values of the specified field.
|
|
4021
|
-
:param default_operator: The default operator for query string query: AND
|
|
4022
|
-
OR
|
|
4023
|
-
specified.
|
|
4024
|
-
:param df: Field to use as default where no field prefix is given in the query
|
|
4025
|
-
string. This parameter can only be used when the q query string parameter
|
|
4788
|
+
:param default_operator: The default operator for the query string query: `AND`
|
|
4789
|
+
or `OR`. This parameter can be used only when the `q` query string parameter
|
|
4026
4790
|
is specified.
|
|
4027
|
-
:param
|
|
4028
|
-
|
|
4029
|
-
|
|
4030
|
-
:param
|
|
4031
|
-
|
|
4032
|
-
|
|
4033
|
-
|
|
4034
|
-
|
|
4035
|
-
|
|
4791
|
+
:param df: The field to use as a default when no field prefix is given in the
|
|
4792
|
+
query string. This parameter can be used only when the `q` query string parameter
|
|
4793
|
+
is specified.
|
|
4794
|
+
:param docvalue_fields: An array of wildcard (`*`) field patterns. The request
|
|
4795
|
+
returns doc values for field names matching these patterns in the `hits.fields`
|
|
4796
|
+
property of the response.
|
|
4797
|
+
:param expand_wildcards: The type of index that wildcard patterns can match.
|
|
4798
|
+
If the request can target data streams, this argument determines whether
|
|
4799
|
+
wildcard expressions match hidden data streams. It supports comma-separated
|
|
4800
|
+
values such as `open,hidden`.
|
|
4801
|
+
:param explain: If `true`, the request returns detailed information about score
|
|
4802
|
+
computation as part of a hit.
|
|
4036
4803
|
:param ext: Configuration of search extensions defined by Elasticsearch plugins.
|
|
4037
|
-
:param fields:
|
|
4038
|
-
field names matching these patterns in the `hits.fields` property
|
|
4039
|
-
response.
|
|
4804
|
+
:param fields: An array of wildcard (`*`) field patterns. The request returns
|
|
4805
|
+
values for field names matching these patterns in the `hits.fields` property
|
|
4806
|
+
of the response.
|
|
4040
4807
|
:param force_synthetic_source: Should this request force synthetic _source? Use
|
|
4041
4808
|
this to test if the mapping supports synthetic _source and to get a sense
|
|
4042
4809
|
of the worst case performance. Fetches with this enabled will be slower the
|
|
4043
4810
|
enabling synthetic source natively in the index.
|
|
4044
|
-
:param from_:
|
|
4811
|
+
:param from_: The starting document offset, which must be non-negative. By default,
|
|
4045
4812
|
you cannot page through more than 10,000 hits using the `from` and `size`
|
|
4046
4813
|
parameters. To page through more hits, use the `search_after` parameter.
|
|
4047
4814
|
:param highlight: Specifies the highlighter to use for retrieving highlighted
|
|
@@ -4050,95 +4817,101 @@ class Elasticsearch(BaseClient):
|
|
|
4050
4817
|
be ignored when frozen.
|
|
4051
4818
|
:param ignore_unavailable: If `false`, the request returns an error if it targets
|
|
4052
4819
|
a missing or closed index.
|
|
4053
|
-
:param include_named_queries_score:
|
|
4054
|
-
|
|
4055
|
-
|
|
4056
|
-
|
|
4057
|
-
|
|
4058
|
-
|
|
4059
|
-
|
|
4060
|
-
|
|
4061
|
-
|
|
4820
|
+
:param include_named_queries_score: If `true`, the response includes the score
|
|
4821
|
+
contribution from any named queries. This functionality reruns each named
|
|
4822
|
+
query on every hit in a search response. Typically, this adds a small overhead
|
|
4823
|
+
to a request. However, using computationally expensive named queries on a
|
|
4824
|
+
large number of hits may add significant overhead.
|
|
4825
|
+
:param indices_boost: Boost the `_score` of documents from specified indices.
|
|
4826
|
+
The boost value is the factor by which scores are multiplied. A boost value
|
|
4827
|
+
greater than `1.0` increases the score. A boost value between `0` and `1.0`
|
|
4828
|
+
decreases the score.
|
|
4829
|
+
:param knn: The approximate kNN search to run.
|
|
4062
4830
|
:param lenient: If `true`, format-based query failures (such as providing text
|
|
4063
4831
|
to a numeric field) in the query string will be ignored. This parameter can
|
|
4064
|
-
|
|
4065
|
-
:param max_concurrent_shard_requests:
|
|
4066
|
-
|
|
4067
|
-
|
|
4068
|
-
|
|
4832
|
+
be used only when the `q` query string parameter is specified.
|
|
4833
|
+
:param max_concurrent_shard_requests: The number of concurrent shard requests
|
|
4834
|
+
per node that the search runs concurrently. This value should be used to
|
|
4835
|
+
limit the impact of the search on the cluster in order to limit the number
|
|
4836
|
+
of concurrent shard requests.
|
|
4069
4837
|
:param min_compatible_shard_node: The minimum version of the node that can handle
|
|
4070
4838
|
the request Any handling node with a lower version will fail the request.
|
|
4071
|
-
:param min_score:
|
|
4072
|
-
`_score` are not included in the search results.
|
|
4073
|
-
:param pit:
|
|
4839
|
+
:param min_score: The minimum `_score` for matching documents. Documents with
|
|
4840
|
+
a lower `_score` are not included in the search results.
|
|
4841
|
+
:param pit: Limit the search to a point in time (PIT). If you provide a PIT,
|
|
4074
4842
|
you cannot specify an `<index>` in the request path.
|
|
4075
4843
|
:param post_filter: Use the `post_filter` parameter to filter search results.
|
|
4076
4844
|
The search hits are filtered after the aggregations are calculated. A post
|
|
4077
4845
|
filter has no impact on the aggregation results.
|
|
4078
|
-
:param pre_filter_shard_size:
|
|
4079
|
-
|
|
4080
|
-
|
|
4081
|
-
|
|
4082
|
-
|
|
4083
|
-
|
|
4084
|
-
|
|
4085
|
-
is met:
|
|
4086
|
-
or more read-only index
|
|
4846
|
+
:param pre_filter_shard_size: A threshold that enforces a pre-filter roundtrip
|
|
4847
|
+
to prefilter search shards based on query rewriting if the number of shards
|
|
4848
|
+
the search request expands to exceeds the threshold. This filter roundtrip
|
|
4849
|
+
can limit the number of shards significantly if for instance a shard can
|
|
4850
|
+
not match any documents based on its rewrite method (if date filters are
|
|
4851
|
+
mandatory to match but the shard bounds and the query are disjoint). When
|
|
4852
|
+
unspecified, the pre-filter phase is executed if any of these conditions
|
|
4853
|
+
is met: * The request targets more than 128 shards. * The request targets
|
|
4854
|
+
one or more read-only index. * The primary sort of the query targets an indexed
|
|
4087
4855
|
field.
|
|
4088
|
-
:param preference:
|
|
4856
|
+
:param preference: The nodes and shards used for the search. By default, Elasticsearch
|
|
4089
4857
|
selects from eligible nodes and shards using adaptive replica selection,
|
|
4090
|
-
accounting for allocation awareness. Valid values are: `_only_local` to
|
|
4091
|
-
the search only on shards on the local node; `_local` to, if possible,
|
|
4092
|
-
the search on shards on the local node, or if not, select shards using
|
|
4093
|
-
default method; `_only_nodes:<node-id>,<node-id>` to run the search
|
|
4094
|
-
the specified nodes IDs, where, if suitable shards exist on more
|
|
4095
|
-
selected node, use shards on those nodes using the default method,
|
|
4096
|
-
none of the specified nodes are available, select shards from any available
|
|
4097
|
-
node using the default method; `_prefer_nodes:<node-id>,<node-id>` to if
|
|
4858
|
+
accounting for allocation awareness. Valid values are: * `_only_local` to
|
|
4859
|
+
run the search only on shards on the local node; * `_local` to, if possible,
|
|
4860
|
+
run the search on shards on the local node, or if not, select shards using
|
|
4861
|
+
the default method; * `_only_nodes:<node-id>,<node-id>` to run the search
|
|
4862
|
+
on only the specified nodes IDs, where, if suitable shards exist on more
|
|
4863
|
+
than one selected node, use shards on those nodes using the default method,
|
|
4864
|
+
or if none of the specified nodes are available, select shards from any available
|
|
4865
|
+
node using the default method; * `_prefer_nodes:<node-id>,<node-id>` to if
|
|
4098
4866
|
possible, run the search on the specified nodes IDs, or if not, select shards
|
|
4099
|
-
using the default method; `_shards:<shard>,<shard>` to run the search only
|
|
4100
|
-
on the specified shards; `<custom-string>` (any string that does not start
|
|
4867
|
+
using the default method; * `_shards:<shard>,<shard>` to run the search only
|
|
4868
|
+
on the specified shards; * `<custom-string>` (any string that does not start
|
|
4101
4869
|
with `_`) to route searches with the same `<custom-string>` to the same shards
|
|
4102
4870
|
in the same order.
|
|
4103
4871
|
:param profile: Set to `true` to return detailed timing information about the
|
|
4104
4872
|
execution of individual components in a search request. NOTE: This is a debugging
|
|
4105
4873
|
tool and adds significant overhead to search execution.
|
|
4106
|
-
:param q:
|
|
4107
|
-
|
|
4108
|
-
|
|
4109
|
-
|
|
4110
|
-
|
|
4874
|
+
:param q: A query in the Lucene query string syntax. Query parameter searches
|
|
4875
|
+
do not support the full Elasticsearch Query DSL but are handy for testing.
|
|
4876
|
+
IMPORTANT: This parameter overrides the query parameter in the request body.
|
|
4877
|
+
If both parameters are specified, documents matching the query request body
|
|
4878
|
+
parameter are not returned.
|
|
4879
|
+
:param query: The search definition using the Query DSL.
|
|
4880
|
+
:param rank: The Reciprocal Rank Fusion (RRF) to use.
|
|
4111
4881
|
:param request_cache: If `true`, the caching of search results is enabled for
|
|
4112
|
-
requests where `size` is `0`.
|
|
4882
|
+
requests where `size` is `0`. It defaults to index level settings.
|
|
4113
4883
|
:param rescore: Can be used to improve precision by reordering just the top (for
|
|
4114
4884
|
example 100 - 500) documents returned by the `query` and `post_filter` phases.
|
|
4115
4885
|
:param rest_total_hits_as_int: Indicates whether `hits.total` should be rendered
|
|
4116
4886
|
as an integer or an object in the rest search response.
|
|
4117
4887
|
:param retriever: A retriever is a specification to describe top documents returned
|
|
4118
4888
|
from a search. A retriever replaces other elements of the search API that
|
|
4119
|
-
also return top documents such as query and knn
|
|
4120
|
-
:param routing:
|
|
4121
|
-
|
|
4122
|
-
|
|
4889
|
+
also return top documents such as `query` and `knn`.
|
|
4890
|
+
:param routing: A custom value that is used to route operations to a specific
|
|
4891
|
+
shard.
|
|
4892
|
+
:param runtime_mappings: One or more runtime fields in the search request. These
|
|
4893
|
+
fields take precedence over mapped fields with the same name.
|
|
4123
4894
|
:param script_fields: Retrieve a script evaluation (based on different fields)
|
|
4124
4895
|
for each hit.
|
|
4125
|
-
:param scroll:
|
|
4126
|
-
|
|
4127
|
-
|
|
4896
|
+
:param scroll: The period to retain the search context for scrolling. By default,
|
|
4897
|
+
this value cannot exceed `1d` (24 hours). You can change this limit by using
|
|
4898
|
+
the `search.max_keep_alive` cluster-level setting.
|
|
4128
4899
|
:param search_after: Used to retrieve the next page of hits using a set of sort
|
|
4129
4900
|
values from the previous page.
|
|
4130
|
-
:param search_type:
|
|
4131
|
-
scoring.
|
|
4132
|
-
:param seq_no_primary_term: If `true`, returns sequence number and
|
|
4133
|
-
of the last modification of each hit.
|
|
4134
|
-
:param size: The number of hits to return. By default,
|
|
4135
|
-
more than 10,000 hits using the `from` and `size`
|
|
4136
|
-
more hits, use the `search_after`
|
|
4137
|
-
:param slice:
|
|
4138
|
-
|
|
4901
|
+
:param search_type: Indicates how distributed term frequencies are calculated
|
|
4902
|
+
for relevance scoring.
|
|
4903
|
+
:param seq_no_primary_term: If `true`, the request returns sequence number and
|
|
4904
|
+
primary term of the last modification of each hit.
|
|
4905
|
+
:param size: The number of hits to return, which must not be negative. By default,
|
|
4906
|
+
you cannot page through more than 10,000 hits using the `from` and `size`
|
|
4907
|
+
parameters. To page through more hits, use the `search_after` property.
|
|
4908
|
+
:param slice: Split a scrolled search into multiple slices that can be consumed
|
|
4909
|
+
independently.
|
|
4139
4910
|
:param sort: A comma-separated list of <field>:<direction> pairs.
|
|
4140
|
-
:param source:
|
|
4141
|
-
|
|
4911
|
+
:param source: The source fields that are returned for matching documents. These
|
|
4912
|
+
fields are returned in the `hits._source` property of the search response.
|
|
4913
|
+
If the `stored_fields` property is specified, the `_source` property defaults
|
|
4914
|
+
to `false`. Otherwise, it defaults to `true`.
|
|
4142
4915
|
:param source_excludes: A comma-separated list of source fields to exclude from
|
|
4143
4916
|
the response. You can also use this parameter to exclude fields from the
|
|
4144
4917
|
subset specified in `_source_includes` query parameter. If the `_source`
|
|
@@ -4148,45 +4921,46 @@ class Elasticsearch(BaseClient):
|
|
|
4148
4921
|
returned. You can exclude fields from this subset using the `_source_excludes`
|
|
4149
4922
|
query parameter. If the `_source` parameter is `false`, this parameter is
|
|
4150
4923
|
ignored.
|
|
4151
|
-
:param stats:
|
|
4924
|
+
:param stats: The stats groups to associate with the search. Each group maintains
|
|
4152
4925
|
a statistics aggregation for its associated searches. You can retrieve these
|
|
4153
4926
|
stats using the indices stats API.
|
|
4154
|
-
:param stored_fields:
|
|
4155
|
-
fields are specified, no stored fields are included in the
|
|
4156
|
-
field is specified, the `_source`
|
|
4157
|
-
pass `_source: true` to return both source fields and stored
|
|
4158
|
-
search response.
|
|
4927
|
+
:param stored_fields: A comma-separated list of stored fields to return as part
|
|
4928
|
+
of a hit. If no fields are specified, no stored fields are included in the
|
|
4929
|
+
response. If this field is specified, the `_source` property defaults to
|
|
4930
|
+
`false`. You can pass `_source: true` to return both source fields and stored
|
|
4931
|
+
fields in the search response.
|
|
4159
4932
|
:param suggest: Defines a suggester that provides similar looking terms based
|
|
4160
4933
|
on a provided text.
|
|
4161
|
-
:param suggest_field:
|
|
4162
|
-
:param suggest_mode:
|
|
4163
|
-
|
|
4164
|
-
:param suggest_size:
|
|
4165
|
-
be used when the `suggest_field` and `suggest_text` query string parameters
|
|
4934
|
+
:param suggest_field: The field to use for suggestions.
|
|
4935
|
+
:param suggest_mode: The suggest mode. This parameter can be used only when the
|
|
4936
|
+
`suggest_field` and `suggest_text` query string parameters are specified.
|
|
4937
|
+
:param suggest_size: The number of suggestions to return. This parameter can
|
|
4938
|
+
be used only when the `suggest_field` and `suggest_text` query string parameters
|
|
4166
4939
|
are specified.
|
|
4167
4940
|
:param suggest_text: The source text for which the suggestions should be returned.
|
|
4168
|
-
This parameter can
|
|
4941
|
+
This parameter can be used only when the `suggest_field` and `suggest_text`
|
|
4169
4942
|
query string parameters are specified.
|
|
4170
|
-
:param terminate_after:
|
|
4943
|
+
:param terminate_after: The maximum number of documents to collect for each shard.
|
|
4171
4944
|
If a query reaches this limit, Elasticsearch terminates the query early.
|
|
4172
|
-
Elasticsearch collects documents before sorting. Use with caution.
|
|
4173
|
-
applies this
|
|
4174
|
-
let Elasticsearch perform early termination automatically. Avoid
|
|
4175
|
-
this
|
|
4176
|
-
across multiple data tiers. If set to `0` (default), the query does
|
|
4177
|
-
early.
|
|
4178
|
-
:param timeout:
|
|
4179
|
-
|
|
4180
|
-
|
|
4181
|
-
:param track_scores: If true
|
|
4182
|
-
scores are not used for sorting.
|
|
4945
|
+
Elasticsearch collects documents before sorting. IMPORTANT: Use with caution.
|
|
4946
|
+
Elasticsearch applies this property to each shard handling the request. When
|
|
4947
|
+
possible, let Elasticsearch perform early termination automatically. Avoid
|
|
4948
|
+
specifying this property for requests that target data streams with backing
|
|
4949
|
+
indices across multiple data tiers. If set to `0` (default), the query does
|
|
4950
|
+
not terminate early.
|
|
4951
|
+
:param timeout: The period of time to wait for a response from each shard. If
|
|
4952
|
+
no response is received before the timeout expires, the request fails and
|
|
4953
|
+
returns an error. Defaults to no timeout.
|
|
4954
|
+
:param track_scores: If `true`, calculate and return document scores, even if
|
|
4955
|
+
the scores are not used for sorting.
|
|
4183
4956
|
:param track_total_hits: Number of hits matching the query to count accurately.
|
|
4184
4957
|
If `true`, the exact number of hits is returned at the cost of some performance.
|
|
4185
4958
|
If `false`, the response does not include the total number of hits matching
|
|
4186
4959
|
the query.
|
|
4187
4960
|
:param typed_keys: If `true`, aggregation and suggester names are be prefixed
|
|
4188
4961
|
by their respective types in the response.
|
|
4189
|
-
:param version: If true
|
|
4962
|
+
:param version: If `true`, the request returns the document version as part of
|
|
4963
|
+
a hit.
|
|
4190
4964
|
"""
|
|
4191
4965
|
__path_parts: t.Dict[str, str]
|
|
4192
4966
|
if index not in SKIP_IN_PATH:
|
|
@@ -4418,52 +5192,376 @@ class Elasticsearch(BaseClient):
|
|
|
4418
5192
|
body: t.Optional[t.Dict[str, t.Any]] = None,
|
|
4419
5193
|
) -> BinaryApiResponse:
|
|
4420
5194
|
"""
|
|
4421
|
-
|
|
4422
|
-
|
|
4423
|
-
|
|
5195
|
+
.. raw:: html
|
|
5196
|
+
|
|
5197
|
+
<p>Search a vector tile.</p>
|
|
5198
|
+
<p>Search a vector tile for geospatial values.
|
|
5199
|
+
Before using this API, you should be familiar with the Mapbox vector tile specification.
|
|
5200
|
+
The API returns results as a binary mapbox vector tile.</p>
|
|
5201
|
+
<p>Internally, Elasticsearch translates a vector tile search API request into a search containing:</p>
|
|
5202
|
+
<ul>
|
|
5203
|
+
<li>A <code>geo_bounding_box</code> query on the <code><field></code>. The query uses the <code><zoom>/<x>/<y></code> tile as a bounding box.</li>
|
|
5204
|
+
<li>A <code>geotile_grid</code> or <code>geohex_grid</code> aggregation on the <code><field></code>. The <code>grid_agg</code> parameter determines the aggregation type. The aggregation uses the <code><zoom>/<x>/<y></code> tile as a bounding box.</li>
|
|
5205
|
+
<li>Optionally, a <code>geo_bounds</code> aggregation on the <code><field></code>. The search only includes this aggregation if the <code>exact_bounds</code> parameter is <code>true</code>.</li>
|
|
5206
|
+
<li>If the optional parameter <code>with_labels</code> is <code>true</code>, the internal search will include a dynamic runtime field that calls the <code>getLabelPosition</code> function of the geometry doc value. This enables the generation of new point features containing suggested geometry labels, so that, for example, multi-polygons will have only one label.</li>
|
|
5207
|
+
</ul>
|
|
5208
|
+
<p>For example, Elasticsearch may translate a vector tile search API request with a <code>grid_agg</code> argument of <code>geotile</code> and an <code>exact_bounds</code> argument of <code>true</code> into the following search</p>
|
|
5209
|
+
<pre><code>GET my-index/_search
|
|
5210
|
+
{
|
|
5211
|
+
"size": 10000,
|
|
5212
|
+
"query": {
|
|
5213
|
+
"geo_bounding_box": {
|
|
5214
|
+
"my-geo-field": {
|
|
5215
|
+
"top_left": {
|
|
5216
|
+
"lat": -40.979898069620134,
|
|
5217
|
+
"lon": -45
|
|
5218
|
+
},
|
|
5219
|
+
"bottom_right": {
|
|
5220
|
+
"lat": -66.51326044311186,
|
|
5221
|
+
"lon": 0
|
|
5222
|
+
}
|
|
5223
|
+
}
|
|
5224
|
+
}
|
|
5225
|
+
},
|
|
5226
|
+
"aggregations": {
|
|
5227
|
+
"grid": {
|
|
5228
|
+
"geotile_grid": {
|
|
5229
|
+
"field": "my-geo-field",
|
|
5230
|
+
"precision": 11,
|
|
5231
|
+
"size": 65536,
|
|
5232
|
+
"bounds": {
|
|
5233
|
+
"top_left": {
|
|
5234
|
+
"lat": -40.979898069620134,
|
|
5235
|
+
"lon": -45
|
|
5236
|
+
},
|
|
5237
|
+
"bottom_right": {
|
|
5238
|
+
"lat": -66.51326044311186,
|
|
5239
|
+
"lon": 0
|
|
5240
|
+
}
|
|
5241
|
+
}
|
|
5242
|
+
}
|
|
5243
|
+
},
|
|
5244
|
+
"bounds": {
|
|
5245
|
+
"geo_bounds": {
|
|
5246
|
+
"field": "my-geo-field",
|
|
5247
|
+
"wrap_longitude": false
|
|
5248
|
+
}
|
|
5249
|
+
}
|
|
5250
|
+
}
|
|
5251
|
+
}
|
|
5252
|
+
</code></pre>
|
|
5253
|
+
<p>The API returns results as a binary Mapbox vector tile.
|
|
5254
|
+
Mapbox vector tiles are encoded as Google Protobufs (PBF). By default, the tile contains three layers:</p>
|
|
5255
|
+
<ul>
|
|
5256
|
+
<li>A <code>hits</code> layer containing a feature for each <code><field></code> value matching the <code>geo_bounding_box</code> query.</li>
|
|
5257
|
+
<li>An <code>aggs</code> layer containing a feature for each cell of the <code>geotile_grid</code> or <code>geohex_grid</code>. The layer only contains features for cells with matching data.</li>
|
|
5258
|
+
<li>A meta layer containing:
|
|
5259
|
+
<ul>
|
|
5260
|
+
<li>A feature containing a bounding box. By default, this is the bounding box of the tile.</li>
|
|
5261
|
+
<li>Value ranges for any sub-aggregations on the <code>geotile_grid</code> or <code>geohex_grid</code>.</li>
|
|
5262
|
+
<li>Metadata for the search.</li>
|
|
5263
|
+
</ul>
|
|
5264
|
+
</li>
|
|
5265
|
+
</ul>
|
|
5266
|
+
<p>The API only returns features that can display at its zoom level.
|
|
5267
|
+
For example, if a polygon feature has no area at its zoom level, the API omits it.
|
|
5268
|
+
The API returns errors as UTF-8 encoded JSON.</p>
|
|
5269
|
+
<p>IMPORTANT: You can specify several options for this API as either a query parameter or request body parameter.
|
|
5270
|
+
If you specify both parameters, the query parameter takes precedence.</p>
|
|
5271
|
+
<p><strong>Grid precision for geotile</strong></p>
|
|
5272
|
+
<p>For a <code>grid_agg</code> of <code>geotile</code>, you can use cells in the <code>aggs</code> layer as tiles for lower zoom levels.
|
|
5273
|
+
<code>grid_precision</code> represents the additional zoom levels available through these cells. The final precision is computed by as follows: <code><zoom> + grid_precision</code>.
|
|
5274
|
+
For example, if <code><zoom></code> is 7 and <code>grid_precision</code> is 8, then the <code>geotile_grid</code> aggregation will use a precision of 15.
|
|
5275
|
+
The maximum final precision is 29.
|
|
5276
|
+
The <code>grid_precision</code> also determines the number of cells for the grid as follows: <code>(2^grid_precision) x (2^grid_precision)</code>.
|
|
5277
|
+
For example, a value of 8 divides the tile into a grid of 256 x 256 cells.
|
|
5278
|
+
The <code>aggs</code> layer only contains features for cells with matching data.</p>
|
|
5279
|
+
<p><strong>Grid precision for geohex</strong></p>
|
|
5280
|
+
<p>For a <code>grid_agg</code> of <code>geohex</code>, Elasticsearch uses <code><zoom></code> and <code>grid_precision</code> to calculate a final precision as follows: <code><zoom> + grid_precision</code>.</p>
|
|
5281
|
+
<p>This precision determines the H3 resolution of the hexagonal cells produced by the <code>geohex</code> aggregation.
|
|
5282
|
+
The following table maps the H3 resolution for each precision.
|
|
5283
|
+
For example, if <code><zoom></code> is 3 and <code>grid_precision</code> is 3, the precision is 6.
|
|
5284
|
+
At a precision of 6, hexagonal cells have an H3 resolution of 2.
|
|
5285
|
+
If <code><zoom></code> is 3 and <code>grid_precision</code> is 4, the precision is 7.
|
|
5286
|
+
At a precision of 7, hexagonal cells have an H3 resolution of 3.</p>
|
|
5287
|
+
<table>
|
|
5288
|
+
<thead>
|
|
5289
|
+
<tr>
|
|
5290
|
+
<th>Precision</th>
|
|
5291
|
+
<th>Unique tile bins</th>
|
|
5292
|
+
<th>H3 resolution</th>
|
|
5293
|
+
<th>Unique hex bins</th>
|
|
5294
|
+
<th>Ratio</th>
|
|
5295
|
+
</tr>
|
|
5296
|
+
</thead>
|
|
5297
|
+
<tbody>
|
|
5298
|
+
<tr>
|
|
5299
|
+
<td>1</td>
|
|
5300
|
+
<td>4</td>
|
|
5301
|
+
<td>0</td>
|
|
5302
|
+
<td>122</td>
|
|
5303
|
+
<td>30.5</td>
|
|
5304
|
+
</tr>
|
|
5305
|
+
<tr>
|
|
5306
|
+
<td>2</td>
|
|
5307
|
+
<td>16</td>
|
|
5308
|
+
<td>0</td>
|
|
5309
|
+
<td>122</td>
|
|
5310
|
+
<td>7.625</td>
|
|
5311
|
+
</tr>
|
|
5312
|
+
<tr>
|
|
5313
|
+
<td>3</td>
|
|
5314
|
+
<td>64</td>
|
|
5315
|
+
<td>1</td>
|
|
5316
|
+
<td>842</td>
|
|
5317
|
+
<td>13.15625</td>
|
|
5318
|
+
</tr>
|
|
5319
|
+
<tr>
|
|
5320
|
+
<td>4</td>
|
|
5321
|
+
<td>256</td>
|
|
5322
|
+
<td>1</td>
|
|
5323
|
+
<td>842</td>
|
|
5324
|
+
<td>3.2890625</td>
|
|
5325
|
+
</tr>
|
|
5326
|
+
<tr>
|
|
5327
|
+
<td>5</td>
|
|
5328
|
+
<td>1024</td>
|
|
5329
|
+
<td>2</td>
|
|
5330
|
+
<td>5882</td>
|
|
5331
|
+
<td>5.744140625</td>
|
|
5332
|
+
</tr>
|
|
5333
|
+
<tr>
|
|
5334
|
+
<td>6</td>
|
|
5335
|
+
<td>4096</td>
|
|
5336
|
+
<td>2</td>
|
|
5337
|
+
<td>5882</td>
|
|
5338
|
+
<td>1.436035156</td>
|
|
5339
|
+
</tr>
|
|
5340
|
+
<tr>
|
|
5341
|
+
<td>7</td>
|
|
5342
|
+
<td>16384</td>
|
|
5343
|
+
<td>3</td>
|
|
5344
|
+
<td>41162</td>
|
|
5345
|
+
<td>2.512329102</td>
|
|
5346
|
+
</tr>
|
|
5347
|
+
<tr>
|
|
5348
|
+
<td>8</td>
|
|
5349
|
+
<td>65536</td>
|
|
5350
|
+
<td>3</td>
|
|
5351
|
+
<td>41162</td>
|
|
5352
|
+
<td>0.6280822754</td>
|
|
5353
|
+
</tr>
|
|
5354
|
+
<tr>
|
|
5355
|
+
<td>9</td>
|
|
5356
|
+
<td>262144</td>
|
|
5357
|
+
<td>4</td>
|
|
5358
|
+
<td>288122</td>
|
|
5359
|
+
<td>1.099098206</td>
|
|
5360
|
+
</tr>
|
|
5361
|
+
<tr>
|
|
5362
|
+
<td>10</td>
|
|
5363
|
+
<td>1048576</td>
|
|
5364
|
+
<td>4</td>
|
|
5365
|
+
<td>288122</td>
|
|
5366
|
+
<td>0.2747745514</td>
|
|
5367
|
+
</tr>
|
|
5368
|
+
<tr>
|
|
5369
|
+
<td>11</td>
|
|
5370
|
+
<td>4194304</td>
|
|
5371
|
+
<td>5</td>
|
|
5372
|
+
<td>2016842</td>
|
|
5373
|
+
<td>0.4808526039</td>
|
|
5374
|
+
</tr>
|
|
5375
|
+
<tr>
|
|
5376
|
+
<td>12</td>
|
|
5377
|
+
<td>16777216</td>
|
|
5378
|
+
<td>6</td>
|
|
5379
|
+
<td>14117882</td>
|
|
5380
|
+
<td>0.8414913416</td>
|
|
5381
|
+
</tr>
|
|
5382
|
+
<tr>
|
|
5383
|
+
<td>13</td>
|
|
5384
|
+
<td>67108864</td>
|
|
5385
|
+
<td>6</td>
|
|
5386
|
+
<td>14117882</td>
|
|
5387
|
+
<td>0.2103728354</td>
|
|
5388
|
+
</tr>
|
|
5389
|
+
<tr>
|
|
5390
|
+
<td>14</td>
|
|
5391
|
+
<td>268435456</td>
|
|
5392
|
+
<td>7</td>
|
|
5393
|
+
<td>98825162</td>
|
|
5394
|
+
<td>0.3681524172</td>
|
|
5395
|
+
</tr>
|
|
5396
|
+
<tr>
|
|
5397
|
+
<td>15</td>
|
|
5398
|
+
<td>1073741824</td>
|
|
5399
|
+
<td>8</td>
|
|
5400
|
+
<td>691776122</td>
|
|
5401
|
+
<td>0.644266719</td>
|
|
5402
|
+
</tr>
|
|
5403
|
+
<tr>
|
|
5404
|
+
<td>16</td>
|
|
5405
|
+
<td>4294967296</td>
|
|
5406
|
+
<td>8</td>
|
|
5407
|
+
<td>691776122</td>
|
|
5408
|
+
<td>0.1610666797</td>
|
|
5409
|
+
</tr>
|
|
5410
|
+
<tr>
|
|
5411
|
+
<td>17</td>
|
|
5412
|
+
<td>17179869184</td>
|
|
5413
|
+
<td>9</td>
|
|
5414
|
+
<td>4842432842</td>
|
|
5415
|
+
<td>0.2818666889</td>
|
|
5416
|
+
</tr>
|
|
5417
|
+
<tr>
|
|
5418
|
+
<td>18</td>
|
|
5419
|
+
<td>68719476736</td>
|
|
5420
|
+
<td>10</td>
|
|
5421
|
+
<td>33897029882</td>
|
|
5422
|
+
<td>0.4932667053</td>
|
|
5423
|
+
</tr>
|
|
5424
|
+
<tr>
|
|
5425
|
+
<td>19</td>
|
|
5426
|
+
<td>274877906944</td>
|
|
5427
|
+
<td>11</td>
|
|
5428
|
+
<td>237279209162</td>
|
|
5429
|
+
<td>0.8632167343</td>
|
|
5430
|
+
</tr>
|
|
5431
|
+
<tr>
|
|
5432
|
+
<td>20</td>
|
|
5433
|
+
<td>1099511627776</td>
|
|
5434
|
+
<td>11</td>
|
|
5435
|
+
<td>237279209162</td>
|
|
5436
|
+
<td>0.2158041836</td>
|
|
5437
|
+
</tr>
|
|
5438
|
+
<tr>
|
|
5439
|
+
<td>21</td>
|
|
5440
|
+
<td>4398046511104</td>
|
|
5441
|
+
<td>12</td>
|
|
5442
|
+
<td>1660954464122</td>
|
|
5443
|
+
<td>0.3776573213</td>
|
|
5444
|
+
</tr>
|
|
5445
|
+
<tr>
|
|
5446
|
+
<td>22</td>
|
|
5447
|
+
<td>17592186044416</td>
|
|
5448
|
+
<td>13</td>
|
|
5449
|
+
<td>11626681248842</td>
|
|
5450
|
+
<td>0.6609003122</td>
|
|
5451
|
+
</tr>
|
|
5452
|
+
<tr>
|
|
5453
|
+
<td>23</td>
|
|
5454
|
+
<td>70368744177664</td>
|
|
5455
|
+
<td>13</td>
|
|
5456
|
+
<td>11626681248842</td>
|
|
5457
|
+
<td>0.165225078</td>
|
|
5458
|
+
</tr>
|
|
5459
|
+
<tr>
|
|
5460
|
+
<td>24</td>
|
|
5461
|
+
<td>281474976710656</td>
|
|
5462
|
+
<td>14</td>
|
|
5463
|
+
<td>81386768741882</td>
|
|
5464
|
+
<td>0.2891438866</td>
|
|
5465
|
+
</tr>
|
|
5466
|
+
<tr>
|
|
5467
|
+
<td>25</td>
|
|
5468
|
+
<td>1125899906842620</td>
|
|
5469
|
+
<td>15</td>
|
|
5470
|
+
<td>569707381193162</td>
|
|
5471
|
+
<td>0.5060018015</td>
|
|
5472
|
+
</tr>
|
|
5473
|
+
<tr>
|
|
5474
|
+
<td>26</td>
|
|
5475
|
+
<td>4503599627370500</td>
|
|
5476
|
+
<td>15</td>
|
|
5477
|
+
<td>569707381193162</td>
|
|
5478
|
+
<td>0.1265004504</td>
|
|
5479
|
+
</tr>
|
|
5480
|
+
<tr>
|
|
5481
|
+
<td>27</td>
|
|
5482
|
+
<td>18014398509482000</td>
|
|
5483
|
+
<td>15</td>
|
|
5484
|
+
<td>569707381193162</td>
|
|
5485
|
+
<td>0.03162511259</td>
|
|
5486
|
+
</tr>
|
|
5487
|
+
<tr>
|
|
5488
|
+
<td>28</td>
|
|
5489
|
+
<td>72057594037927900</td>
|
|
5490
|
+
<td>15</td>
|
|
5491
|
+
<td>569707381193162</td>
|
|
5492
|
+
<td>0.007906278149</td>
|
|
5493
|
+
</tr>
|
|
5494
|
+
<tr>
|
|
5495
|
+
<td>29</td>
|
|
5496
|
+
<td>288230376151712000</td>
|
|
5497
|
+
<td>15</td>
|
|
5498
|
+
<td>569707381193162</td>
|
|
5499
|
+
<td>0.001976569537</td>
|
|
5500
|
+
</tr>
|
|
5501
|
+
</tbody>
|
|
5502
|
+
</table>
|
|
5503
|
+
<p>Hexagonal cells don't align perfectly on a vector tile.
|
|
5504
|
+
Some cells may intersect more than one vector tile.
|
|
5505
|
+
To compute the H3 resolution for each precision, Elasticsearch compares the average density of hexagonal bins at each resolution with the average density of tile bins at each zoom level.
|
|
5506
|
+
Elasticsearch uses the H3 resolution that is closest to the corresponding geotile density.</p>
|
|
5507
|
+
|
|
5508
|
+
|
|
5509
|
+
`<https://www.elastic.co/guide/en/elasticsearch/reference/8.18/search-vector-tile-api.html>`_
|
|
4424
5510
|
|
|
4425
5511
|
:param index: Comma-separated list of data streams, indices, or aliases to search
|
|
4426
5512
|
:param field: Field containing geospatial data to return
|
|
4427
5513
|
:param zoom: Zoom level for the vector tile to search
|
|
4428
5514
|
:param x: X coordinate for the vector tile to search
|
|
4429
5515
|
:param y: Y coordinate for the vector tile to search
|
|
4430
|
-
:param aggs: Sub-aggregations for the geotile_grid.
|
|
4431
|
-
types: - avg -
|
|
4432
|
-
|
|
4433
|
-
|
|
4434
|
-
|
|
4435
|
-
:param
|
|
4436
|
-
|
|
4437
|
-
|
|
4438
|
-
|
|
4439
|
-
|
|
4440
|
-
|
|
5516
|
+
:param aggs: Sub-aggregations for the geotile_grid. It supports the following
|
|
5517
|
+
aggregation types: - `avg` - `boxplot` - `cardinality` - `extended stats`
|
|
5518
|
+
- `max` - `median absolute deviation` - `min` - `percentile` - `percentile-rank`
|
|
5519
|
+
- `stats` - `sum` - `value count` The aggregation names can't start with
|
|
5520
|
+
`_mvt_`. The `_mvt_` prefix is reserved for internal aggregations.
|
|
5521
|
+
:param buffer: The size, in pixels, of a clipping buffer outside the tile. This
|
|
5522
|
+
allows renderers to avoid outline artifacts from geometries that extend past
|
|
5523
|
+
the extent of the tile.
|
|
5524
|
+
:param exact_bounds: If `false`, the meta layer's feature is the bounding box
|
|
5525
|
+
of the tile. If `true`, the meta layer's feature is a bounding box resulting
|
|
5526
|
+
from a `geo_bounds` aggregation. The aggregation runs on <field> values that
|
|
5527
|
+
intersect the `<zoom>/<x>/<y>` tile with `wrap_longitude` set to `false`.
|
|
5528
|
+
The resulting bounding box may be larger than the vector tile.
|
|
5529
|
+
:param extent: The size, in pixels, of a side of the tile. Vector tiles are square
|
|
4441
5530
|
with equal sides.
|
|
4442
|
-
:param fields:
|
|
4443
|
-
This parameter does not support fields with array values. Fields with
|
|
4444
|
-
values may return inconsistent results.
|
|
4445
|
-
:param grid_agg:
|
|
5531
|
+
:param fields: The fields to return in the `hits` layer. It supports wildcards
|
|
5532
|
+
(`*`). This parameter does not support fields with array values. Fields with
|
|
5533
|
+
array values may return inconsistent results.
|
|
5534
|
+
:param grid_agg: The aggregation used to create a grid for the `field`.
|
|
4446
5535
|
:param grid_precision: Additional zoom levels available through the aggs layer.
|
|
4447
|
-
For example, if
|
|
4448
|
-
level 15. Accepts 0-8. If 0, results don
|
|
5536
|
+
For example, if `<zoom>` is `7` and `grid_precision` is `8`, you can zoom
|
|
5537
|
+
in up to level 15. Accepts 0-8. If 0, results don't include the aggs layer.
|
|
4449
5538
|
:param grid_type: Determines the geometry type for features in the aggs layer.
|
|
4450
|
-
In the aggs layer, each feature represents a geotile_grid cell. If
|
|
4451
|
-
each feature is a
|
|
5539
|
+
In the aggs layer, each feature represents a `geotile_grid` cell. If `grid,
|
|
5540
|
+
each feature is a polygon of the cells bounding box. If `point`, each feature
|
|
4452
5541
|
is a Point that is the centroid of the cell.
|
|
4453
|
-
:param query:
|
|
5542
|
+
:param query: The query DSL used to filter documents for the search.
|
|
4454
5543
|
:param runtime_mappings: Defines one or more runtime fields in the search request.
|
|
4455
5544
|
These fields take precedence over mapped fields with the same name.
|
|
4456
|
-
:param size:
|
|
4457
|
-
0-10000. If 0, results don
|
|
4458
|
-
:param sort:
|
|
4459
|
-
a bounding box for each feature. It sorts features based on this box
|
|
5545
|
+
:param size: The maximum number of features to return in the hits layer. Accepts
|
|
5546
|
+
0-10000. If 0, results don't include the hits layer.
|
|
5547
|
+
:param sort: Sort the features in the hits layer. By default, the API calculates
|
|
5548
|
+
a bounding box for each feature. It sorts features based on this box's diagonal
|
|
4460
5549
|
length, from longest to shortest.
|
|
4461
|
-
:param track_total_hits:
|
|
5550
|
+
:param track_total_hits: The number of hits matching the query to count accurately.
|
|
4462
5551
|
If `true`, the exact number of hits is returned at the cost of some performance.
|
|
4463
5552
|
If `false`, the response does not include the total number of hits matching
|
|
4464
5553
|
the query.
|
|
4465
5554
|
:param with_labels: If `true`, the hits and aggs layers will contain additional
|
|
4466
5555
|
point features representing suggested label positions for the original features.
|
|
5556
|
+
* `Point` and `MultiPoint` features will have one of the points selected.
|
|
5557
|
+
* `Polygon` and `MultiPolygon` features will have a single point generated,
|
|
5558
|
+
either the centroid, if it is within the polygon, or another point within
|
|
5559
|
+
the polygon selected from the sorted triangle-tree. * `LineString` features
|
|
5560
|
+
will likewise provide a roughly central point selected from the triangle-tree.
|
|
5561
|
+
* The aggregation results will provide one central point for each aggregation
|
|
5562
|
+
bucket. All attributes from the original features will also be copied to
|
|
5563
|
+
the new label features. In addition, the new features will be distinguishable
|
|
5564
|
+
using the tag `_mvt_label_position`.
|
|
4467
5565
|
"""
|
|
4468
5566
|
if index in SKIP_IN_PATH:
|
|
4469
5567
|
raise ValueError("Empty value passed for parameter 'index'")
|
|
@@ -4567,20 +5665,26 @@ class Elasticsearch(BaseClient):
|
|
|
4567
5665
|
human: t.Optional[bool] = None,
|
|
4568
5666
|
ignore_unavailable: t.Optional[bool] = None,
|
|
4569
5667
|
local: t.Optional[bool] = None,
|
|
5668
|
+
master_timeout: t.Optional[t.Union[str, t.Literal[-1], t.Literal[0]]] = None,
|
|
4570
5669
|
preference: t.Optional[str] = None,
|
|
4571
5670
|
pretty: t.Optional[bool] = None,
|
|
4572
5671
|
routing: t.Optional[str] = None,
|
|
4573
5672
|
) -> ObjectApiResponse[t.Any]:
|
|
4574
5673
|
"""
|
|
4575
|
-
|
|
4576
|
-
|
|
4577
|
-
|
|
4578
|
-
|
|
5674
|
+
.. raw:: html
|
|
5675
|
+
|
|
5676
|
+
<p>Get the search shards.</p>
|
|
5677
|
+
<p>Get the indices and shards that a search request would be run against.
|
|
5678
|
+
This information can be useful for working out issues or planning optimizations with routing and shard preferences.
|
|
5679
|
+
When filtered aliases are used, the filter is returned as part of the <code>indices</code> section.</p>
|
|
5680
|
+
<p>If the Elasticsearch security features are enabled, you must have the <code>view_index_metadata</code> or <code>manage</code> index privilege for the target data stream, index, or alias.</p>
|
|
4579
5681
|
|
|
4580
|
-
`<https://www.elastic.co/guide/en/elasticsearch/reference/8.17/search-shards.html>`_
|
|
4581
5682
|
|
|
4582
|
-
|
|
4583
|
-
|
|
5683
|
+
`<https://www.elastic.co/guide/en/elasticsearch/reference/8.18/search-shards.html>`_
|
|
5684
|
+
|
|
5685
|
+
:param index: A comma-separated list of data streams, indices, and aliases to
|
|
5686
|
+
search. It supports wildcards (`*`). To search all data streams and indices,
|
|
5687
|
+
omit this parameter or use `*` or `_all`.
|
|
4584
5688
|
:param allow_no_indices: If `false`, the request returns an error if any wildcard
|
|
4585
5689
|
expression, index alias, or `_all` value targets only missing or closed indices.
|
|
4586
5690
|
This behavior applies even if the request targets other open indices. For
|
|
@@ -4594,9 +5698,13 @@ class Elasticsearch(BaseClient):
|
|
|
4594
5698
|
a missing or closed index.
|
|
4595
5699
|
:param local: If `true`, the request retrieves information from the local node
|
|
4596
5700
|
only.
|
|
4597
|
-
:param
|
|
4598
|
-
|
|
4599
|
-
|
|
5701
|
+
:param master_timeout: The period to wait for a connection to the master node.
|
|
5702
|
+
If the master node is not available before the timeout expires, the request
|
|
5703
|
+
fails and returns an error. IT can also be set to `-1` to indicate that the
|
|
5704
|
+
request should never timeout.
|
|
5705
|
+
:param preference: The node or shard the operation should be performed on. It
|
|
5706
|
+
is random by default.
|
|
5707
|
+
:param routing: A custom value used to route operations to a specific shard.
|
|
4600
5708
|
"""
|
|
4601
5709
|
__path_parts: t.Dict[str, str]
|
|
4602
5710
|
if index not in SKIP_IN_PATH:
|
|
@@ -4620,6 +5728,8 @@ class Elasticsearch(BaseClient):
|
|
|
4620
5728
|
__query["ignore_unavailable"] = ignore_unavailable
|
|
4621
5729
|
if local is not None:
|
|
4622
5730
|
__query["local"] = local
|
|
5731
|
+
if master_timeout is not None:
|
|
5732
|
+
__query["master_timeout"] = master_timeout
|
|
4623
5733
|
if preference is not None:
|
|
4624
5734
|
__query["preference"] = preference
|
|
4625
5735
|
if pretty is not None:
|
|
@@ -4676,12 +5786,15 @@ class Elasticsearch(BaseClient):
|
|
|
4676
5786
|
body: t.Optional[t.Dict[str, t.Any]] = None,
|
|
4677
5787
|
) -> ObjectApiResponse[t.Any]:
|
|
4678
5788
|
"""
|
|
4679
|
-
|
|
5789
|
+
.. raw:: html
|
|
4680
5790
|
|
|
4681
|
-
|
|
5791
|
+
<p>Run a search with a search template.</p>
|
|
4682
5792
|
|
|
4683
|
-
|
|
4684
|
-
|
|
5793
|
+
|
|
5794
|
+
`<https://www.elastic.co/guide/en/elasticsearch/reference/8.18/search-template-api.html>`_
|
|
5795
|
+
|
|
5796
|
+
:param index: A comma-separated list of data streams, indices, and aliases to
|
|
5797
|
+
search. It supports wildcards (`*`).
|
|
4685
5798
|
:param allow_no_indices: If `false`, the request returns an error if any wildcard
|
|
4686
5799
|
expression, index alias, or `_all` value targets only missing or closed indices.
|
|
4687
5800
|
This behavior applies even if the request targets other open indices. For
|
|
@@ -4689,32 +5802,34 @@ class Elasticsearch(BaseClient):
|
|
|
4689
5802
|
with `foo` but no index starts with `bar`.
|
|
4690
5803
|
:param ccs_minimize_roundtrips: If `true`, network round-trips are minimized
|
|
4691
5804
|
for cross-cluster search requests.
|
|
4692
|
-
:param expand_wildcards:
|
|
4693
|
-
request can target data streams, this argument determines whether
|
|
4694
|
-
expressions match hidden data streams. Supports comma-separated
|
|
4695
|
-
as `open,hidden`. Valid values are: `all`, `open`, `closed`,
|
|
5805
|
+
:param expand_wildcards: The type of index that wildcard patterns can match.
|
|
5806
|
+
If the request can target data streams, this argument determines whether
|
|
5807
|
+
wildcard expressions match hidden data streams. Supports comma-separated
|
|
5808
|
+
values, such as `open,hidden`. Valid values are: `all`, `open`, `closed`,
|
|
5809
|
+
`hidden`, `none`.
|
|
4696
5810
|
:param explain: If `true`, returns detailed information about score calculation
|
|
4697
|
-
as part of each hit.
|
|
4698
|
-
|
|
4699
|
-
|
|
5811
|
+
as part of each hit. If you specify both this and the `explain` query parameter,
|
|
5812
|
+
the API uses only the query parameter.
|
|
5813
|
+
:param id: The ID of the search template to use. If no `source` is specified,
|
|
5814
|
+
this parameter is required.
|
|
4700
5815
|
:param ignore_throttled: If `true`, specified concrete, expanded, or aliased
|
|
4701
5816
|
indices are not included in the response when throttled.
|
|
4702
5817
|
:param ignore_unavailable: If `false`, the request returns an error if it targets
|
|
4703
5818
|
a missing or closed index.
|
|
4704
5819
|
:param params: Key-value pairs used to replace Mustache variables in the template.
|
|
4705
5820
|
The key is the variable name. The value is the variable value.
|
|
4706
|
-
:param preference:
|
|
4707
|
-
|
|
5821
|
+
:param preference: The node or shard the operation should be performed on. It
|
|
5822
|
+
is random by default.
|
|
4708
5823
|
:param profile: If `true`, the query execution is profiled.
|
|
4709
|
-
:param rest_total_hits_as_int: If true
|
|
4710
|
-
in the response.
|
|
4711
|
-
:param routing:
|
|
5824
|
+
:param rest_total_hits_as_int: If `true`, `hits.total` is rendered as an integer
|
|
5825
|
+
in the response. If `false`, it is rendered as an object.
|
|
5826
|
+
:param routing: A custom value used to route operations to a specific shard.
|
|
4712
5827
|
:param scroll: Specifies how long a consistent view of the index should be maintained
|
|
4713
5828
|
for scrolled search.
|
|
4714
5829
|
:param search_type: The type of the search operation.
|
|
4715
5830
|
:param source: An inline search template. Supports the same parameters as the
|
|
4716
|
-
search API's request body.
|
|
4717
|
-
specified, this parameter is required.
|
|
5831
|
+
search API's request body. It also supports Mustache variables. If no `id`
|
|
5832
|
+
is specified, this parameter is required.
|
|
4718
5833
|
:param typed_keys: If `true`, the response prefixes aggregation and suggester
|
|
4719
5834
|
names with their respective types.
|
|
4720
5835
|
"""
|
|
@@ -4808,34 +5923,39 @@ class Elasticsearch(BaseClient):
|
|
|
4808
5923
|
body: t.Optional[t.Dict[str, t.Any]] = None,
|
|
4809
5924
|
) -> ObjectApiResponse[t.Any]:
|
|
4810
5925
|
"""
|
|
4811
|
-
|
|
4812
|
-
This "terms enum" API is designed for low-latency look-ups used in auto-complete
|
|
4813
|
-
scenarios. If the `complete` property in the response is false, the returned
|
|
4814
|
-
terms set may be incomplete and should be treated as approximate. This can occur
|
|
4815
|
-
due to a few reasons, such as a request timeout or a node error. NOTE: The terms
|
|
4816
|
-
enum API may return terms from deleted documents. Deleted documents are initially
|
|
4817
|
-
only marked as deleted. It is not until their segments are merged that documents
|
|
4818
|
-
are actually deleted. Until that happens, the terms enum API will return terms
|
|
4819
|
-
from these documents.
|
|
4820
|
-
|
|
4821
|
-
`<https://www.elastic.co/guide/en/elasticsearch/reference/8.17/search-terms-enum.html>`_
|
|
5926
|
+
.. raw:: html
|
|
4822
5927
|
|
|
4823
|
-
|
|
4824
|
-
|
|
5928
|
+
<p>Get terms in an index.</p>
|
|
5929
|
+
<p>Discover terms that match a partial string in an index.
|
|
5930
|
+
This API is designed for low-latency look-ups used in auto-complete scenarios.</p>
|
|
5931
|
+
<blockquote>
|
|
5932
|
+
<p>info
|
|
5933
|
+
The terms enum API may return terms from deleted documents. Deleted documents are initially only marked as deleted. It is not until their segments are merged that documents are actually deleted. Until that happens, the terms enum API will return terms from these documents.</p>
|
|
5934
|
+
</blockquote>
|
|
5935
|
+
|
|
5936
|
+
|
|
5937
|
+
`<https://www.elastic.co/guide/en/elasticsearch/reference/8.18/search-terms-enum.html>`_
|
|
5938
|
+
|
|
5939
|
+
:param index: A comma-separated list of data streams, indices, and index aliases
|
|
5940
|
+
to search. Wildcard (`*`) expressions are supported. To search all data streams
|
|
5941
|
+
or indices, omit this parameter or use `*` or `_all`.
|
|
4825
5942
|
:param field: The string to match at the start of indexed terms. If not provided,
|
|
4826
5943
|
all terms in the field are considered.
|
|
4827
|
-
:param case_insensitive: When true the provided search string is matched against
|
|
5944
|
+
:param case_insensitive: When `true`, the provided search string is matched against
|
|
4828
5945
|
index terms without case sensitivity.
|
|
4829
|
-
:param index_filter:
|
|
4830
|
-
|
|
4831
|
-
:param search_after:
|
|
4832
|
-
|
|
4833
|
-
|
|
4834
|
-
|
|
4835
|
-
|
|
4836
|
-
|
|
4837
|
-
|
|
4838
|
-
|
|
5946
|
+
:param index_filter: Filter an index shard if the provided query rewrites to
|
|
5947
|
+
`match_none`.
|
|
5948
|
+
:param search_after: The string after which terms in the index should be returned.
|
|
5949
|
+
It allows for a form of pagination if the last result from one request is
|
|
5950
|
+
passed as the `search_after` parameter for a subsequent request.
|
|
5951
|
+
:param size: The number of matching terms to return.
|
|
5952
|
+
:param string: The string to match at the start of indexed terms. If it is not
|
|
5953
|
+
provided, all terms in the field are considered. > info > The prefix string
|
|
5954
|
+
cannot be larger than the largest possible keyword value, which is Lucene's
|
|
5955
|
+
term byte-length limit of 32766.
|
|
5956
|
+
:param timeout: The maximum length of time to spend collecting results. If the
|
|
5957
|
+
timeout is exceeded the `complete` flag set to `false` in the response and
|
|
5958
|
+
the results may be partial or empty.
|
|
4839
5959
|
"""
|
|
4840
5960
|
if index in SKIP_IN_PATH:
|
|
4841
5961
|
raise ValueError("Empty value passed for parameter 'index'")
|
|
@@ -4884,7 +6004,20 @@ class Elasticsearch(BaseClient):
|
|
|
4884
6004
|
)
|
|
4885
6005
|
|
|
4886
6006
|
@_rewrite_parameters(
|
|
4887
|
-
body_fields=(
|
|
6007
|
+
body_fields=(
|
|
6008
|
+
"doc",
|
|
6009
|
+
"field_statistics",
|
|
6010
|
+
"fields",
|
|
6011
|
+
"filter",
|
|
6012
|
+
"offsets",
|
|
6013
|
+
"payloads",
|
|
6014
|
+
"per_field_analyzer",
|
|
6015
|
+
"positions",
|
|
6016
|
+
"routing",
|
|
6017
|
+
"term_statistics",
|
|
6018
|
+
"version",
|
|
6019
|
+
"version_type",
|
|
6020
|
+
),
|
|
4888
6021
|
)
|
|
4889
6022
|
def termvectors(
|
|
4890
6023
|
self,
|
|
@@ -4914,33 +6047,77 @@ class Elasticsearch(BaseClient):
|
|
|
4914
6047
|
body: t.Optional[t.Dict[str, t.Any]] = None,
|
|
4915
6048
|
) -> ObjectApiResponse[t.Any]:
|
|
4916
6049
|
"""
|
|
4917
|
-
|
|
4918
|
-
|
|
4919
|
-
|
|
4920
|
-
|
|
4921
|
-
|
|
4922
|
-
|
|
4923
|
-
|
|
6050
|
+
.. raw:: html
|
|
6051
|
+
|
|
6052
|
+
<p>Get term vector information.</p>
|
|
6053
|
+
<p>Get information and statistics about terms in the fields of a particular document.</p>
|
|
6054
|
+
<p>You can retrieve term vectors for documents stored in the index or for artificial documents passed in the body of the request.
|
|
6055
|
+
You can specify the fields you are interested in through the <code>fields</code> parameter or by adding the fields to the request body.
|
|
6056
|
+
For example:</p>
|
|
6057
|
+
<pre><code>GET /my-index-000001/_termvectors/1?fields=message
|
|
6058
|
+
</code></pre>
|
|
6059
|
+
<p>Fields can be specified using wildcards, similar to the multi match query.</p>
|
|
6060
|
+
<p>Term vectors are real-time by default, not near real-time.
|
|
6061
|
+
This can be changed by setting <code>realtime</code> parameter to <code>false</code>.</p>
|
|
6062
|
+
<p>You can request three types of values: <em>term information</em>, <em>term statistics</em>, and <em>field statistics</em>.
|
|
6063
|
+
By default, all term information and field statistics are returned for all fields but term statistics are excluded.</p>
|
|
6064
|
+
<p><strong>Term information</strong></p>
|
|
6065
|
+
<ul>
|
|
6066
|
+
<li>term frequency in the field (always returned)</li>
|
|
6067
|
+
<li>term positions (<code>positions: true</code>)</li>
|
|
6068
|
+
<li>start and end offsets (<code>offsets: true</code>)</li>
|
|
6069
|
+
<li>term payloads (<code>payloads: true</code>), as base64 encoded bytes</li>
|
|
6070
|
+
</ul>
|
|
6071
|
+
<p>If the requested information wasn't stored in the index, it will be computed on the fly if possible.
|
|
6072
|
+
Additionally, term vectors could be computed for documents not even existing in the index, but instead provided by the user.</p>
|
|
6073
|
+
<blockquote>
|
|
6074
|
+
<p>warn
|
|
6075
|
+
Start and end offsets assume UTF-16 encoding is being used. If you want to use these offsets in order to get the original text that produced this token, you should make sure that the string you are taking a sub-string of is also encoded using UTF-16.</p>
|
|
6076
|
+
</blockquote>
|
|
6077
|
+
<p><strong>Behaviour</strong></p>
|
|
6078
|
+
<p>The term and field statistics are not accurate.
|
|
6079
|
+
Deleted documents are not taken into account.
|
|
6080
|
+
The information is only retrieved for the shard the requested document resides in.
|
|
6081
|
+
The term and field statistics are therefore only useful as relative measures whereas the absolute numbers have no meaning in this context.
|
|
6082
|
+
By default, when requesting term vectors of artificial documents, a shard to get the statistics from is randomly selected.
|
|
6083
|
+
Use <code>routing</code> only to hit a particular shard.</p>
|
|
6084
|
+
|
|
6085
|
+
|
|
6086
|
+
`<https://www.elastic.co/guide/en/elasticsearch/reference/8.18/docs-termvectors.html>`_
|
|
6087
|
+
|
|
6088
|
+
:param index: The name of the index that contains the document.
|
|
6089
|
+
:param id: A unique identifier for the document.
|
|
4924
6090
|
:param doc: An artificial document (a document not present in the index) for
|
|
4925
6091
|
which you want to retrieve term vectors.
|
|
4926
|
-
:param field_statistics: If `true`, the response includes
|
|
4927
|
-
|
|
4928
|
-
|
|
4929
|
-
|
|
4930
|
-
|
|
4931
|
-
:param
|
|
6092
|
+
:param field_statistics: If `true`, the response includes: * The document count
|
|
6093
|
+
(how many documents contain this field). * The sum of document frequencies
|
|
6094
|
+
(the sum of document frequencies for all terms in this field). * The sum
|
|
6095
|
+
of total term frequencies (the sum of total term frequencies of each term
|
|
6096
|
+
in this field).
|
|
6097
|
+
:param fields: A list of fields to include in the statistics. It is used as the
|
|
6098
|
+
default list unless a specific field list is provided in the `completion_fields`
|
|
6099
|
+
or `fielddata_fields` parameters.
|
|
6100
|
+
:param filter: Filter terms based on their tf-idf scores. This could be useful
|
|
6101
|
+
in order find out a good characteristic vector of a document. This feature
|
|
6102
|
+
works in a similar manner to the second phase of the More Like This Query.
|
|
4932
6103
|
:param offsets: If `true`, the response includes term offsets.
|
|
4933
6104
|
:param payloads: If `true`, the response includes term payloads.
|
|
4934
|
-
:param per_field_analyzer:
|
|
6105
|
+
:param per_field_analyzer: Override the default per-field analyzer. This is useful
|
|
6106
|
+
in order to generate term vectors in any fashion, especially when using artificial
|
|
6107
|
+
documents. When providing an analyzer for a field that already stores term
|
|
6108
|
+
vectors, the term vectors will be regenerated.
|
|
4935
6109
|
:param positions: If `true`, the response includes term positions.
|
|
4936
|
-
:param preference:
|
|
4937
|
-
|
|
6110
|
+
:param preference: The node or shard the operation should be performed on. It
|
|
6111
|
+
is random by default.
|
|
4938
6112
|
:param realtime: If true, the request is real-time as opposed to near-real-time.
|
|
4939
|
-
:param routing:
|
|
4940
|
-
|
|
4941
|
-
|
|
6113
|
+
:param routing: A custom value that is used to route operations to a specific
|
|
6114
|
+
shard.
|
|
6115
|
+
:param term_statistics: If `true`, the response includes: * The total term frequency
|
|
6116
|
+
(how often a term occurs in all documents). * The document frequency (the
|
|
6117
|
+
number of documents containing the current term). By default these values
|
|
6118
|
+
are not returned since term statistics can have a serious performance impact.
|
|
4942
6119
|
:param version: If `true`, returns the document version as part of a hit.
|
|
4943
|
-
:param version_type:
|
|
6120
|
+
:param version_type: The version type.
|
|
4944
6121
|
"""
|
|
4945
6122
|
if index in SKIP_IN_PATH:
|
|
4946
6123
|
raise ValueError("Empty value passed for parameter 'index'")
|
|
@@ -4957,41 +6134,41 @@ class Elasticsearch(BaseClient):
|
|
|
4957
6134
|
__body: t.Dict[str, t.Any] = body if body is not None else {}
|
|
4958
6135
|
if error_trace is not None:
|
|
4959
6136
|
__query["error_trace"] = error_trace
|
|
4960
|
-
if field_statistics is not None:
|
|
4961
|
-
__query["field_statistics"] = field_statistics
|
|
4962
|
-
if fields is not None:
|
|
4963
|
-
__query["fields"] = fields
|
|
4964
6137
|
if filter_path is not None:
|
|
4965
6138
|
__query["filter_path"] = filter_path
|
|
4966
6139
|
if human is not None:
|
|
4967
6140
|
__query["human"] = human
|
|
4968
|
-
if offsets is not None:
|
|
4969
|
-
__query["offsets"] = offsets
|
|
4970
|
-
if payloads is not None:
|
|
4971
|
-
__query["payloads"] = payloads
|
|
4972
|
-
if positions is not None:
|
|
4973
|
-
__query["positions"] = positions
|
|
4974
6141
|
if preference is not None:
|
|
4975
6142
|
__query["preference"] = preference
|
|
4976
6143
|
if pretty is not None:
|
|
4977
6144
|
__query["pretty"] = pretty
|
|
4978
6145
|
if realtime is not None:
|
|
4979
6146
|
__query["realtime"] = realtime
|
|
4980
|
-
if routing is not None:
|
|
4981
|
-
__query["routing"] = routing
|
|
4982
|
-
if term_statistics is not None:
|
|
4983
|
-
__query["term_statistics"] = term_statistics
|
|
4984
|
-
if version is not None:
|
|
4985
|
-
__query["version"] = version
|
|
4986
|
-
if version_type is not None:
|
|
4987
|
-
__query["version_type"] = version_type
|
|
4988
6147
|
if not __body:
|
|
4989
6148
|
if doc is not None:
|
|
4990
6149
|
__body["doc"] = doc
|
|
6150
|
+
if field_statistics is not None:
|
|
6151
|
+
__body["field_statistics"] = field_statistics
|
|
6152
|
+
if fields is not None:
|
|
6153
|
+
__body["fields"] = fields
|
|
4991
6154
|
if filter is not None:
|
|
4992
6155
|
__body["filter"] = filter
|
|
6156
|
+
if offsets is not None:
|
|
6157
|
+
__body["offsets"] = offsets
|
|
6158
|
+
if payloads is not None:
|
|
6159
|
+
__body["payloads"] = payloads
|
|
4993
6160
|
if per_field_analyzer is not None:
|
|
4994
6161
|
__body["per_field_analyzer"] = per_field_analyzer
|
|
6162
|
+
if positions is not None:
|
|
6163
|
+
__body["positions"] = positions
|
|
6164
|
+
if routing is not None:
|
|
6165
|
+
__body["routing"] = routing
|
|
6166
|
+
if term_statistics is not None:
|
|
6167
|
+
__body["term_statistics"] = term_statistics
|
|
6168
|
+
if version is not None:
|
|
6169
|
+
__body["version"] = version
|
|
6170
|
+
if version_type is not None:
|
|
6171
|
+
__body["version_type"] = version_type
|
|
4995
6172
|
if not __body:
|
|
4996
6173
|
__body = None # type: ignore[assignment]
|
|
4997
6174
|
__headers = {"accept": "application/json"}
|
|
@@ -5036,6 +6213,7 @@ class Elasticsearch(BaseClient):
|
|
|
5036
6213
|
human: t.Optional[bool] = None,
|
|
5037
6214
|
if_primary_term: t.Optional[int] = None,
|
|
5038
6215
|
if_seq_no: t.Optional[int] = None,
|
|
6216
|
+
include_source_on_error: t.Optional[bool] = None,
|
|
5039
6217
|
lang: t.Optional[str] = None,
|
|
5040
6218
|
pretty: t.Optional[bool] = None,
|
|
5041
6219
|
refresh: t.Optional[
|
|
@@ -5057,46 +6235,67 @@ class Elasticsearch(BaseClient):
|
|
|
5057
6235
|
body: t.Optional[t.Dict[str, t.Any]] = None,
|
|
5058
6236
|
) -> ObjectApiResponse[t.Any]:
|
|
5059
6237
|
"""
|
|
5060
|
-
|
|
5061
|
-
|
|
5062
|
-
|
|
5063
|
-
|
|
5064
|
-
|
|
5065
|
-
|
|
5066
|
-
|
|
5067
|
-
|
|
5068
|
-
|
|
5069
|
-
|
|
5070
|
-
|
|
5071
|
-
|
|
6238
|
+
.. raw:: html
|
|
6239
|
+
|
|
6240
|
+
<p>Update a document.</p>
|
|
6241
|
+
<p>Update a document by running a script or passing a partial document.</p>
|
|
6242
|
+
<p>If the Elasticsearch security features are enabled, you must have the <code>index</code> or <code>write</code> index privilege for the target index or index alias.</p>
|
|
6243
|
+
<p>The script can update, delete, or skip modifying the document.
|
|
6244
|
+
The API also supports passing a partial document, which is merged into the existing document.
|
|
6245
|
+
To fully replace an existing document, use the index API.
|
|
6246
|
+
This operation:</p>
|
|
6247
|
+
<ul>
|
|
6248
|
+
<li>Gets the document (collocated with the shard) from the index.</li>
|
|
6249
|
+
<li>Runs the specified script.</li>
|
|
6250
|
+
<li>Indexes the result.</li>
|
|
6251
|
+
</ul>
|
|
6252
|
+
<p>The document must still be reindexed, but using this API removes some network roundtrips and reduces chances of version conflicts between the GET and the index operation.</p>
|
|
6253
|
+
<p>The <code>_source</code> field must be enabled to use this API.
|
|
6254
|
+
In addition to <code>_source</code>, you can access the following variables through the <code>ctx</code> map: <code>_index</code>, <code>_type</code>, <code>_id</code>, <code>_version</code>, <code>_routing</code>, and <code>_now</code> (the current timestamp).</p>
|
|
6255
|
+
|
|
6256
|
+
|
|
6257
|
+
`<https://www.elastic.co/guide/en/elasticsearch/reference/8.18/docs-update.html>`_
|
|
6258
|
+
|
|
6259
|
+
:param index: The name of the target index. By default, the index is created
|
|
6260
|
+
automatically if it doesn't exist.
|
|
6261
|
+
:param id: A unique identifier for the document to be updated.
|
|
6262
|
+
:param detect_noop: If `true`, the `result` in the response is set to `noop`
|
|
6263
|
+
(no operation) when there are no changes to the document.
|
|
6264
|
+
:param doc: A partial update to an existing document. If both `doc` and `script`
|
|
6265
|
+
are specified, `doc` is ignored.
|
|
6266
|
+
:param doc_as_upsert: If `true`, use the contents of 'doc' as the value of 'upsert'.
|
|
6267
|
+
NOTE: Using ingest pipelines with `doc_as_upsert` is not supported.
|
|
5072
6268
|
:param if_primary_term: Only perform the operation if the document has this primary
|
|
5073
6269
|
term.
|
|
5074
6270
|
:param if_seq_no: Only perform the operation if the document has this sequence
|
|
5075
6271
|
number.
|
|
6272
|
+
:param include_source_on_error: True or false if to include the document source
|
|
6273
|
+
in the error message in case of parsing errors.
|
|
5076
6274
|
:param lang: The script language.
|
|
5077
6275
|
:param refresh: If 'true', Elasticsearch refreshes the affected shards to make
|
|
5078
|
-
this operation visible to search
|
|
5079
|
-
make this operation visible to search
|
|
5080
|
-
:param require_alias: If true
|
|
5081
|
-
:param retry_on_conflict:
|
|
6276
|
+
this operation visible to search. If 'wait_for', it waits for a refresh to
|
|
6277
|
+
make this operation visible to search. If 'false', it does nothing with refreshes.
|
|
6278
|
+
:param require_alias: If `true`, the destination must be an index alias.
|
|
6279
|
+
:param retry_on_conflict: The number of times the operation should be retried
|
|
5082
6280
|
when a conflict occurs.
|
|
5083
|
-
:param routing:
|
|
5084
|
-
:param script:
|
|
5085
|
-
:param scripted_upsert:
|
|
5086
|
-
|
|
5087
|
-
:param source:
|
|
5088
|
-
|
|
5089
|
-
:param source_excludes:
|
|
5090
|
-
:param source_includes:
|
|
5091
|
-
:param timeout:
|
|
5092
|
-
|
|
5093
|
-
The actual wait time could be longer, particularly
|
|
6281
|
+
:param routing: A custom value used to route operations to a specific shard.
|
|
6282
|
+
:param script: The script to run to update the document.
|
|
6283
|
+
:param scripted_upsert: If `true`, run the script whether or not the document
|
|
6284
|
+
exists.
|
|
6285
|
+
:param source: If `false`, turn off source retrieval. You can also specify a
|
|
6286
|
+
comma-separated list of the fields you want to retrieve.
|
|
6287
|
+
:param source_excludes: The source fields you want to exclude.
|
|
6288
|
+
:param source_includes: The source fields you want to retrieve.
|
|
6289
|
+
:param timeout: The period to wait for the following operations: dynamic mapping
|
|
6290
|
+
updates and waiting for active shards. Elasticsearch waits for at least the
|
|
6291
|
+
timeout period before failing. The actual wait time could be longer, particularly
|
|
6292
|
+
when multiple waits occur.
|
|
5094
6293
|
:param upsert: If the document does not already exist, the contents of 'upsert'
|
|
5095
|
-
are inserted as a new document. If the document exists, the 'script' is
|
|
5096
|
-
:param wait_for_active_shards: The number of shard
|
|
5097
|
-
before proceeding with the
|
|
5098
|
-
up to the total number of shards in the index (number_of_replicas
|
|
5099
|
-
|
|
6294
|
+
are inserted as a new document. If the document exists, the 'script' is run.
|
|
6295
|
+
:param wait_for_active_shards: The number of copies of each shard that must be
|
|
6296
|
+
active before proceeding with the operation. Set to 'all' or any positive
|
|
6297
|
+
integer up to the total number of shards in the index (`number_of_replicas`+1).
|
|
6298
|
+
The default value of `1` means it waits for each primary shard to be active.
|
|
5100
6299
|
"""
|
|
5101
6300
|
if index in SKIP_IN_PATH:
|
|
5102
6301
|
raise ValueError("Empty value passed for parameter 'index'")
|
|
@@ -5116,6 +6315,8 @@ class Elasticsearch(BaseClient):
|
|
|
5116
6315
|
__query["if_primary_term"] = if_primary_term
|
|
5117
6316
|
if if_seq_no is not None:
|
|
5118
6317
|
__query["if_seq_no"] = if_seq_no
|
|
6318
|
+
if include_source_on_error is not None:
|
|
6319
|
+
__query["include_source_on_error"] = include_source_on_error
|
|
5119
6320
|
if lang is not None:
|
|
5120
6321
|
__query["lang"] = lang
|
|
5121
6322
|
if pretty is not None:
|
|
@@ -5222,82 +6423,166 @@ class Elasticsearch(BaseClient):
|
|
|
5222
6423
|
body: t.Optional[t.Dict[str, t.Any]] = None,
|
|
5223
6424
|
) -> ObjectApiResponse[t.Any]:
|
|
5224
6425
|
"""
|
|
5225
|
-
|
|
5226
|
-
|
|
5227
|
-
|
|
5228
|
-
|
|
5229
|
-
|
|
6426
|
+
.. raw:: html
|
|
6427
|
+
|
|
6428
|
+
<p>Update documents.
|
|
6429
|
+
Updates documents that match the specified query.
|
|
6430
|
+
If no query is specified, performs an update on every document in the data stream or index without modifying the source, which is useful for picking up mapping changes.</p>
|
|
6431
|
+
<p>If the Elasticsearch security features are enabled, you must have the following index privileges for the target data stream, index, or alias:</p>
|
|
6432
|
+
<ul>
|
|
6433
|
+
<li><code>read</code></li>
|
|
6434
|
+
<li><code>index</code> or <code>write</code></li>
|
|
6435
|
+
</ul>
|
|
6436
|
+
<p>You can specify the query criteria in the request URI or the request body using the same syntax as the search API.</p>
|
|
6437
|
+
<p>When you submit an update by query request, Elasticsearch gets a snapshot of the data stream or index when it begins processing the request and updates matching documents using internal versioning.
|
|
6438
|
+
When the versions match, the document is updated and the version number is incremented.
|
|
6439
|
+
If a document changes between the time that the snapshot is taken and the update operation is processed, it results in a version conflict and the operation fails.
|
|
6440
|
+
You can opt to count version conflicts instead of halting and returning by setting <code>conflicts</code> to <code>proceed</code>.
|
|
6441
|
+
Note that if you opt to count version conflicts, the operation could attempt to update more documents from the source than <code>max_docs</code> until it has successfully updated <code>max_docs</code> documents or it has gone through every document in the source query.</p>
|
|
6442
|
+
<p>NOTE: Documents with a version equal to 0 cannot be updated using update by query because internal versioning does not support 0 as a valid version number.</p>
|
|
6443
|
+
<p>While processing an update by query request, Elasticsearch performs multiple search requests sequentially to find all of the matching documents.
|
|
6444
|
+
A bulk update request is performed for each batch of matching documents.
|
|
6445
|
+
Any query or update failures cause the update by query request to fail and the failures are shown in the response.
|
|
6446
|
+
Any update requests that completed successfully still stick, they are not rolled back.</p>
|
|
6447
|
+
<p><strong>Throttling update requests</strong></p>
|
|
6448
|
+
<p>To control the rate at which update by query issues batches of update operations, you can set <code>requests_per_second</code> to any positive decimal number.
|
|
6449
|
+
This pads each batch with a wait time to throttle the rate.
|
|
6450
|
+
Set <code>requests_per_second</code> to <code>-1</code> to turn off throttling.</p>
|
|
6451
|
+
<p>Throttling uses a wait time between batches so that the internal scroll requests can be given a timeout that takes the request padding into account.
|
|
6452
|
+
The padding time is the difference between the batch size divided by the <code>requests_per_second</code> and the time spent writing.
|
|
6453
|
+
By default the batch size is 1000, so if <code>requests_per_second</code> is set to <code>500</code>:</p>
|
|
6454
|
+
<pre><code>target_time = 1000 / 500 per second = 2 seconds
|
|
6455
|
+
wait_time = target_time - write_time = 2 seconds - .5 seconds = 1.5 seconds
|
|
6456
|
+
</code></pre>
|
|
6457
|
+
<p>Since the batch is issued as a single _bulk request, large batch sizes cause Elasticsearch to create many requests and wait before starting the next set.
|
|
6458
|
+
This is "bursty" instead of "smooth".</p>
|
|
6459
|
+
<p><strong>Slicing</strong></p>
|
|
6460
|
+
<p>Update by query supports sliced scroll to parallelize the update process.
|
|
6461
|
+
This can improve efficiency and provide a convenient way to break the request down into smaller parts.</p>
|
|
6462
|
+
<p>Setting <code>slices</code> to <code>auto</code> chooses a reasonable number for most data streams and indices.
|
|
6463
|
+
This setting will use one slice per shard, up to a certain limit.
|
|
6464
|
+
If there are multiple source data streams or indices, it will choose the number of slices based on the index or backing index with the smallest number of shards.</p>
|
|
6465
|
+
<p>Adding <code>slices</code> to <code>_update_by_query</code> just automates the manual process of creating sub-requests, which means it has some quirks:</p>
|
|
6466
|
+
<ul>
|
|
6467
|
+
<li>You can see these requests in the tasks APIs. These sub-requests are "child" tasks of the task for the request with slices.</li>
|
|
6468
|
+
<li>Fetching the status of the task for the request with <code>slices</code> only contains the status of completed slices.</li>
|
|
6469
|
+
<li>These sub-requests are individually addressable for things like cancellation and rethrottling.</li>
|
|
6470
|
+
<li>Rethrottling the request with <code>slices</code> will rethrottle the unfinished sub-request proportionally.</li>
|
|
6471
|
+
<li>Canceling the request with slices will cancel each sub-request.</li>
|
|
6472
|
+
<li>Due to the nature of slices each sub-request won't get a perfectly even portion of the documents. All documents will be addressed, but some slices may be larger than others. Expect larger slices to have a more even distribution.</li>
|
|
6473
|
+
<li>Parameters like <code>requests_per_second</code> and <code>max_docs</code> on a request with slices are distributed proportionally to each sub-request. Combine that with the point above about distribution being uneven and you should conclude that using <code>max_docs</code> with <code>slices</code> might not result in exactly <code>max_docs</code> documents being updated.</li>
|
|
6474
|
+
<li>Each sub-request gets a slightly different snapshot of the source data stream or index though these are all taken at approximately the same time.</li>
|
|
6475
|
+
</ul>
|
|
6476
|
+
<p>If you're slicing manually or otherwise tuning automatic slicing, keep in mind that:</p>
|
|
6477
|
+
<ul>
|
|
6478
|
+
<li>Query performance is most efficient when the number of slices is equal to the number of shards in the index or backing index. If that number is large (for example, 500), choose a lower number as too many slices hurts performance. Setting slices higher than the number of shards generally does not improve efficiency and adds overhead.</li>
|
|
6479
|
+
<li>Update performance scales linearly across available resources with the number of slices.</li>
|
|
6480
|
+
</ul>
|
|
6481
|
+
<p>Whether query or update performance dominates the runtime depends on the documents being reindexed and cluster resources.</p>
|
|
6482
|
+
<p><strong>Update the document source</strong></p>
|
|
6483
|
+
<p>Update by query supports scripts to update the document source.
|
|
6484
|
+
As with the update API, you can set <code>ctx.op</code> to change the operation that is performed.</p>
|
|
6485
|
+
<p>Set <code>ctx.op = "noop"</code> if your script decides that it doesn't have to make any changes.
|
|
6486
|
+
The update by query operation skips updating the document and increments the <code>noop</code> counter.</p>
|
|
6487
|
+
<p>Set <code>ctx.op = "delete"</code> if your script decides that the document should be deleted.
|
|
6488
|
+
The update by query operation deletes the document and increments the <code>deleted</code> counter.</p>
|
|
6489
|
+
<p>Update by query supports only <code>index</code>, <code>noop</code>, and <code>delete</code>.
|
|
6490
|
+
Setting <code>ctx.op</code> to anything else is an error.
|
|
6491
|
+
Setting any other field in <code>ctx</code> is an error.
|
|
6492
|
+
This API enables you to only modify the source of matching documents; you cannot move them.</p>
|
|
6493
|
+
|
|
6494
|
+
|
|
6495
|
+
`<https://www.elastic.co/guide/en/elasticsearch/reference/8.18/docs-update-by-query.html>`_
|
|
5230
6496
|
|
|
5231
|
-
:param index:
|
|
5232
|
-
|
|
5233
|
-
parameter or use `*` or `_all`.
|
|
6497
|
+
:param index: A comma-separated list of data streams, indices, and aliases to
|
|
6498
|
+
search. It supports wildcards (`*`). To search all data streams or indices,
|
|
6499
|
+
omit this parameter or use `*` or `_all`.
|
|
5234
6500
|
:param allow_no_indices: If `false`, the request returns an error if any wildcard
|
|
5235
6501
|
expression, index alias, or `_all` value targets only missing or closed indices.
|
|
5236
6502
|
This behavior applies even if the request targets other open indices. For
|
|
5237
6503
|
example, a request targeting `foo*,bar*` returns an error if an index starts
|
|
5238
6504
|
with `foo` but no index starts with `bar`.
|
|
5239
6505
|
:param analyze_wildcard: If `true`, wildcard and prefix queries are analyzed.
|
|
5240
|
-
|
|
5241
|
-
:param
|
|
5242
|
-
|
|
6506
|
+
This parameter can be used only when the `q` query string parameter is specified.
|
|
6507
|
+
:param analyzer: The analyzer to use for the query string. This parameter can
|
|
6508
|
+
be used only when the `q` query string parameter is specified.
|
|
6509
|
+
:param conflicts: The preferred behavior when update by query hits version conflicts:
|
|
6510
|
+
`abort` or `proceed`.
|
|
5243
6511
|
:param default_operator: The default operator for query string query: `AND` or
|
|
5244
|
-
`OR`.
|
|
5245
|
-
|
|
5246
|
-
|
|
5247
|
-
|
|
5248
|
-
|
|
5249
|
-
|
|
5250
|
-
|
|
5251
|
-
|
|
6512
|
+
`OR`. This parameter can be used only when the `q` query string parameter
|
|
6513
|
+
is specified.
|
|
6514
|
+
:param df: The field to use as default where no field prefix is given in the
|
|
6515
|
+
query string. This parameter can be used only when the `q` query string parameter
|
|
6516
|
+
is specified.
|
|
6517
|
+
:param expand_wildcards: The type of index that wildcard patterns can match.
|
|
6518
|
+
If the request can target data streams, this argument determines whether
|
|
6519
|
+
wildcard expressions match hidden data streams. It supports comma-separated
|
|
6520
|
+
values, such as `open,hidden`. Valid values are: `all`, `open`, `closed`,
|
|
6521
|
+
`hidden`, `none`.
|
|
6522
|
+
:param from_: Skips the specified number of documents.
|
|
5252
6523
|
:param ignore_unavailable: If `false`, the request returns an error if it targets
|
|
5253
6524
|
a missing or closed index.
|
|
5254
6525
|
:param lenient: If `true`, format-based query failures (such as providing text
|
|
5255
|
-
to a numeric field) in the query string will be ignored.
|
|
6526
|
+
to a numeric field) in the query string will be ignored. This parameter can
|
|
6527
|
+
be used only when the `q` query string parameter is specified.
|
|
5256
6528
|
:param max_docs: The maximum number of documents to update.
|
|
5257
|
-
:param pipeline: ID of the pipeline to use to preprocess incoming documents.
|
|
6529
|
+
:param pipeline: The ID of the pipeline to use to preprocess incoming documents.
|
|
5258
6530
|
If the index has a default ingest pipeline specified, then setting the value
|
|
5259
6531
|
to `_none` disables the default ingest pipeline for this request. If a final
|
|
5260
6532
|
pipeline is configured it will always run, regardless of the value of this
|
|
5261
6533
|
parameter.
|
|
5262
|
-
:param preference:
|
|
5263
|
-
|
|
5264
|
-
:param q:
|
|
5265
|
-
:param query:
|
|
6534
|
+
:param preference: The node or shard the operation should be performed on. It
|
|
6535
|
+
is random by default.
|
|
6536
|
+
:param q: A query in the Lucene query string syntax.
|
|
6537
|
+
:param query: The documents to update using the Query DSL.
|
|
5266
6538
|
:param refresh: If `true`, Elasticsearch refreshes affected shards to make the
|
|
5267
|
-
operation visible to search.
|
|
6539
|
+
operation visible to search after the request completes. This is different
|
|
6540
|
+
than the update API's `refresh` parameter, which causes just the shard that
|
|
6541
|
+
received the request to be refreshed.
|
|
5268
6542
|
:param request_cache: If `true`, the request cache is used for this request.
|
|
6543
|
+
It defaults to the index-level setting.
|
|
5269
6544
|
:param requests_per_second: The throttle for this request in sub-requests per
|
|
5270
6545
|
second.
|
|
5271
|
-
:param routing:
|
|
6546
|
+
:param routing: A custom value used to route operations to a specific shard.
|
|
5272
6547
|
:param script: The script to run to update the document source or metadata when
|
|
5273
6548
|
updating.
|
|
5274
|
-
:param scroll:
|
|
5275
|
-
:param scroll_size:
|
|
5276
|
-
:param search_timeout:
|
|
5277
|
-
|
|
5278
|
-
|
|
6549
|
+
:param scroll: The period to retain the search context for scrolling.
|
|
6550
|
+
:param scroll_size: The size of the scroll request that powers the operation.
|
|
6551
|
+
:param search_timeout: An explicit timeout for each search request. By default,
|
|
6552
|
+
there is no timeout.
|
|
6553
|
+
:param search_type: The type of the search operation. Available options include
|
|
6554
|
+
`query_then_fetch` and `dfs_query_then_fetch`.
|
|
5279
6555
|
:param slice: Slice the request manually using the provided slice ID and total
|
|
5280
6556
|
number of slices.
|
|
5281
6557
|
:param slices: The number of slices this task should be divided into.
|
|
5282
6558
|
:param sort: A comma-separated list of <field>:<direction> pairs.
|
|
5283
|
-
:param stats:
|
|
5284
|
-
:param terminate_after:
|
|
6559
|
+
:param stats: The specific `tag` of the request for logging and statistical purposes.
|
|
6560
|
+
:param terminate_after: The maximum number of documents to collect for each shard.
|
|
5285
6561
|
If a query reaches this limit, Elasticsearch terminates the query early.
|
|
5286
|
-
Elasticsearch collects documents before sorting. Use with caution.
|
|
5287
|
-
applies this parameter to each shard handling the request.
|
|
5288
|
-
let Elasticsearch perform early termination automatically.
|
|
5289
|
-
this parameter for requests that target data streams with
|
|
5290
|
-
across multiple data tiers.
|
|
5291
|
-
:param timeout:
|
|
5292
|
-
dynamic mapping updates, waiting for active shards.
|
|
6562
|
+
Elasticsearch collects documents before sorting. IMPORTANT: Use with caution.
|
|
6563
|
+
Elasticsearch applies this parameter to each shard handling the request.
|
|
6564
|
+
When possible, let Elasticsearch perform early termination automatically.
|
|
6565
|
+
Avoid specifying this parameter for requests that target data streams with
|
|
6566
|
+
backing indices across multiple data tiers.
|
|
6567
|
+
:param timeout: The period each update request waits for the following operations:
|
|
6568
|
+
dynamic mapping updates, waiting for active shards. By default, it is one
|
|
6569
|
+
minute. This guarantees Elasticsearch waits for at least the timeout before
|
|
6570
|
+
failing. The actual wait time could be longer, particularly when multiple
|
|
6571
|
+
waits occur.
|
|
5293
6572
|
:param version: If `true`, returns the document version as part of a hit.
|
|
5294
6573
|
:param version_type: Should the document increment the version number (internal)
|
|
5295
6574
|
on hit or not (reindex)
|
|
5296
6575
|
:param wait_for_active_shards: The number of shard copies that must be active
|
|
5297
6576
|
before proceeding with the operation. Set to `all` or any positive integer
|
|
5298
|
-
up to the total number of shards in the index (`number_of_replicas+1`).
|
|
6577
|
+
up to the total number of shards in the index (`number_of_replicas+1`). The
|
|
6578
|
+
`timeout` parameter controls how long each write request waits for unavailable
|
|
6579
|
+
shards to become available. Both work exactly the way they work in the bulk
|
|
6580
|
+
API.
|
|
5299
6581
|
:param wait_for_completion: If `true`, the request blocks until the operation
|
|
5300
|
-
is complete.
|
|
6582
|
+
is complete. If `false`, Elasticsearch performs some preflight checks, launches
|
|
6583
|
+
the request, and returns a task ID that you can use to cancel or get the
|
|
6584
|
+
status of the task. Elasticsearch creates a record of this task as a document
|
|
6585
|
+
at `.tasks/task/${taskId}`.
|
|
5301
6586
|
"""
|
|
5302
6587
|
if index in SKIP_IN_PATH:
|
|
5303
6588
|
raise ValueError("Empty value passed for parameter 'index'")
|
|
@@ -5420,16 +6705,18 @@ class Elasticsearch(BaseClient):
|
|
|
5420
6705
|
requests_per_second: t.Optional[float] = None,
|
|
5421
6706
|
) -> ObjectApiResponse[t.Any]:
|
|
5422
6707
|
"""
|
|
5423
|
-
|
|
5424
|
-
for a particular update by query operation. Rethrottling that speeds up the query
|
|
5425
|
-
takes effect immediately but rethrotting that slows down the query takes effect
|
|
5426
|
-
after completing the current batch to prevent scroll timeouts.
|
|
6708
|
+
.. raw:: html
|
|
5427
6709
|
|
|
5428
|
-
|
|
6710
|
+
<p>Throttle an update by query operation.</p>
|
|
6711
|
+
<p>Change the number of requests per second for a particular update by query operation.
|
|
6712
|
+
Rethrottling that speeds up the query takes effect immediately but rethrotting that slows down the query takes effect after completing the current batch to prevent scroll timeouts.</p>
|
|
6713
|
+
|
|
6714
|
+
|
|
6715
|
+
`<https://www.elastic.co/guide/en/elasticsearch/reference/8.18/docs-update-by-query.html#docs-update-by-query-rethrottle>`_
|
|
5429
6716
|
|
|
5430
6717
|
:param task_id: The ID for the task.
|
|
5431
6718
|
:param requests_per_second: The throttle for this request in sub-requests per
|
|
5432
|
-
second.
|
|
6719
|
+
second. To turn off throttling, set it to `-1`.
|
|
5433
6720
|
"""
|
|
5434
6721
|
if task_id in SKIP_IN_PATH:
|
|
5435
6722
|
raise ValueError("Empty value passed for parameter 'task_id'")
|