[7.x] Backport overrides for typeless APIs

This commit is contained in:
Seth Michael Larson
2020-05-26 08:23:21 -05:00
committed by Seth Michael Larson
parent a3e103b00e
commit 1773bd17be
13 changed files with 408 additions and 224 deletions
+28 -36
View File
@@ -309,14 +309,12 @@ class AsyncElasticsearch(object):
raise ValueError("Empty value passed for a required argument.") raise ValueError("Empty value passed for a required argument.")
if doc_type in SKIP_IN_PATH: if doc_type in SKIP_IN_PATH:
doc_type = "_doc" path = _make_path(index, "_create", id)
else:
path = _make_path(index, doc_type, id, "_create")
return await self.transport.perform_request( return await self.transport.perform_request(
"PUT", "PUT", path, params=params, headers=headers, body=body
_make_path(index, doc_type, id, "_create"),
params=params,
headers=headers,
body=body,
) )
@query_params( @query_params(
@@ -892,14 +890,12 @@ class AsyncElasticsearch(object):
raise ValueError("Empty value passed for a required argument.") raise ValueError("Empty value passed for a required argument.")
if doc_type in SKIP_IN_PATH: if doc_type in SKIP_IN_PATH:
doc_type = "_doc" path = _make_path(index, "_explain", id)
else:
path = _make_path(index, doc_type, id, "_explain")
return await self.transport.perform_request( return await self.transport.perform_request(
"POST", "POST", path, params=params, headers=headers, body=body
_make_path(index, doc_type, id, "_explain"),
params=params,
headers=headers,
body=body,
) )
@query_params( @query_params(
@@ -1042,13 +1038,12 @@ class AsyncElasticsearch(object):
raise ValueError("Empty value passed for a required argument.") raise ValueError("Empty value passed for a required argument.")
if doc_type in SKIP_IN_PATH: if doc_type in SKIP_IN_PATH:
doc_type = "_doc" path = _make_path(index, "_source", id)
else:
path = _make_path(index, doc_type, id, "_source")
return await self.transport.perform_request( return await self.transport.perform_request(
"GET", "GET", path, params=params, headers=headers
_make_path(index, doc_type, id, "_source"),
params=params,
headers=headers,
) )
@query_params( @query_params(
@@ -1257,12 +1252,13 @@ class AsyncElasticsearch(object):
:arg version_type: Specific version type Valid choices: :arg version_type: Specific version type Valid choices:
internal, external, external_gte, force internal, external, external_gte, force
""" """
if doc_type in SKIP_IN_PATH:
path = _make_path(index, "_mtermvectors")
else:
path = _make_path(index, doc_type, "_mtermvectors")
return await self.transport.perform_request( return await self.transport.perform_request(
"POST", "POST", path, params=params, headers=headers, body=body
_make_path(index, doc_type, "_mtermvectors"),
params=params,
headers=headers,
body=body,
) )
@query_params("master_timeout", "timeout") @query_params("master_timeout", "timeout")
@@ -1579,8 +1575,8 @@ class AsyncElasticsearch(object):
:arg stored_fields: A comma-separated list of stored fields to :arg stored_fields: A comma-separated list of stored fields to
return as part of a hit return as part of a hit
:arg suggest_field: Specify which field to use for suggestions :arg suggest_field: Specify which field to use for suggestions
:arg suggest_mode: Specify suggest mode Valid choices: missing, :arg suggest_mode: Specify suggest mode Valid choices:
popular, always Default: missing missing, popular, always Default: missing
:arg suggest_size: How many suggestions to return in response :arg suggest_size: How many suggestions to return in response
:arg suggest_text: The source text for which the suggestions :arg suggest_text: The source text for which the suggestions
should be returned should be returned
@@ -1762,14 +1758,12 @@ class AsyncElasticsearch(object):
raise ValueError("Empty value passed for a required argument 'index'.") raise ValueError("Empty value passed for a required argument 'index'.")
if doc_type in SKIP_IN_PATH: if doc_type in SKIP_IN_PATH:
doc_type = "_doc" path = _make_path(index, "_termvectors", id)
else:
path = _make_path(index, doc_type, id, "_termvectors")
return await self.transport.perform_request( return await self.transport.perform_request(
"POST", "POST", path, params=params, headers=headers, body=body
_make_path(index, doc_type, id, "_termvectors"),
params=params,
headers=headers,
body=body,
) )
@query_params( @query_params(
@@ -1827,14 +1821,12 @@ class AsyncElasticsearch(object):
raise ValueError("Empty value passed for a required argument.") raise ValueError("Empty value passed for a required argument.")
if doc_type in SKIP_IN_PATH: if doc_type in SKIP_IN_PATH:
doc_type = "_doc" path = _make_path(index, "_update", id)
else:
path = _make_path(index, doc_type, id, "_update")
return await self.transport.perform_request( return await self.transport.perform_request(
"POST", "POST", path, params=params, headers=headers, body=body
_make_path(index, doc_type, id, "_update"),
params=params,
headers=headers,
body=body,
) )
@query_params( @query_params(
+28 -36
View File
@@ -309,14 +309,12 @@ class Elasticsearch(object):
raise ValueError("Empty value passed for a required argument.") raise ValueError("Empty value passed for a required argument.")
if doc_type in SKIP_IN_PATH: if doc_type in SKIP_IN_PATH:
doc_type = "_doc" path = _make_path(index, "_create", id)
else:
path = _make_path(index, doc_type, id, "_create")
return self.transport.perform_request( return self.transport.perform_request(
"PUT", "PUT", path, params=params, headers=headers, body=body
_make_path(index, doc_type, id, "_create"),
params=params,
headers=headers,
body=body,
) )
@query_params( @query_params(
@@ -884,14 +882,12 @@ class Elasticsearch(object):
raise ValueError("Empty value passed for a required argument.") raise ValueError("Empty value passed for a required argument.")
if doc_type in SKIP_IN_PATH: if doc_type in SKIP_IN_PATH:
doc_type = "_doc" path = _make_path(index, "_explain", id)
else:
path = _make_path(index, doc_type, id, "_explain")
return self.transport.perform_request( return self.transport.perform_request(
"POST", "POST", path, params=params, headers=headers, body=body
_make_path(index, doc_type, id, "_explain"),
params=params,
headers=headers,
body=body,
) )
@query_params( @query_params(
@@ -1034,13 +1030,12 @@ class Elasticsearch(object):
raise ValueError("Empty value passed for a required argument.") raise ValueError("Empty value passed for a required argument.")
if doc_type in SKIP_IN_PATH: if doc_type in SKIP_IN_PATH:
doc_type = "_doc" path = _make_path(index, "_source", id)
else:
path = _make_path(index, doc_type, id, "_source")
return self.transport.perform_request( return self.transport.perform_request(
"GET", "GET", path, params=params, headers=headers
_make_path(index, doc_type, id, "_source"),
params=params,
headers=headers,
) )
@query_params( @query_params(
@@ -1249,12 +1244,13 @@ class Elasticsearch(object):
:arg version_type: Specific version type Valid choices: :arg version_type: Specific version type Valid choices:
internal, external, external_gte, force internal, external, external_gte, force
""" """
if doc_type in SKIP_IN_PATH:
path = _make_path(index, "_mtermvectors")
else:
path = _make_path(index, doc_type, "_mtermvectors")
return self.transport.perform_request( return self.transport.perform_request(
"POST", "POST", path, params=params, headers=headers, body=body
_make_path(index, doc_type, "_mtermvectors"),
params=params,
headers=headers,
body=body,
) )
@query_params("master_timeout", "timeout") @query_params("master_timeout", "timeout")
@@ -1567,8 +1563,8 @@ class Elasticsearch(object):
:arg stored_fields: A comma-separated list of stored fields to :arg stored_fields: A comma-separated list of stored fields to
return as part of a hit return as part of a hit
:arg suggest_field: Specify which field to use for suggestions :arg suggest_field: Specify which field to use for suggestions
:arg suggest_mode: Specify suggest mode Valid choices: missing, :arg suggest_mode: Specify suggest mode Valid choices:
popular, always Default: missing missing, popular, always Default: missing
:arg suggest_size: How many suggestions to return in response :arg suggest_size: How many suggestions to return in response
:arg suggest_text: The source text for which the suggestions :arg suggest_text: The source text for which the suggestions
should be returned should be returned
@@ -1750,14 +1746,12 @@ class Elasticsearch(object):
raise ValueError("Empty value passed for a required argument 'index'.") raise ValueError("Empty value passed for a required argument 'index'.")
if doc_type in SKIP_IN_PATH: if doc_type in SKIP_IN_PATH:
doc_type = "_doc" path = _make_path(index, "_termvectors", id)
else:
path = _make_path(index, doc_type, id, "_termvectors")
return self.transport.perform_request( return self.transport.perform_request(
"POST", "POST", path, params=params, headers=headers, body=body
_make_path(index, doc_type, id, "_termvectors"),
params=params,
headers=headers,
body=body,
) )
@query_params( @query_params(
@@ -1815,14 +1809,12 @@ class Elasticsearch(object):
raise ValueError("Empty value passed for a required argument.") raise ValueError("Empty value passed for a required argument.")
if doc_type in SKIP_IN_PATH: if doc_type in SKIP_IN_PATH:
doc_type = "_doc" path = _make_path(index, "_update", id)
else:
path = _make_path(index, doc_type, id, "_update")
return self.transport.perform_request( return self.transport.perform_request(
"POST", "POST", path, params=params, headers=headers, body=body
_make_path(index, doc_type, id, "_update"),
params=params,
headers=headers,
body=body,
) )
@query_params( @query_params(
@@ -0,0 +1,141 @@
# -*- coding: utf-8 -*-
# Licensed to Elasticsearch B.V under one or more agreements.
# Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
# See the LICENSE file in the project root for more information
import pytest
from test_elasticsearch.test_cases import ElasticsearchTestCase
class TestOverriddenUrlTargets(ElasticsearchTestCase):
def test_create(self):
self.client.create(index="test-index", id="test-id", body={})
self.assert_url_called("PUT", "/test-index/_create/test-id")
self.client.create(
index="test-index", doc_type="test-type", id="test-id", body={}
)
self.assert_url_called("PUT", "/test-index/test-type/test-id/_create")
def test_delete(self):
self.client.delete(index="test-index", id="test-id")
self.assert_url_called("DELETE", "/test-index/_doc/test-id")
self.client.delete(index="test-index", doc_type="test-type", id="test-id")
self.assert_url_called("DELETE", "/test-index/test-type/test-id")
def test_exists(self):
self.client.exists(index="test-index", id="test-id")
self.assert_url_called("HEAD", "/test-index/_doc/test-id")
self.client.exists(index="test-index", doc_type="test-type", id="test-id")
self.assert_url_called("HEAD", "/test-index/test-type/test-id")
def test_explain(self):
self.client.explain(index="test-index", id="test-id")
self.assert_url_called("POST", "/test-index/_explain/test-id")
self.client.explain(index="test-index", doc_type="test-type", id="test-id")
self.assert_url_called("POST", "/test-index/test-type/test-id/_explain")
def test_get(self):
self.client.get(index="test-index", id="test-id")
self.assert_url_called("GET", "/test-index/_doc/test-id")
self.client.get(index="test-index", doc_type="test-type", id="test-id")
self.assert_url_called("GET", "/test-index/test-type/test-id")
def test_get_source(self):
self.client.get_source(index="test-index", id="test-id")
self.assert_url_called("GET", "/test-index/_source/test-id")
self.client.get_source(index="test-index", doc_type="test-type", id="test-id")
self.assert_url_called("GET", "/test-index/test-type/test-id/_source")
def test_index(self):
self.client.index(index="test-index", body={})
self.assert_url_called("POST", "/test-index/_doc")
self.client.index(index="test-index", id="test-id", body={})
self.assert_url_called("PUT", "/test-index/_doc/test-id")
self.client.index(index="test-index", doc_type="test-type", body={})
self.assert_url_called("POST", "/test-index/test-type")
self.client.index(
index="test-index", doc_type="test-type", id="test-id", body={}
)
self.assert_url_called("PUT", "/test-index/test-type/test-id")
self.client.index(index="test-index", doc_type="_doc", body={})
self.assert_url_called("POST", "/test-index/_doc", count=2)
self.client.index(index="test-index", doc_type="_doc", id="test-id", body={})
self.assert_url_called("PUT", "/test-index/_doc/test-id", count=2)
def test_termvectors(self):
self.client.termvectors(index="test-index", body={})
self.assert_url_called("POST", "/test-index/_termvectors")
self.client.termvectors(index="test-index", id="test-id", body={})
self.assert_url_called("POST", "/test-index/_termvectors/test-id")
self.client.termvectors(index="test-index", doc_type="test-type", body={})
self.assert_url_called("POST", "/test-index/test-type/_termvectors")
self.client.termvectors(
index="test-index", doc_type="test-type", id="test-id", body={}
)
self.assert_url_called("POST", "/test-index/test-type/test-id/_termvectors")
def test_mtermvectors(self):
self.client.mtermvectors(index="test-index", body={})
self.assert_url_called("POST", "/test-index/_mtermvectors")
self.client.mtermvectors(index="test-index", doc_type="test-type", body={})
self.assert_url_called("POST", "/test-index/test-type/_mtermvectors")
def test_update(self):
self.client.update(index="test-index", id="test-id", body={})
self.assert_url_called("POST", "/test-index/_update/test-id")
self.client.update(
index="test-index", doc_type="test-type", id="test-id", body={}
)
self.assert_url_called("POST", "/test-index/test-type/test-id/_update")
def test_cluster_state(self):
self.client.cluster.state()
self.assert_url_called("GET", "/_cluster/state")
self.client.cluster.state(index="test-index")
self.assert_url_called("GET", "/_cluster/state/_all/test-index")
self.client.cluster.state(index="test-index", metric="test-metric")
self.assert_url_called("GET", "/_cluster/state/test-metric/test-index")
def test_cluster_stats(self):
self.client.cluster.stats()
self.assert_url_called("GET", "/_cluster/stats")
self.client.cluster.stats(node_id="test-node")
self.assert_url_called("GET", "/_cluster/stats/nodes/test-node")
def test_indices_put_mapping(self):
self.client.indices.put_mapping(body={})
self.assert_url_called("PUT", "/_mapping")
self.client.indices.put_mapping(index="test-index", body={})
self.assert_url_called("PUT", "/test-index/_mapping")
self.client.indices.put_mapping(
index="test-index", doc_type="test-type", body={}
)
self.assert_url_called("PUT", "/test-index/test-type/_mapping")
self.client.indices.put_mapping(doc_type="test-type", body={})
self.assert_url_called("PUT", "/_all/test-type/_mapping")
def test_tasks_get(self):
with pytest.warns(DeprecationWarning):
self.client.tasks.get()
@@ -1 +0,0 @@
single_doc_op
@@ -0,0 +1,9 @@
{% extends "base" %}
{% block request %}
if doc_type in SKIP_IN_PATH:
path = _make_path(index, "_create", id)
else:
path = _make_path(index, doc_type, id, "_create")
return await self.transport.perform_request("{{ api.method }}", path, params=params, headers=headers, body=body)
{% endblock %}
@@ -1 +0,0 @@
single_doc_op
@@ -0,0 +1,7 @@
{% extends "base" %}
{% block request %}
if doc_type in SKIP_IN_PATH:
doc_type = "_doc"
{{ super()|trim }}
{% endblock %}
@@ -1 +0,0 @@
single_doc_op
@@ -0,0 +1,7 @@
{% extends "base" %}
{% block request %}
if doc_type in SKIP_IN_PATH:
doc_type = "_doc"
{{ super()|trim }}
{% endblock %}
@@ -1 +0,0 @@
single_doc_op
@@ -0,0 +1,9 @@
{% extends "base" %}
{% block request %}
if doc_type in SKIP_IN_PATH:
path = _make_path(index, "_explain", id)
else:
path = _make_path(index, doc_type, id, "_explain")
return await self.transport.perform_request("{{ api.method }}", path, params=params, headers=headers, body=body)
{% endblock %}
-1
View File
@@ -1 +0,0 @@
single_doc_op
+7
View File
@@ -0,0 +1,7 @@
{% extends "base" %}
{% block request %}
if doc_type in SKIP_IN_PATH:
doc_type = "_doc"
{{ super()|trim }}
{% endblock %}
@@ -1 +0,0 @@
single_doc_op
@@ -0,0 +1,9 @@
{% extends "base" %}
{% block request %}
if doc_type in SKIP_IN_PATH:
path = _make_path(index, "_source", id)
else:
path = _make_path(index, doc_type, id, "_source")
return await self.transport.perform_request("{{ api.method }}", path, params=params, headers=headers)
{% endblock %}
@@ -0,0 +1,9 @@
{% extends "base" %}
{% block request %}
if doc_type in SKIP_IN_PATH:
path = _make_path(index, "_mtermvectors")
else:
path = _make_path(index, doc_type, "_mtermvectors")
return await self.transport.perform_request("{{ api.method }}", path, params=params, headers=headers, body=body)
{% endblock %}
@@ -1,8 +0,0 @@
{% extends "base" %}
{% block request %}
if doc_type in SKIP_IN_PATH:
doc_type = "_doc"
{{ super()|trim }}
{% endblock %}
@@ -1 +0,0 @@
single_doc_op
@@ -0,0 +1,9 @@
{% extends "base" %}
{% block request %}
if doc_type in SKIP_IN_PATH:
path = _make_path(index, "_termvectors", id)
else:
path = _make_path(index, doc_type, id, "_termvectors")
return await self.transport.perform_request("{{ api.method }}", path, params=params, headers=headers, body=body)
{% endblock %}
@@ -1 +0,0 @@
single_doc_op
@@ -0,0 +1,9 @@
{% extends "base" %}
{% block request %}
if doc_type in SKIP_IN_PATH:
path = _make_path(index, "_update", id)
else:
path = _make_path(index, doc_type, id, "_update")
return await self.transport.perform_request("{{ api.method }}", path, params=params, headers=headers, body=body)
{% endblock %}