def _execute_query(query: Dict) -> Union[Dict, None]: """ Call search api """ with _get_es_connection() as es: results = es.search(query, INDEX_NAME) return results
def _update_document(result: Dict) -> None: """ Update thumbnail_url of document in elasticsearch """ es = _get_es_connection() for _ in range(NUMBER_OF_RETRY): try: es.update(index=INDEX_NAME, id=result["id"],body={'doc': result,'doc_as_upsert':False}) print("Successfully indexing to elasticsearch") break except Exception as e: print(e) print("Retrying indexing") else: print(f"Maximum retries reached.")
def _indexing(result: Dict) -> None: """ Index new bookmark group to elasticsearch or update if exist """ es = _get_es_connection() for _ in range(NUMBER_OF_RETRY): try: es.update(index=INDEX_NAME, id=result["id"],body={'doc': result,'doc_as_upsert':True}) print("Successfully indexing to elasticsearch") break except Exception as e: print(e) print("Retrying indexing") else: print(f"Maximum retries reached.")
def _delete_index(result: Dict) -> None: """ Delete bookmark group to elasticsearch """ es = _get_es_connection() for _ in range(NUMBER_OF_RETRY): try: es.delete(index=INDEX_NAME, id=result["id"]) print( f"Successfully deleted document id {result['id']} from elasticsearch" ) break except Exception as e: print(e) print("Retrying deleting") else: print(f"Maximum retries reached.")
def _update_tag_es(bg_id: int, result: List[Dict]) -> None: """ Update tags in elasticsearch """ es = _get_es_connection() for _ in range(NUMBER_OF_RETRY): try: es.update(index=INDEX_NAME, id=bg_id, body={ 'doc': { "tags": result }, 'doc_as_upsert': False }) print("Successfully update tags") break except Exception as e: print(e) print("Retrying update") else: print(f"Maximum retries reached.")