Skip to content

Commit ade0b13

Browse files
authored
Deprecate 'doc_type' for query parameters
1 parent 28a82a0 commit ade0b13

File tree

12 files changed

+117
-26
lines changed

12 files changed

+117
-26
lines changed

elasticsearch/_async/client/license.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ async def post_start_basic(self, params=None, headers=None):
9797
"POST", "/_license/start_basic", params=params, headers=headers
9898
)
9999

100-
@query_params("acknowledge", "doc_type")
100+
@query_params("acknowledge", "type")
101101
async def post_start_trial(self, params=None, headers=None):
102102
"""
103103
starts a limited time trial license.
@@ -106,12 +106,9 @@ async def post_start_trial(self, params=None, headers=None):
106106
107107
:arg acknowledge: whether the user has acknowledged acknowledge
108108
messages (default: false)
109-
:arg doc_type: The type of trial license to generate (default:
109+
:arg type: The type of trial license to generate (default:
110110
"trial")
111111
"""
112-
if "doc_type" in params:
113-
params["type"] = params.pop("doc_type")
114-
115112
return await self.transport.perform_request(
116113
"POST", "/_license/start_trial", params=params, headers=headers
117114
)

elasticsearch/_async/client/license.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ class LicenseClient(NamespacedClient):
134134
self,
135135
*,
136136
acknowledge: Optional[bool] = ...,
137-
doc_type: Optional[Any] = ...,
137+
type: Optional[Any] = ...,
138138
pretty: Optional[bool] = ...,
139139
human: Optional[bool] = ...,
140140
error_trace: Optional[bool] = ...,

elasticsearch/_async/client/nodes.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ async def stats(
124124
)
125125

126126
@query_params(
127-
"doc_type", "ignore_idle_threads", "interval", "snapshots", "threads", "timeout"
127+
"ignore_idle_threads", "interval", "snapshots", "threads", "timeout", "type"
128128
)
129129
async def hot_threads(self, node_id=None, params=None, headers=None):
130130
"""
@@ -136,8 +136,6 @@ async def hot_threads(self, node_id=None, params=None, headers=None):
136136
limit the returned information; use `_local` to return information from
137137
the node you're connecting to, leave empty to get information from all
138138
nodes
139-
:arg doc_type: The type to sample (default: cpu) Valid choices:
140-
cpu, wait, block
141139
:arg ignore_idle_threads: Don't show threads that are in known-
142140
idle places, such as waiting on a socket select or pulling from an empty
143141
task queue (default: true)
@@ -147,10 +145,9 @@ async def hot_threads(self, node_id=None, params=None, headers=None):
147145
:arg threads: Specify the number of threads to provide
148146
information for (default: 3)
149147
:arg timeout: Explicit operation timeout
148+
:arg type: The type to sample (default: cpu) Valid choices:
149+
cpu, wait, block
150150
"""
151-
if "doc_type" in params:
152-
params["type"] = params.pop("doc_type")
153-
154151
return await self.transport.perform_request(
155152
"GET",
156153
_make_path("_nodes", node_id, "hot_threads"),

elasticsearch/_async/client/nodes.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,12 @@ class NodesClient(NamespacedClient):
100100
self,
101101
*,
102102
node_id: Optional[Any] = ...,
103-
doc_type: Optional[Any] = ...,
104103
ignore_idle_threads: Optional[bool] = ...,
105104
interval: Optional[Any] = ...,
106105
snapshots: Optional[Any] = ...,
107106
threads: Optional[Any] = ...,
108107
timeout: Optional[Any] = ...,
108+
type: Optional[Any] = ...,
109109
pretty: Optional[bool] = ...,
110110
human: Optional[bool] = ...,
111111
error_trace: Optional[bool] = ...,

elasticsearch/client/license.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def post_start_basic(self, params=None, headers=None):
9797
"POST", "/_license/start_basic", params=params, headers=headers
9898
)
9999

100-
@query_params("acknowledge", "doc_type")
100+
@query_params("acknowledge", "type")
101101
def post_start_trial(self, params=None, headers=None):
102102
"""
103103
starts a limited time trial license.
@@ -106,12 +106,9 @@ def post_start_trial(self, params=None, headers=None):
106106
107107
:arg acknowledge: whether the user has acknowledged acknowledge
108108
messages (default: false)
109-
:arg doc_type: The type of trial license to generate (default:
109+
:arg type: The type of trial license to generate (default:
110110
"trial")
111111
"""
112-
if "doc_type" in params:
113-
params["type"] = params.pop("doc_type")
114-
115112
return self.transport.perform_request(
116113
"POST", "/_license/start_trial", params=params, headers=headers
117114
)

elasticsearch/client/license.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ class LicenseClient(NamespacedClient):
134134
self,
135135
*,
136136
acknowledge: Optional[bool] = ...,
137-
doc_type: Optional[Any] = ...,
137+
type: Optional[Any] = ...,
138138
pretty: Optional[bool] = ...,
139139
human: Optional[bool] = ...,
140140
error_trace: Optional[bool] = ...,

