How to use Bulk API to store the keywords in ES by using Python

前端 未结 4 1807
时光说笑
时光说笑 2020-11-27 12:12

I have to store some message in ElasticSearch integrate with my python program. Now what I try to store the message is:

d={\"message\":\"this is message\"}
         


        
4条回答
  •  一生所求
    2020-11-27 12:30

    There are two options which I can think of at the moment:

    1. Define index name and document type with each entity:

    es_client = Elasticsearch()
    
    body = []
    for entry in entries:
        body.append({'index': {'_index': index, '_type': 'doc', '_id': entry['id']}})
        body.append(entry)
    
    response = es_client.bulk(body=body)
    

    2. Provide the default index and document type with the method:

    es_client = Elasticsearch()
    
    body = []
    for entry in entries:
        body.append({'index': {'_id': entry['id']}})
        body.append(entry)
    
    response = es_client.bulk(index='my_index', doc_type='doc', body=body)
    

    Works with:

    ES version:6.4.0

    ES python lib: 6.3.1

提交回复
热议问题