Skip to content

Commit a359c5f

Browse files
committed
Elasticsearch 5.0 APIs
1 parent f28b634 commit a359c5f

File tree

4 files changed

+299
-8
lines changed

4 files changed

+299
-8
lines changed

elasticsearch/client/__init__.py

Lines changed: 247 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,11 @@ def index(self, index, doc_type, body, id=None, params=None):
269269
are: 'index', 'create'
270270
:arg parent: ID of the parent document
271271
:arg pipeline: The pipeline id to preprocess incoming documents with
272-
:arg refresh: Refresh the index after performing the operation
272+
:arg refresh: If `true` then refresh the effected shards to make this
273+
operation visible to search, if `wait_for` then wait for a refresh
274+
to make this operation visible to search, if `false` (the default)
275+
then do nothing with refreshes., valid choices are: 'true', 'false',
276+
'wait_for'
273277
:arg routing: Specific routing value
274278
:arg timeout: Explicit operation timeout
275279
:arg timestamp: Explicit timestamp for the document
@@ -432,7 +436,11 @@ def update(self, index, doc_type, id, body=None, params=None):
432436
:arg lang: The script language (default: groovy)
433437
:arg parent: ID of the parent document. Is is only used for routing and
434438
when for the upsert request
435-
:arg refresh: Refresh the index after performing the operation
439+
:arg refresh: If `true` then refresh the effected shards to make this
440+
operation visible to search, if `wait_for` then wait for a refresh
441+
to make this operation visible to search, if `false` (the default)
442+
then do nothing with refreshes., valid choices are: 'true', 'false',
443+
'wait_for'
436444
:arg retry_on_conflict: Specify how many times should the operation be
437445
retried when a conflict occurs (default: 0)
438446
:arg routing: Specific routing value
@@ -541,6 +549,230 @@ def search(self, index=None, doc_type=None, body=None, params=None):
541549
return self.transport.perform_request('GET', _make_path(index,
542550
doc_type, '_search'), params=params, body=body)
543551

