在使用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,表示寫入數據后立即刷新索引。