def update_index ( index ) : logger . info ( "Updating search index: '%s'" , index ) client = get_client ( ) responses = [ ] for model in get_index_models ( index ) : logger . info ( "Updating search index model: '%s'" , model . search_doc_type ) objects = model . objects . get_search_queryset ( index ) . iterator ( ) actions = bulk_actions ( objects , index = index , action = "index" ) response = helpers . bulk ( client , actions , chunk_size = get_setting ( "chunk_size" ) ) responses . append ( response ) return responses
python helpers bulk load data elasticsearch
Re - index every document in a named index .
def update_index(index):
    """Re-index every document in a named index."""
    logger.info("Updating search index: '%s'", index)
    client = get_client()
    responses = []
    for model in get_index_models(index):
        logger.info("Updating search index model: '%s'", model.search_doc_type)
        objects = model.objects.get_search_queryset(index).iterator()
        actions = bulk_actions(objects, index=index, action="index")
        response = helpers.bulk(client, actions, chunk_size=get_setting("chunk_size"))
        responses.append(response)
    return responses