Move HEAD handling to Transport
This commit is contained in:
@@ -3,7 +3,7 @@ import weakref
|
|||||||
import logging
|
import logging
|
||||||
|
|
||||||
from ..transport import Transport
|
from ..transport import Transport
|
||||||
from ..exceptions import NotFoundError, TransportError
|
from ..exceptions import TransportError
|
||||||
from ..compat import string_types, urlparse
|
from ..compat import string_types, urlparse
|
||||||
from .indices import IndicesClient
|
from .indices import IndicesClient
|
||||||
from .cluster import ClusterClient
|
from .cluster import ClusterClient
|
||||||
@@ -204,11 +204,7 @@ class Elasticsearch(object):
|
|||||||
Returns True if the cluster is up, False otherwise.
|
Returns True if the cluster is up, False otherwise.
|
||||||
`<http://www.elastic.co/guide/>`_
|
`<http://www.elastic.co/guide/>`_
|
||||||
"""
|
"""
|
||||||
try:
|
return self.transport.perform_request('HEAD', '/', params=params)
|
||||||
self.transport.perform_request('HEAD', '/', params=params)
|
|
||||||
except NotFoundError:
|
|
||||||
return False
|
|
||||||
return True
|
|
||||||
|
|
||||||
@query_params()
|
@query_params()
|
||||||
def info(self, params=None):
|
def info(self, params=None):
|
||||||
@@ -299,12 +295,8 @@ class Elasticsearch(object):
|
|||||||
for param in (index, doc_type, id):
|
for param in (index, doc_type, id):
|
||||||
if param in SKIP_IN_PATH:
|
if param in SKIP_IN_PATH:
|
||||||
raise ValueError("Empty value passed for a required argument.")
|
raise ValueError("Empty value passed for a required argument.")
|
||||||
try:
|
return self.transport.perform_request('HEAD', _make_path(index, doc_type,
|
||||||
self.transport.perform_request('HEAD', _make_path(index, doc_type,
|
|
||||||
id), params=params)
|
id), params=params)
|
||||||
except NotFoundError:
|
|
||||||
return False
|
|
||||||
return True
|
|
||||||
|
|
||||||
@query_params('_source', '_source_exclude', '_source_include', 'fields',
|
@query_params('_source', '_source_exclude', '_source_include', 'fields',
|
||||||
'parent', 'preference', 'realtime', 'refresh', 'routing', 'version',
|
'parent', 'preference', 'realtime', 'refresh', 'routing', 'version',
|
||||||
@@ -1158,53 +1150,6 @@ class Elasticsearch(object):
|
|||||||
return self.transport.perform_request('DELETE', _make_path('_search',
|
return self.transport.perform_request('DELETE', _make_path('_search',
|
||||||
'template', id), params=params)
|
'template', id), params=params)
|
||||||
|
|
||||||
@query_params('allow_no_indices', 'analyze_wildcard', 'analyzer',
|
|
||||||
'default_operator', 'df', 'expand_wildcards', 'ignore_unavailable',
|
|
||||||
'lenient', 'lowercase_expanded_terms', 'min_score', 'preference', 'q',
|
|
||||||
'routing')
|
|
||||||
def search_exists(self, index=None, doc_type=None, body=None, params=None):
|
|
||||||
"""
|
|
||||||
The exists API allows to easily determine if any matching documents
|
|
||||||
exist for a provided query.
|
|
||||||
`<http://www.elastic.co/guide/en/elasticsearch/reference/current/search-exists.html>`_
|
|
||||||
|
|
||||||
:arg index: A comma-separated list of indices to restrict the results
|
|
||||||
:arg doc_type: A comma-separated list of types to restrict the results
|
|
||||||
:arg body: A query to restrict the results specified with the Query DSL
|
|
||||||
(optional)
|
|
||||||
:arg allow_no_indices: Whether to ignore if a wildcard indices
|
|
||||||
expression resolves into no concrete indices. (This includes `_all`
|
|
||||||
string or when no indices have been specified)
|
|
||||||
:arg analyze_wildcard: Specify whether wildcard and prefix queries
|
|
||||||
should be analyzed (default: false)
|
|
||||||
:arg analyzer: The analyzer to use for the query string
|
|
||||||
:arg default_operator: The default operator for query string query (AND
|
|
||||||
or OR), default 'OR', valid choices are: 'AND', 'OR'
|
|
||||||
:arg df: The field to use as default where no field prefix is given in
|
|
||||||
the query string
|
|
||||||
:arg expand_wildcards: Whether to expand wildcard expression to concrete
|
|
||||||
indices that are open, closed or both., default 'open', valid
|
|
||||||
choices are: 'open', 'closed', 'none', 'all'
|
|
||||||
:arg ignore_unavailable: Whether specified concrete indices should be
|
|
||||||
ignored when unavailable (missing or closed)
|
|
||||||
:arg lenient: Specify whether format-based query failures (such as
|
|
||||||
providing text to a numeric field) should be ignored
|
|
||||||
:arg lowercase_expanded_terms: Specify whether query terms should be
|
|
||||||
lowercased
|
|
||||||
:arg min_score: Include only documents with a specific `_score` value in
|
|
||||||
the result
|
|
||||||
:arg preference: Specify the node or shard the operation should be
|
|
||||||
performed on (default: random)
|
|
||||||
:arg q: Query in the Lucene query string syntax
|
|
||||||
:arg routing: Specific routing value
|
|
||||||
"""
|
|
||||||
try:
|
|
||||||
self.transport.perform_request('POST', _make_path(index,
|
|
||||||
doc_type, '_search', 'exists'), params=params, body=body)
|
|
||||||
except NotFoundError:
|
|
||||||
return False
|
|
||||||
return True
|
|
||||||
|
|
||||||
@query_params('allow_no_indices', 'expand_wildcards', 'fields',
|
@query_params('allow_no_indices', 'expand_wildcards', 'fields',
|
||||||
'ignore_unavailable', 'level')
|
'ignore_unavailable', 'level')
|
||||||
def field_stats(self, index=None, body=None, params=None):
|
def field_stats(self, index=None, body=None, params=None):
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
from .utils import NamespacedClient, query_params, _make_path, SKIP_IN_PATH
|
from .utils import NamespacedClient, query_params, _make_path, SKIP_IN_PATH
|
||||||
from ..exceptions import NotFoundError
|
|
||||||
|
|
||||||
class IndicesClient(NamespacedClient):
|
class IndicesClient(NamespacedClient):
|
||||||
@query_params('analyzer', 'char_filters', 'field', 'filters', 'format',
|
@query_params('analyzer', 'char_filters', 'field', 'filters', 'format',
|
||||||
@@ -213,12 +212,8 @@ class IndicesClient(NamespacedClient):
|
|||||||
"""
|
"""
|
||||||
if index in SKIP_IN_PATH:
|
if index in SKIP_IN_PATH:
|
||||||
raise ValueError("Empty value passed for a required argument 'index'.")
|
raise ValueError("Empty value passed for a required argument 'index'.")
|
||||||
try:
|
return self.transport.perform_request('HEAD', _make_path(index),
|
||||||
self.transport.perform_request('HEAD', _make_path(index),
|
|
||||||
params=params)
|
params=params)
|
||||||
except NotFoundError:
|
|
||||||
return False
|
|
||||||
return True
|
|
||||||
|
|
||||||
@query_params('allow_no_indices', 'expand_wildcards', 'ignore_unavailable',
|
@query_params('allow_no_indices', 'expand_wildcards', 'ignore_unavailable',
|
||||||
'local')
|
'local')
|
||||||
@@ -244,12 +239,8 @@ class IndicesClient(NamespacedClient):
|
|||||||
for param in (index, doc_type):
|
for param in (index, doc_type):
|
||||||
if param in SKIP_IN_PATH:
|
if param in SKIP_IN_PATH:
|
||||||
raise ValueError("Empty value passed for a required argument.")
|
raise ValueError("Empty value passed for a required argument.")
|
||||||
try:
|
return self.transport.perform_request('HEAD', _make_path(index, doc_type),
|
||||||
self.transport.perform_request('HEAD', _make_path(index, doc_type),
|
|
||||||
params=params)
|
params=params)
|
||||||
except NotFoundError:
|
|
||||||
return False
|
|
||||||
return True
|
|
||||||
|
|
||||||
@query_params('allow_no_indices', 'expand_wildcards', 'ignore_unavailable',
|
@query_params('allow_no_indices', 'expand_wildcards', 'ignore_unavailable',
|
||||||
'master_timeout', 'timeout', 'update_all_types')
|
'master_timeout', 'timeout', 'update_all_types')
|
||||||
@@ -373,12 +364,8 @@ class IndicesClient(NamespacedClient):
|
|||||||
:arg local: Return local information, do not retrieve the state from
|
:arg local: Return local information, do not retrieve the state from
|
||||||
master node (default: false)
|
master node (default: false)
|
||||||
"""
|
"""
|
||||||
try:
|
return self.transport.perform_request('HEAD', _make_path(index, '_alias',
|
||||||
self.transport.perform_request('HEAD', _make_path(index, '_alias',
|
|
||||||
name), params=params)
|
name), params=params)
|
||||||
except NotFoundError:
|
|
||||||
return False
|
|
||||||
return True
|
|
||||||
|
|
||||||
@query_params('allow_no_indices', 'expand_wildcards', 'ignore_unavailable',
|
@query_params('allow_no_indices', 'expand_wildcards', 'ignore_unavailable',
|
||||||
'local')
|
'local')
|
||||||
@@ -491,12 +478,8 @@ class IndicesClient(NamespacedClient):
|
|||||||
"""
|
"""
|
||||||
if name in SKIP_IN_PATH:
|
if name in SKIP_IN_PATH:
|
||||||
raise ValueError("Empty value passed for a required argument 'name'.")
|
raise ValueError("Empty value passed for a required argument 'name'.")
|
||||||
try:
|
return self.transport.perform_request('HEAD', _make_path('_template',
|
||||||
self.transport.perform_request('HEAD', _make_path('_template',
|
|
||||||
name), params=params)
|
name), params=params)
|
||||||
except NotFoundError:
|
|
||||||
return False
|
|
||||||
return True
|
|
||||||
|
|
||||||
@query_params('flat_settings', 'local', 'master_timeout')
|
@query_params('flat_settings', 'local', 'master_timeout')
|
||||||
def get_template(self, name=None, params=None):
|
def get_template(self, name=None, params=None):
|
||||||
|
|||||||
@@ -329,6 +329,9 @@ class Transport(object):
|
|||||||
status, headers, data = connection.perform_request(method, url, params, body, ignore=ignore, timeout=timeout)
|
status, headers, data = connection.perform_request(method, url, params, body, ignore=ignore, timeout=timeout)
|
||||||
|
|
||||||
except TransportError as e:
|
except TransportError as e:
|
||||||
|
if method == 'HEAD' and e.status_code == 404:
|
||||||
|
return False
|
||||||
|
|
||||||
retry = False
|
retry = False
|
||||||
if isinstance(e, ConnectionTimeout):
|
if isinstance(e, ConnectionTimeout):
|
||||||
retry = self.retry_on_timeout
|
retry = self.retry_on_timeout
|
||||||
@@ -347,6 +350,9 @@ class Transport(object):
|
|||||||
raise
|
raise
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
if method == 'HEAD':
|
||||||
|
return 200 <= status < 300
|
||||||
|
|
||||||
# connection didn't fail, confirm it's live status
|
# connection didn't fail, confirm it's live status
|
||||||
self.connection_pool.mark_live(connection)
|
self.connection_pool.mark_live(connection)
|
||||||
if data:
|
if data:
|
||||||
|
|||||||
Reference in New Issue
Block a user