def create_dictionary_data_from_file(connection, index_name, doc_type, csv_file_path, update, logger, **kwargs):
"""
Indexes all entity data from the csv file at path csv_file_path
Args:
connection: Elasticsearch client object
index_name: The name of the index
doc_type: The type of the documents being indexed
csv_file_path: absolute file path of the csv file to populate entity data from
update: boolean, True if this is a update type operation, False if create/index type operation
logger: logging object to log at debug and exception level
kwargs:
Refer http://elasticsearch-py.readthedocs.io/en/master/helpers.html#elasticsearch.helpers.bulk
"""
base_file_name = os.path.basename(csv_file_path)
dictionary_key = os.path.splitext(base_file_name)[0]
if update:
delete_entity_by_name(connection=connection, index_name=index_name, doc_type=doc_type,
entity_name=dictionary_key, logger=logger, **kwargs)
dictionary_value = get_variants_dictionary_value_from_key(csv_file_path=csv_file_path,
dictionary_key=dictionary_key, logger=logger,
**kwargs)
if dictionary_value:
add_data_elastic_search(connection=connection, index_name=index_name, doc_type=doc_type,
dictionary_key=dictionary_key,
dictionary_value=remove_duplicate_data(dictionary_value), logger=logger, **kwargs)
if os.path.exists(csv_file_path) and os.path.splitext(csv_file_path)[1] == '.csv':
os.path.basename(csv_file_path)
评论列表
文章目录