indices.exists_type
This commit is contained in:
@@ -175,6 +175,22 @@ class InidicesClient(NamespacedClient):
|
||||
return False
|
||||
return True
|
||||
|
||||
@query_params('ignore_indices')
|
||||
def exists_type(self, index, doc_type, params=None):
|
||||
"""
|
||||
Used to check if a type/types exists in an index/indices (available since 0.
|
||||
http://www.elasticsearch.org/guide/reference/api/admin-indices-types-exists/
|
||||
|
||||
:arg index: A comma-separated list of index names; use `_all` to check the types across all indices
|
||||
:arg doc_type: A comma-separated list of document types to check
|
||||
:arg ignore_indices: When performed on multiple indices, allows to ignore `missing` ones, default u'none'
|
||||
"""
|
||||
try:
|
||||
self.transport.perform_request('HEAD', _make_path(index, doc_type), params=params)
|
||||
except NotFoundError:
|
||||
return False
|
||||
return True
|
||||
|
||||
@query_params('ignore_conflicts', 'timeout')
|
||||
def put_mapping(self, index, body, doc_type=None, params=None):
|
||||
"""
|
||||
|
||||
@@ -59,19 +59,27 @@ class YamlTestCase(TestCase):
|
||||
|
||||
def run_is(self, action, transform=None):
|
||||
""" Match part of last response to test data. """
|
||||
self.assertEquals(1, len(action))
|
||||
path, expected = list(action.items())[0]
|
||||
|
||||
# fetch the possibly nested value from last_response
|
||||
value = self.last_response
|
||||
for step in path.split('.'):
|
||||
if step.isdigit():
|
||||
step = int(step)
|
||||
self.assertIsInstance(value, list)
|
||||
self.assertGreater(len(value), step)
|
||||
else:
|
||||
self.assertIn(step, value)
|
||||
value = value[step]
|
||||
# matching part of the reponse dict
|
||||
if isinstance(action, dict):
|
||||
self.assertEquals(1, len(action))
|
||||
path, expected = list(action.items())[0]
|
||||
|
||||
# fetch the possibly nested value from last_response
|
||||
value = self.last_response
|
||||
for step in path.split('.'):
|
||||
if step.isdigit():
|
||||
step = int(step)
|
||||
self.assertIsInstance(value, list)
|
||||
self.assertGreater(len(value), step)
|
||||
else:
|
||||
self.assertIn(step, value)
|
||||
value = value[step]
|
||||
|
||||
# matching the entire response
|
||||
else:
|
||||
value = self.last_response
|
||||
expected = action
|
||||
|
||||
# sometimes we need to transform the json value before comparing
|
||||
if transform:
|
||||
|
||||
@@ -29,3 +29,17 @@
|
||||
indices.get_mapping:
|
||||
index: test
|
||||
- length: { test: 0 }
|
||||
---
|
||||
"Test type exists":
|
||||
- do:
|
||||
indices.exists_type:
|
||||
index: test
|
||||
type: test-type
|
||||
- is: true
|
||||
---
|
||||
"Test type doesn't exists":
|
||||
- do:
|
||||
indices.exists_type:
|
||||
index: test
|
||||
type: not-test-type
|
||||
- is: false
|
||||
|
||||
Reference in New Issue
Block a user