Exemplo n.º 1
0
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
Exemplo n.º 2
0
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.")        
Exemplo n.º 3
0
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.")        
Exemplo n.º 4
0
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.")
Exemplo n.º 5
0
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.")