elasticsearch bulk indexing using python
pyelasticsearch supports bulk indexing:
bulk_index(index, doc_type, docs, id_field='id', parent_field='_parent'[, other kwargs listed below])
For example,
cities = []for line in f: fields = line.rstrip().split("\t") city = { "id" : fields[0], "city" : fields[1] } cities.append(cities) if len(cities) == 1000: es.bulk_index(es_index, "city", cities, id_field="id") cities = []if len(cities) > 0: es.bulk_index(es_index, "city", cities, id_field="id")