本文整理汇总了Python中elasticsearch.NotFoundError方法的典型用法代码示例。如果您正苦于以下问题:Python elasticsearch.NotFoundError方法的具体用法?Python elasticsearch.NotFoundError怎么用?Python elasticsearch.NotFoundError使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类elasticsearch
的用法示例。
在下文中一共展示了elasticsearch.NotFoundError方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: delete_item
# 需要导入模块: import elasticsearch [as 别名]
# 或者: from elasticsearch import NotFoundError [as 别名]
def delete_item(self, item):
# Make sure the object can be indexed
if not class_is_indexed(item.__class__):
return
# Get mapping
mapping = self.mapping_class(item.__class__)
# Delete document
try:
self.es.delete(
self.name,
mapping.get_document_type(),
mapping.get_document_id(item),
)
except NotFoundError:
pass # Document doesn't exist, ignore this exception
示例2: test_execute_single_with_http_400
# 需要导入模块: import elasticsearch [as 别名]
# 或者: from elasticsearch import NotFoundError [as 别名]
def test_execute_single_with_http_400(self):
import elasticsearch
es = None
params = None
runner = mock.Mock(side_effect=
as_future(exception=elasticsearch.NotFoundError(404, "not found", "the requested document could not be found")))
ops, unit, request_meta_data = await driver.execute_single(
self.context_managed(runner), es, params, on_error="continue-on-non-fatal")
self.assertEqual(0, ops)
self.assertEqual("ops", unit)
self.assertEqual({
"http-status": 404,
"error-type": "transport",
"error-description": "not found (the requested document could not be found)",
"success": False
}, request_meta_data)
示例3: _kibana_remove
# 需要导入模块: import elasticsearch [as 别名]
# 或者: from elasticsearch import NotFoundError [as 别名]
def _kibana_remove(self, _type, body):
i = 0
ids = []
if get_es_major_version() >= 6:
body['query']['query_string']['query'] += ' type:%s' % _type
_type = self.doc_type
while True:
res = self.client.search(index='.kibana', from_=i, doc_type=_type, body=body, request_cache=False)
if len(res['hits']['hits']) == 0:
break
i += 10
_ids = [hit['_id'] for hit in res['hits']['hits']]
ids += _ids
for _id in ids:
try:
self.client.delete(index='.kibana', doc_type=_type, id=_id, refresh=True)
except NotFoundError:
pass
示例4: _kibana_inject
# 需要导入模块: import elasticsearch [as 别名]
# 或者: from elasticsearch import NotFoundError [as 别名]
def _kibana_inject(self, _type, _file):
with open(_file) as f:
content = f.read()
name = _file.rsplit('/', 1)[1]
name = name.rsplit('.', 1)[0]
if get_es_major_version() < 6:
doc_type = _type
else:
doc_type = self.doc_type
try:
# Delete the document first, to prevent an error when it's already there
self.client.delete(index='.kibana', doc_type=doc_type, id=name, refresh=True)
except NotFoundError:
pass
try:
self.client.create(index='.kibana', doc_type=doc_type, id=name, body=content, refresh=True)
except Exception as e:
print 'While processing %s:\n' % _file
raise
示例5: delete
# 需要导入模块: import elasticsearch [as 别名]
# 或者: from elasticsearch import NotFoundError [as 别名]
def delete(obj, index=None, using=None):
"""
Shortcut to delete a Django object from the ES index based on it's model class.
"""
from django.contrib.contenttypes.models import ContentType
model_class = ContentType.objects.get_for_model(obj).model_class()
for doc_class in model_documents.get(model_class, []):
doc_using = using or doc_class._doc_type.using or 'default'
doc_index = index or doc_class._doc_type.index or getattr(settings, 'SEEKER_INDEX', 'seeker')
es = connections.get_connection(doc_using)
try:
es.delete(
index=doc_index,
doc_type=doc_class._doc_type.name,
id=doc_class.get_id(obj),
refresh=True
)
except NotFoundError:
# If this object wasn't indexed for some reason (maybe not in the document's queryset), no big deal.
pass
示例6: es_query_total
# 需要导入模块: import elasticsearch [as 别名]
# 或者: from elasticsearch import NotFoundError [as 别名]
def es_query_total(cls, cluster: Elasticsearch, index: str, group: str, **kwargs) -> 'MetricMonitor':
def fetch_stat() -> Optional[float]:
try:
response = cluster.indices.stats(index=index, groups=[group], metric='search')
except elasticsearch.NotFoundError:
# If our index doesn't exist we can't possibly allow things
# to continue. Report the metric unavailable and wait for
# the index to exist.
log.exception('Index not found while fetching index stats for %s', index)
return None
except elasticsearch.TransportError:
# Connection error to elasticsearch, could be network, restarts, etc.
log.exception('Transport error while fetching index stats for %s', index)
return None
try:
query_total = response['_all']['total']['search']['groups'][group]['query_total']
log.debug('Group %s in index %s reported query_total of %d', group, index, query_total)
return query_total
except KeyError:
# Typically this means the group hasn't collected any stats.
# This could happen after a full cluster restart but before any
# prod traffic is run through. I'm a bit wary of always
# returning 0, but it is correct.
log.info('No stats in index %s for group %s', index, group)
return 0.0
return cls(fetch_stat, StreamingEMA(), **kwargs)
示例7: complete
# 需要导入模块: import elasticsearch [as 别名]
# 或者: from elasticsearch import NotFoundError [as 别名]
def complete(self):
""" Check, if out hashed date:url id is already in the index. """
id = hashlib.sha1('%s:%s' % (self.date, self.url)).hexdigest()
es = elasticsearch.Elasticsearch()
try:
es.get(index='frontpage', doc_type='html', id=id)
except elasticsearch.NotFoundError:
return False
return True
# Wrapper tasks
# =============
示例8: _clear
# 需要导入模块: import elasticsearch [as 别名]
# 或者: from elasticsearch import NotFoundError [as 别名]
def _clear(self):
"""
We do a index deletion and creation when we clean a index.
"""
try:
self.connection.indices.delete(settings.SEARCH_INDEX)
except NotFoundError:
pass
self.connection.indices.create(settings.SEARCH_INDEX)
示例9: _refresh_template
# 需要导入模块: import elasticsearch [as 别名]
# 或者: from elasticsearch import NotFoundError [as 别名]
def _refresh_template(self, template_name="lego-search"):
context = {"index": self._index_name()}
template = render_to_string("search/elasticsearch/index_template.json", context)
try:
self.connection.indices.delete_template(template_name)
except NotFoundError:
pass
return self.connection.indices.put_template(template_name, template)
示例10: delete
# 需要导入模块: import elasticsearch [as 别名]
# 或者: from elasticsearch import NotFoundError [as 别名]
def delete(self):
try:
self.es.indices.delete(self.name)
except NotFoundError:
pass
示例11: delete_item
# 需要导入模块: import elasticsearch [as 别名]
# 或者: from elasticsearch import NotFoundError [as 别名]
def delete_item(self, item):
# Make sure the object can be indexed
if not class_is_indexed(item.__class__):
return
# Get mapping
mapping = self.mapping_class(item.__class__)
# Delete document
try:
self.es.delete(self.name, mapping.get_document_id(item))
except NotFoundError:
pass # Document doesn't exist, ignore this exception
示例12: get_es_client
# 需要导入模块: import elasticsearch [as 别名]
# 或者: from elasticsearch import NotFoundError [as 别名]
def get_es_client(self):
self._es = Elasticsearch(hosts=self.es_hosts)
self._es_version = [int(i) for i in self._es.info()["version"]["number"].split(".")]
# template
template_body = ES_TEMPLATE
if self._es_version < [7]:
template_body["mappings"] = {"_doc": template_body.pop("mappings")}
self._es.indices.put_template(ES_TEMPLATE_NAME, template_body)
# create index
for i in range(10):
existing_indices = self._es.indices.get(ES_INDEX_PATTERN).keys()
if not len(existing_indices):
next_id = 0
else:
next_id = max(int(index.rsplit("-", 1)[-1]) for index in existing_indices) + 1
index_name = ES_INDEX_PATTERN.replace("*", "{:08d}".format(next_id))
try:
self._es.indices.create(index_name)
except RequestError:
# probably race
pass
else:
# move alias
update_aliases_body = {
"actions": [
{"add": {"index": index_name, "alias": ES_ALIAS}}
]
}
try:
old_indices = self._es.indices.get_alias(ES_ALIAS)
except NotFoundError:
old_indices = []
for old_index in old_indices:
if old_index != index_name:
update_aliases_body["actions"].append(
{"remove": {"index": old_index, "alias": ES_ALIAS}}
)
self._es.indices.update_aliases(update_aliases_body)
return index_name
示例13: latest_enrichment_date
# 需要导入模块: import elasticsearch [as 别名]
# 或者: from elasticsearch import NotFoundError [as 别名]
def latest_enrichment_date(self):
"""Get the most recent enrichment date.
:return: latest date based on `metadata__enriched_on` field,
None if no values found for that field.
:raises NotFoundError: index not found in ElasticSearch
"""
latest_date = None
search = Search(using=self._es_conn, index=self._es_index)
# from:to parameters (=> from: 0, size: 0)
search = search[0:0]
search = search.aggs.metric('max_date', 'max', field='metadata__enriched_on')
try:
response = search.execute()
aggs = response.to_dict()['aggregations']
if aggs['max_date']['value'] is None:
logger.debug("{} No data for metadata__enriched_on field found in {} index".format(
self.__log_prefix, self._es_index))
else:
# Incremental case: retrieve items from last item in ES write index
max_date = aggs['max_date']['value_as_string']
latest_date = gl_dt.str_to_datetime(max_date)
except NotFoundError as nfe:
raise nfe
return latest_date
示例14: test_get_raises_404_on_index_missing
# 需要导入模块: import elasticsearch [as 别名]
# 或者: from elasticsearch import NotFoundError [as 别名]
def test_get_raises_404_on_index_missing(data_client):
with raises(NotFoundError):
Repository.get('elasticsearch-dsl-php', index='not-there')
示例15: test_get_raises_404_on_non_existent_id
# 需要导入模块: import elasticsearch [as 别名]
# 或者: from elasticsearch import NotFoundError [as 别名]
def test_get_raises_404_on_non_existent_id(data_client):
with raises(NotFoundError):
Repository.get('elasticsearch-dsl-php')