def find_one(self, endpoint_name, req, **lookup): """Find single item. :param endpoint_name: resource name :param req: parsed request :param lookup: additional filter """ backend = self._backend(endpoint_name) item = backend.find_one(endpoint_name, req=req, **lookup) search_backend = self._lookup_backend(endpoint_name, fallback=True) if search_backend: # set the parent for the parent child in elastic search self._set_parent(endpoint_name, item, lookup) item_search = search_backend.find_one(endpoint_name, req=req, **lookup) if item is None and item_search: item = item_search logger.warn(item_msg('item is only in elastic', item)) elif item_search is None and item: logger.warn(item_msg('item is only in mongo', item)) try: logger.info(item_msg('trying to add item to elastic', item)) search_backend.insert(endpoint_name, [item]) except RequestError as e: logger.error( item_msg( 'failed to add item into elastic error={}'.format( str(e)), item)) return item
def find_one(self, endpoint_name, req, **lookup): """Find single item. :param endpoint_name: resource name :param req: parsed request :param lookup: additional filter """ backend = self._backend(endpoint_name) item = backend.find_one(endpoint_name, req=req, **lookup) search_backend = self._lookup_backend(endpoint_name, fallback=True) if search_backend: # set the parent for the parent child in elastic search self._set_parent(endpoint_name, item, lookup) item_search = search_backend.find_one(endpoint_name, req=req, **lookup) if item is None and item_search: item = item_search logger.warn(item_msg('item is only in elastic', item)) elif item_search is None and item: logger.warn(item_msg('item is only in mongo', item)) try: logger.info(item_msg('trying to add item to elastic', item)) search_backend.insert(endpoint_name, [item]) except RequestError as e: logger.error(item_msg('failed to add item into elastic error={}'.format(str(e)), item)) return item
def find_one(self, endpoint_name, req, **lookup): backend = self._backend(endpoint_name) item = backend.find_one(endpoint_name, req=req, **lookup) search_backend = self._lookup_backend(endpoint_name, fallback=True) if search_backend: item_search = search_backend.find_one(endpoint_name, req=req, **lookup) if item is None and item_search: item = item_search logger.warn(item_msg('item is only in elastic', item)) elif item_search is None and item: logger.warn(item_msg('item is only in mongo', item)) try: logger.info(item_msg('trying to add item to elastic', item)) search_backend.insert(endpoint_name, [item]) except RequestError as e: logger.error(item_msg('failed to add item into elastic error={}'.format(str(e)), item)) return item
def find_one(self, endpoint_name, req, **lookup): backend = self._backend(endpoint_name) item = backend.find_one(endpoint_name, req=req, **lookup) search_backend = self._lookup_backend(endpoint_name, fallback=True) if search_backend: item_search = search_backend.find_one(endpoint_name, req=req, **lookup) if item is None and item_search: item = item_search logger.warn(item_msg('item is only in elastic', item)) elif item_search is None and item: logger.warn(item_msg('item is only in mongo', item)) try: logger.info(item_msg('trying to add item to elastic', item)) search_backend.insert(endpoint_name, [item]) except RequestError as e: logger.error(item_msg('failed to add item into elastic error={}'.format(str(e)), item)) return item