在使用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,表示写入数据后立即刷新索引。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读:es怎么避免写入重复数据