Skip to content

Commit 11232e9

Browse files
committed
Add more body fields to indices APIs
1 parent 642d33f commit 11232e9

File tree

13 files changed

+821
-252
lines changed

13 files changed

+821
-252
lines changed

elasticsearch/_async/client/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1945,6 +1945,7 @@ async def termvectors(
19451945
"scripted_upsert",
19461946
"upsert",
19471947
],
1948+
body_required=True,
19481949
)
19491950
async def update(self, index, id, body, doc_type=None, params=None, headers=None):
19501951
"""

elasticsearch/_async/client/indices.py

Lines changed: 125 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,11 @@ async def flush(self, index=None, params=None, headers=None):
9999
)
100100

101101
@query_params(
102-
"include_type_name", "master_timeout", "timeout", "wait_for_active_shards"
102+
"include_type_name",
103+
"master_timeout",
104+
"timeout",
105+
"wait_for_active_shards",
106+
body_params=["aliases", "mappings", "settings"],
103107
)
104108
async def create(self, index, body=None, params=None, headers=None):
105109
"""
@@ -110,9 +114,14 @@ async def create(self, index, body=None, params=None, headers=None):
110114
:arg index: The name of the index
111115
:arg body: The configuration for the index (`settings` and
112116
`mappings`)
117+
:arg aliases:
113118
:arg include_type_name: Whether a type should be expected in the
114119
body of the mappings.
120+
:arg mappings: Mapping for fields in the index. If specified,
121+
this mapping can include: - Field names - Field data types - Mapping
122+
parameters
115123
:arg master_timeout: Specify timeout for connection to master
124+
:arg settings:
116125
:arg timeout: Explicit operation timeout
117126
:arg wait_for_active_shards: Set the number of active shards to
118127
wait for before the operation returns.
@@ -168,23 +177,29 @@ async def get(self, index, params=None, headers=None):
168177
169178
`<https://www.elastic.co/guide/en/elasticsearch/reference/7.x/indices-get-index.html>`_
170179
171-
:arg index: A comma-separated list of index names
180+
:arg index: Comma-separated list of data streams, indices, and
181+
index aliases used to limit the request. Wildcard expressions (*) are
182+
supported.
172183
:arg allow_no_indices: Ignore if a wildcard expression resolves
173-
to no concrete indices (default: false)
174-
:arg expand_wildcards: Whether wildcard expressions should get
175-
expanded to open or closed indices (default: open) Valid choices: open,
176-
closed, hidden, none, all Default: open
177-
:arg flat_settings: Return settings in flat format (default:
178-
false)
179-
:arg ignore_unavailable: Ignore unavailable indexes (default:
180-
false)
181-
:arg include_defaults: Whether to return all default setting for
182-
each of the indices.
183-
:arg include_type_name: Whether to add the type name to the
184-
response (default: false)
185-
:arg local: Return local information, do not retrieve the state
186-
from master node (default: false)
187-
:arg master_timeout: Specify timeout for connection to master
184+
to no concrete indices (default: false) Default: True
185+
:arg expand_wildcards: Type of index that wildcard expressions
186+
can match. If the request can target data streams, this argument
187+
determines whether wildcard expressions match hidden data streams.
188+
Supports comma-separated values, such as open,hidden. Valid choices:
189+
open, closed, hidden, none, all Default: open
190+
:arg flat_settings: If true, returns settings in flat format.
191+
:arg ignore_unavailable: If false, requests that target a
192+
missing index return an error.
193+
:arg include_defaults: If true, return all default settings in
194+
the response.
195+
:arg include_type_name: If true, a mapping type is expected in
196+
the body of mappings.
197+
:arg local: If true, the request retrieves information from the
198+
local node only. Defaults to false, which means information is retrieved
199+
from the master node.
200+
:arg master_timeout: Period to wait for a connection to the
201+
master node. If no response is received before the timeout expires, the
202+
request fails and returns an error. Default: 30s
188203
"""
189204
if index in SKIP_IN_PATH:
190205
raise ValueError("Empty value passed for a required argument 'index'.")
@@ -374,6 +389,20 @@ async def exists_type(self, index, doc_type, params=None, headers=None):
374389
"master_timeout",
375390
"timeout",
376391
"write_index_only",
392+
body_params=[
393+
"_field_names",
394+
"_meta",
395+
"_routing",
396+
"_source",
397+
"date_detection",
398+
"dynamic",
399+
"dynamic_date_formats",
400+
"dynamic_templates",
401+
"numeric_detection",
402+
"properties",
403+
"runtime",
404+
],
405+
body_required=True,
377406
)
378407
async def put_mapping(
379408
self, body, index=None, doc_type=None, params=None, headers=None
@@ -388,9 +417,26 @@ async def put_mapping(
388417
should be added to (supports wildcards); use `_all` or omit to add the
389418
mapping on all indices.
390419
:arg doc_type: The name of the document type
420+
:arg _field_names: Control whether field names are enabled for
421+
the index.
422+
:arg _meta: A mapping type can have custom meta data associated
423+
with it. These are not used at all by Elasticsearch, but can be used to
424+
store application-specific metadata.
425+
:arg _routing: Enable making a routing value required on indexed
426+
documents.
427+
:arg _source: Control whether the _source field is enabled on
428+
the index.
391429
:arg allow_no_indices: Whether to ignore if a wildcard indices
392430
expression resolves into no concrete indices. (This includes `_all`
393431
string or when no indices have been specified)
432+
:arg date_detection: Controls whether dynamic date detection is
433+
enabled.
434+
:arg dynamic: Controls whether new fields are added dynamically.
435+
:arg dynamic_date_formats: If date detection is enabled then new
436+
string fields are checked against 'dynamic_date_formats' and if the
437+
value matches then a new date field is added instead of string.
438+
:arg dynamic_templates: Specify dynamic templates for the
439+
mapping.
394440
:arg expand_wildcards: Whether to expand wildcard expression to
395441
concrete indices that are open, closed or both. Valid choices: open,
396442
closed, hidden, none, all Default: open
@@ -399,6 +445,11 @@ async def put_mapping(
399445
:arg include_type_name: Whether a type should be expected in the
400446
body of the mappings.
401447
:arg master_timeout: Specify timeout for connection to master
448+
:arg numeric_detection: Automatically map strings into numeric
449+
data types for all fields.
450+
:arg properties: Mapping for a field. For new fields, this
451+
mapping can include: - Field name - Field data type - Mapping parameters
452+
:arg runtime: Mapping of runtime fields for the index.
402453
:arg timeout: Explicit operation timeout
403454
:arg write_index_only: When true, applies mappings only to the
404455
write index of an alias or data stream
@@ -411,7 +462,7 @@ async def put_mapping(
411462

412463
return await self.transport.perform_request(
413464
"PUT",
414-
_make_path(index, doc_type, "_mapping"),
465+
_make_path(index, doc_type, "_mappings"),
415466
params=params,
416467
headers=headers,
417468
body=body,
@@ -498,7 +549,17 @@ async def get_field_mapping(
498549
headers=headers,
499550
)
500551

501-
@query_params("master_timeout", "timeout")
552+
@query_params(
553+
"master_timeout",
554+
"timeout",
555+
body_params=[
556+
"filter",
557+
"index_routing",
558+
"is_write_index",
559+
"routing",
560+
"search_routing",
561+
],
562+
)
502563
async def put_alias(self, index, name, body=None, params=None, headers=None):
503564
"""
504565
Creates or updates an alias.
@@ -511,7 +572,12 @@ async def put_alias(self, index, name, body=None, params=None, headers=None):
511572
:arg name: The name of the alias to be created or updated
512573
:arg body: The settings for the alias, such as `routing` or
513574
`filter`
575+
:arg filter:
576+
:arg index_routing:
577+
:arg is_write_index:
514578
:arg master_timeout: Specify timeout for connection to master
579+
:arg routing:
580+
:arg search_routing:
515581
:arg timeout: Explicit timestamp for the document
516582
"""
517583
for param in (index, name):
@@ -520,7 +586,7 @@ async def put_alias(self, index, name, body=None, params=None, headers=None):
520586

521587
return await self.transport.perform_request(
522588
"PUT",
523-
_make_path(index, "_alias", name),
589+
_make_path(index, "_aliases", name),
524590
params=params,
525591
headers=headers,
526592
body=body,
@@ -616,10 +682,28 @@ async def delete_alias(self, index, name, params=None, headers=None):
616682
raise ValueError("Empty value passed for a required argument.")
617683

618684
return await self.transport.perform_request(
619-
"DELETE", _make_path(index, "_alias", name), params=params, headers=headers
685+
"DELETE",
686+
_make_path(index, "_aliases", name),
687+
params=params,
688+
headers=headers,
620689
)
621690

622-
@query_params("create", "include_type_name", "master_timeout", "order")
691+
@query_params(
692+
"create",
693+
"flat_settings",
694+
"include_type_name",
695+
"master_timeout",
696+
"timeout",
697+
body_params=[
698+
"aliases",
699+
"index_patterns",
700+
"mappings",
701+
"order",
702+
"settings",
703+
"version",
704+
],
705+
body_required=True,
706+
)
623707
async def put_template(self, name, body, params=None, headers=None):
624708
"""
625709
Creates or updates an index template.
@@ -628,14 +712,26 @@ async def put_template(self, name, body, params=None, headers=None):
628712
629713
:arg name: The name of the template
630714
:arg body: The template definition
631-
:arg create: Whether the index template should only be added if
632-
new or can also replace an existing one
715+
:arg aliases: Aliases for the index.
716+
:arg create: If true, this request cannot replace or update
717+
existing index templates.
718+
:arg flat_settings:
633719
:arg include_type_name: Whether a type should be returned in the
634720
body of the mappings.
635-
:arg master_timeout: Specify timeout for connection to master
636-
:arg order: The order for this template when merging multiple
637-
matching ones (higher numbers are merged later, overriding the lower
638-
numbers)
721+
:arg index_patterns: Array of wildcard expressions used to match
722+
the names of indices during creation.
723+
:arg mappings: Mapping for fields in the index.
724+
:arg master_timeout: Period to wait for a connection to the
725+
master node. If no response is received before the timeout expires, the
726+
request fails and returns an error. Default: 30s
727+
:arg order: Order in which Elasticsearch applies this template
728+
if index matches multiple templates. Templates with lower 'order' values
729+
are merged first. Templates with higher 'order' values are merged later,
730+
overriding templates with lower values.
731+
:arg settings: Configuration options for the index.
732+
:arg timeout:
733+
:arg version: Version number used to manage index templates
734+
externally. This number is not automatically generated by Elasticsearch.
639735
"""
640736
for param in (name, body):
641737
if param in SKIP_IN_PATH:
@@ -814,9 +910,7 @@ async def stats(self, index=None, metric=None, params=None, headers=None):
814910
:arg index: A comma-separated list of index names; use `_all` or
815911
empty string to perform the operation on all indices
816912
:arg metric: Limit the information returned the specific
817-
metrics. Valid choices: _all, completion, docs, fielddata, query_cache,
818-
flush, get, indexing, merge, request_cache, refresh, search, segments,
819-
store, warmer, suggest
913+
metrics.
820914
:arg completion_fields: A comma-separated list of fields for
821915
`fielddata` and `suggest` index metric (supports wildcards)
822916
:arg expand_wildcards: Whether to expand wildcard expression to

0 commit comments

Comments
 (0)