在使用es写入数据时,可以通过以下方式设置参数:
示例代码:
from elasticsearch import Elasticsearch # 连接ES es = Elasticsearch() # 设置参数并写入数据 index = "my_index" id = "1" body = { "field1": "value1", "field2": "value2" } routing = "1" refresh = True es.index(index=index, id=id, body=body, routing=routing, refresh=refresh) 以上示例中,设置了index参数为"my_index",id参数为"1",body参数为一个包含两个字段的JSON对象,routing参数为"1",refresh参数为True,表示写入数据后立即刷新索引。