552+
@query_params('_source', '_source_exclude', '_source_include',
553+
'allow_no_indices', 'analyze_wildcard', 'analyzer', 'conflicts',
554+
'consistency', 'default_operator', 'df', 'expand_wildcards', 'explain',
555+
'fielddata_fields', 'fields', 'from_', 'ignore_unavailable', 'lenient',
556+
'lowercase_expanded_terms', 'pipeline', 'preference', 'q', 'refresh',
557+
'request_cache', 'requests_per_second', 'routing', 'scroll',
558+
'scroll_size', 'search_timeout', 'search_type', 'size', 'sort', 'stats',
559+
'suggest_field', 'suggest_mode', 'suggest_size', 'suggest_text',
560+
'terminate_after', 'timeout', 'track_scores', 'version', 'version_type',
561+
'wait_for_completion')
562+
def update_by_query(self, index, doc_type=None, body=None, params=None):
563+
"""
564+
`<https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-update-by-query.html>`_
565+
566+
:arg index: A comma-separated list of index names to search; use `_all`
567+
or empty string to perform the operation on all indices
568+
:arg doc_type: A comma-separated list of document types to search; leave
569+
empty to perform the operation on all types
570+
:arg body: The search definition using the Query DSL
571+
:arg _source: True or false to return the _source field or not, or a
572+
list of fields to return
573+
:arg _source_exclude: A list of fields to exclude from the returned
574+
_source field
575+
:arg _source_include: A list of fields to extract and return from the
576+
_source field
577+
:arg allow_no_indices: Whether to ignore if a wildcard indices
578+
expression resolves into no concrete indices. (This includes `_all`
579+
string or when no indices have been specified)
580+
:arg analyze_wildcard: Specify whether wildcard and prefix queries
581+
should be analyzed (default: false)
582+
:arg analyzer: The analyzer to use for the query string
583+
:arg conflicts: What to do when the reindex hits version conflicts?,
584+
default 'abort', valid choices are: 'abort', 'proceed'
585+
:arg consistency: Explicit write consistency setting for the operation,
586+
valid choices are: 'one', 'quorum', 'all'
587+
:arg default_operator: The default operator for query string query (AND
588+
or OR), default 'OR', valid choices are: 'AND', 'OR'
589+
:arg df: The field to use as default where no field prefix is given in
590+
the query string
591+
:arg expand_wildcards: Whether to expand wildcard expression to concrete
592+
indices that are open, closed or both., default 'open', valid
593+
choices are: 'open', 'closed', 'none', 'all'
594+
:arg explain: Specify whether to return detailed information about score
595+
computation as part of a hit
596+
:arg fielddata_fields: A comma-separated list of fields to return as the
597+
field data representation of a field for each hit
598+
:arg fields: A comma-separated list of fields to return as part of a hit
599+
:arg from_: Starting offset (default: 0)
600+
:arg ignore_unavailable: Whether specified concrete indices should be
601+
ignored when unavailable (missing or closed)
602+
:arg lenient: Specify whether format-based query failures (such as
603+
providing text to a numeric field) should be ignored
604+
:arg lowercase_expanded_terms: Specify whether query terms should be
605+
lowercased
606+
:arg pipeline: Ingest pipeline to set on index requests made by this
607+
action. (default: none)
608+
:arg preference: Specify the node or shard the operation should be
609+
performed on (default: random)
610+
:arg q: Query in the Lucene query string syntax
611+
:arg refresh: Should the effected indexes be refreshed?
612+
:arg request_cache: Specify if request cache should be used for this
613+
request or not, defaults to index level setting
614+
:arg requests_per_second: The throttle for this request in sub-requests
615+
per second. 0 means set no throttle., default 0
616+
:arg routing: A comma-separated list of specific routing values
617+
:arg scroll: Specify how long a consistent view of the index should be
618+
maintained for scrolled search
619+
:arg scroll_size: Size on the scroll request powering the
620+
update_by_query
621+
:arg search_timeout: Explicit timeout for each search request. Defaults
622+
to no timeout.
623+
:arg search_type: Search operation type, valid choices are:
624+
'query_then_fetch', 'dfs_query_then_fetch'
625+
:arg size: Number of hits to return (default: 10)
626+
:arg sort: A comma-separated list of <field>:<direction> pairs
627+
:arg stats: Specific 'tag' of the request for logging and statistical
628+
purposes
629+
:arg suggest_field: Specify which field to use for suggestions
630+
:arg suggest_mode: Specify suggest mode, default 'missing', valid
631+
choices are: 'missing', 'popular', 'always'
632+
:arg suggest_size: How many suggestions to return in response
633+
:arg suggest_text: The source text for which the suggestions should be
634+
returned
635+
:arg terminate_after: The maximum number of documents to collect for
636+
each shard, upon reaching which the query execution will terminate
637+
early.
638+
:arg timeout: Time each individual bulk request should wait for shards
639+
that are unavailable., default '1m'
640+
:arg track_scores: Whether to calculate and return scores even if they
641+
are not used for sorting
642+
:arg version: Specify whether to return document version as part of a
643+
hit
644+
:arg version_type: Should the document increment the version number
645+
(internal) on hit or not (reindex)
646+
:arg wait_for_completion: Should the request should block until the
647+
reindex is complete., default False
648+
"""
649+
if index in SKIP_IN_PATH:
650+
raise ValueError("Empty value passed for a required argument 'index'.")
651+
return self.transport.perform_request('POST', _make_path(index,
652+
doc_type, '_update_by_query'), params=params, body=body)
653+
654+
@query_params('consistency', 'refresh', 'requests_per_second', 'timeout',
655+
'wait_for_completion')
656+
def reindex(self, body, params=None):
657+
"""
658+
`<https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-reindex.html>`_
659+
660+
:arg body: The search definition using the Query DSL and the prototype
661+
for the index request.
662+
:arg consistency: Explicit write consistency setting for the operation,
663+
valid choices are: 'one', 'quorum', 'all'
664+
:arg refresh: Should the effected indexes be refreshed?
665+
:arg requests_per_second: The throttle for this request in sub-requests
666+
per second. 0 means set no throttle., default 0
667+
:arg timeout: Time each individual bulk request should wait for shards
668+
that are unavailable., default '1m'
669+
:arg wait_for_completion: Should the request should block until the
670+
reindex is complete., default False
671+
"""
672+
if body in SKIP_IN_PATH:
673+
raise ValueError("Empty value passed for a required argument 'body'.")
674+
return self.transport.perform_request('POST', '/_reindex',
675+
params=params, body=body)
676+
677+
@query_params('_source', '_source_exclude', '_source_include',
678+
'allow_no_indices', 'analyze_wildcard', 'analyzer', 'conflicts',
679+
'consistency', 'default_operator', 'df', 'expand_wildcards', 'explain',
680+
'fielddata_fields', 'fields', 'from_', 'ignore_unavailable', 'lenient',
681+
'lowercase_expanded_terms', 'preference', 'q', 'refresh',
682+
'request_cache', 'requests_per_second', 'routing', 'scroll',
683+
'scroll_size', 'search_timeout', 'search_type', 'size', 'sort', 'stats',
684+
'suggest_field', 'suggest_mode', 'suggest_size', 'suggest_text',
685+
'terminate_after', 'timeout', 'track_scores', 'version',
686+
'wait_for_completion')
687+
def delete_by_query(self, index, body, doc_type=None, params=None):
688+
"""
689+
`<https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-delete-by-query.html>`_
690+
691+
:arg index: A comma-separated list of index names to search; use `_all`
692+
or empty string to perform the operation on all indices
693+
:arg body: The search definition using the Query DSL
694+
:arg doc_type: A comma-separated list of document types to search; leave
695+
empty to perform the operation on all types
696+
:arg _source: True or false to return the _source field or not, or a
697+
list of fields to return
698+
:arg _source_exclude: A list of fields to exclude from the returned
699+
_source field
700+
:arg _source_include: A list of fields to extract and return from the
701+
_source field
702+
:arg allow_no_indices: Whether to ignore if a wildcard indices
703+
expression resolves into no concrete indices. (This includes `_all`
704+
string or when no indices have been specified)
705+
:arg analyze_wildcard: Specify whether wildcard and prefix queries
706+
should be analyzed (default: false)
707+
:arg analyzer: The analyzer to use for the query string
708+
:arg conflicts: What to do when the delete-by-query hits version
709+
conflicts?, default 'abort', valid choices are: 'abort', 'proceed'
710+
:arg consistency: Explicit write consistency setting for the operation,
711+
valid choices are: 'one', 'quorum', 'all'
712+
:arg default_operator: The default operator for query string query (AND
713+
or OR), default 'OR', valid choices are: 'AND', 'OR'
714+
:arg df: The field to use as default where no field prefix is given in
715+
the query string
716+
:arg expand_wildcards: Whether to expand wildcard expression to concrete
717+
indices that are open, closed or both., default 'open', valid
718+
choices are: 'open', 'closed', 'none', 'all'
719+
:arg explain: Specify whether to return detailed information about score
720+
computation as part of a hit
721+
:arg fielddata_fields: A comma-separated list of fields to return as the
722+
field data representation of a field for each hit
723+
:arg fields: A comma-separated list of fields to return as part of a hit
724+
:arg from_: Starting offset (default: 0)
725+
:arg ignore_unavailable: Whether specified concrete indices should be
726+
ignored when unavailable (missing or closed)
727+
:arg lenient: Specify whether format-based query failures (such as
728+
providing text to a numeric field) should be ignored
729+
:arg lowercase_expanded_terms: Specify whether query terms should be
730+
lowercased
731+
:arg preference: Specify the node or shard the operation should be
732+
performed on (default: random)
733+
:arg q: Query in the Lucene query string syntax
734+
:arg refresh: Should the effected indexes be refreshed?
735+
:arg request_cache: Specify if request cache should be used for this
736+
request or not, defaults to index level setting
737+
:arg requests_per_second: The throttle for this request in sub-requests
738+
per second. 0 means set no throttle., default 0
739+
:arg routing: A comma-separated list of specific routing values
740+
:arg scroll: Specify how long a consistent view of the index should be
741+
maintained for scrolled search
742+
:arg scroll_size: Size on the scroll request powering the
743+
update_by_query
744+
:arg search_timeout: Explicit timeout for each search request. Defaults
745+
to no timeout.
746+
:arg search_type: Search operation type, valid choices are:
747+
'query_then_fetch', 'dfs_query_then_fetch'
748+
:arg size: Number of hits to return (default: 10)
749+
:arg sort: A comma-separated list of <field>:<direction> pairs
750+
:arg stats: Specific 'tag' of the request for logging and statistical
751+
purposes
752+
:arg suggest_field: Specify which field to use for suggestions
753+
:arg suggest_mode: Specify suggest mode, default 'missing', valid
754+
choices are: 'missing', 'popular', 'always'
755+
:arg suggest_size: How many suggestions to return in response
756+
:arg suggest_text: The source text for which the suggestions should be
757+
returned
758+
:arg terminate_after: The maximum number of documents to collect for
759+
each shard, upon reaching which the query execution will terminate
760+
early.
761+
:arg timeout: Time each individual bulk request should wait for shards
762+
that are unavailable., default '1m'
763+
:arg track_scores: Whether to calculate and return scores even if they
764+
are not used for sorting
765+
:arg version: Specify whether to return document version as part of a
766+
hit
767+
:arg wait_for_completion: Should the request should block until the
768+
delete-by-query is complete., default False
769+
"""
770+
for param in (index, body):
771+
if param in SKIP_IN_PATH:
772+
raise ValueError("Empty value passed for a required argument.")
773+
return self.transport.perform_request('POST', _make_path(index,
774+
doc_type, '_delete_by_query'), params=params, body=body)
775+
544776
@query_params('allow_no_indices', 'expand_wildcards', 'ignore_unavailable',
545777
'local', 'preference', 'routing')
546778
def search_shards(self, index=None, doc_type=None, params=None):
@@ -703,7 +935,11 @@ def delete(self, index, doc_type, id, params=None):
703935
:arg consistency: Specific write consistency setting for the operation,
704936
valid choices are: 'one', 'quorum', 'all'
705937
:arg parent: ID of parent document
706-
:arg refresh: Refresh the index after performing the operation
938+
:arg refresh: If `true` then refresh the effected shards to make this
939+
operation visible to search, if `wait_for` then wait for a refresh
940+
to make this operation visible to search, if `false` (the default)
941+
then do nothing with refreshes., valid choices are: 'true', 'false',
942+
'wait_for'
707943
:arg routing: Specific routing value
708944
:arg timeout: Explicit operation timeout
709945
:arg version: Explicit version number for concurrency control
@@ -780,7 +1016,11 @@ def bulk(self, body, index=None, doc_type=None, params=None):
7801016
:arg fields: Default comma-separated list of fields to return in the
7811017
response for updates
7821018
:arg pipeline: The pipeline id to preprocess incoming documents with
783-
:arg refresh: Refresh the index after performing the operation
1019+
:arg refresh: If `true` then refresh the effected shards to make this
1020+
operation visible to search, if `wait_for` then wait for a refresh
1021+
to make this operation visible to search, if `false` (the default)
1022+
then do nothing with refreshes., valid choices are: 'true', 'false',
1023+
'wait_for'
7841024
:arg routing: Specific routing value
7851025
:arg timeout: Explicit operation timeout
7861026
"""
@@ -789,7 +1029,7 @@ def bulk(self, body, index=None, doc_type=None, params=None):
7891029
return self.transport.perform_request('POST', _make_path(index,
7901030
doc_type, '_bulk'), params=params, body=self._bulk_body(body))
7911031

792-
@query_params('search_type')
1032+
@query_params('max_concurrent_searches', 'search_type')
7931033
def msearch(self, body, index=None, doc_type=None, params=None):
7941034
"""
7951035
Execute several search requests within the same API.
@@ -800,6 +1040,8 @@ def msearch(self, body, index=None, doc_type=None, params=None):
8001040
:arg index: A comma-separated list of index names to use as default
8011041
:arg doc_type: A comma-separated list of document types to use as
8021042
default
1043+
:arg max_concurrent_searches: Controls the maximum number of concurrent
1044+
searches the multi search api will execute
8031045
:arg search_type: Search operation type, valid choices are:
8041046
'query_then_fetch', 'query_and_fetch', 'dfs_query_then_fetch',
8051047
'dfs_query_and_fetch'

elasticsearch/client/cluster.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ def stats(self, node_id=None, params=None):
9494
url = _make_path('_cluster/stats/nodes', node_id)
9595
return self.transport.perform_request('GET', url, params=params)
9696

97-
@query_params('dry_run', 'explain', 'master_timeout', 'metric', 'timeout')
97+
@query_params('dry_run', 'explain', 'master_timeout', 'metric',
98+
'retry_failed', 'timeout')
9899
def reroute(self, body=None, params=None):
99100
"""
100101
Explicitly execute a cluster reroute allocation command including specific commands.
@@ -110,6 +111,8 @@ def reroute(self, body=None, params=None):
110111
:arg metric: Limit the information returned to the specified metrics.
111112
Defaults to all but metadata, valid choices are: '_all', 'blocks',
112113
'metadata', 'nodes', 'routing_table', 'master_node', 'version'
114+
:arg retry_failed: Retries allocation of shards that are blocked due to
115+
too many subsequent allocation failures
113116
:arg timeout: Explicit operation timeout
114117
"""
115118
return self.transport.perform_request('POST', '/_cluster/reroute',

0 commit comments

Comments
 (0)