elasticsearch/client/nodes.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ def stats(
124124
)
125125

126126
@query_params(
127-
"doc_type", "ignore_idle_threads", "interval", "snapshots", "threads", "timeout"
127+
"ignore_idle_threads", "interval", "snapshots", "threads", "timeout", "type"
128128
)
129129
def hot_threads(self, node_id=None, params=None, headers=None):
130130
"""
@@ -136,8 +136,6 @@ def hot_threads(self, node_id=None, params=None, headers=None):
136136
limit the returned information; use `_local` to return information from
137137
the node you're connecting to, leave empty to get information from all
138138
nodes
139-
:arg doc_type: The type to sample (default: cpu) Valid choices:
140-
cpu, wait, block
141139
:arg ignore_idle_threads: Don't show threads that are in known-
142140
idle places, such as waiting on a socket select or pulling from an empty
143141
task queue (default: true)
@@ -147,10 +145,9 @@ def hot_threads(self, node_id=None, params=None, headers=None):
147145
:arg threads: Specify the number of threads to provide
148146
information for (default: 3)
149147
:arg timeout: Explicit operation timeout
148+
:arg type: The type to sample (default: cpu) Valid choices:
149+
cpu, wait, block
150150
"""
151-
if "doc_type" in params:
152-
params["type"] = params.pop("doc_type")
153-
154151
return self.transport.perform_request(
155152
"GET",
156153
_make_path("_nodes", node_id, "hot_threads"),

elasticsearch/client/nodes.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,12 @@ class NodesClient(NamespacedClient):
100100
self,
101101
*,
102102
node_id: Optional[Any] = ...,
103-
doc_type: Optional[Any] = ...,
104103
ignore_idle_threads: Optional[bool] = ...,
105104
interval: Optional[Any] = ...,
106105
snapshots: Optional[Any] = ...,
107106
threads: Optional[Any] = ...,
108107
timeout: Optional[Any] = ...,
108+
type: Optional[Any] = ...,
109109
pretty: Optional[bool] = ...,
110110
human: Optional[bool] = ...,
111111
error_trace: Optional[bool] = ...,

elasticsearch/client/utils.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ def query_params(*es_query_params, **kwargs):
133133
body_only_params = set(body_params or ()) - set(es_query_params)
134134
body_name = kwargs.pop("body_name", None)
135135
body_required = kwargs.pop("body_required", False)
136+
type_possible_in_params = "type" in es_query_params
136137

137138
# There should be no APIs defined with both 'body_params' and a named body.
138139
assert not (body_name and body_params)
@@ -163,6 +164,27 @@ def _wrapped(*args, **kwargs):
163164
using_body_kwarg = kwargs.get("body", None) is not None
164165
using_positional_args = args and len(args) > 1
165166

167+
# The 'doc_type' parameter is deprecated in the query
168+
# string. This was generated and missed in 7.x so to
169+
# push users to use 'type' instead of 'doc_type' in 8.x
170+
# we deprecate it here.
171+
if type_possible_in_params:
172+
doc_type_in_params = params and "doc_type" in params
173+
doc_type_in_kwargs = "doc_type" in kwargs
174+
175+
if doc_type_in_params or doc_type_in_kwargs:
176+
warnings.warn(
177+
"The 'doc_type' parameter is deprecated, use 'type' for this "
178+
"API instead. See https://github.com/elastic/elasticsearch-py/"
179+
"issues/1698 for more information",
180+
category=DeprecationWarning,
181+
stacklevel=2,
182+
)
183+
if doc_type_in_params:
184+
params["type"] = params.pop("doc_type")
185+
if doc_type_in_kwargs:
186+
kwargs["type"] = kwargs.pop("doc_type")
187+
166188
if using_body_kwarg or using_positional_args:
167189
# If there are any body-only parameters then we raise a 'TypeError'
168190
# to alert the user they have to either not use a 'body' parameter

test_elasticsearch/test_async/test_server/test_rest_api_spec.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
from elasticsearch.helpers.test import _get_version
3030

3131
from ...test_server.test_rest_api_spec import (
32+
APIS_USING_TYPE_INSTEAD_OF_DOC_TYPE,
3233
APIS_WITH_BODY_FIELDS,
3334
IMPLEMENTED_FEATURES,
3435
PARAMS_RENAMES,
@@ -138,6 +139,11 @@ async def run_do(self, action):
138139
# some parameters had to be renamed to not clash with python builtins,
139140
# compensate
140141
for k in PARAMS_RENAMES:
142+
143+
# Don't do the 'doc_type' rename for APIs that actually want 'type'
144+
if k == "type" and method in APIS_USING_TYPE_INSTEAD_OF_DOC_TYPE:
145+
continue
146+
141147
if k in args:
142148
args[PARAMS_RENAMES[k]] = args.pop(k)
143149

0 commit comments

Comments
 (0)