ES 5.* 版本常用操作
常用操作
1 新增字段 ( index/type/_mapping) , 里面用 properties设置
PUT idx-t-hr-iteminfo/es_t_hr_iteminfo/_mapping
{
"properties": {
"AREACODE":{
"type": "keyword"
},
"AREACODETWO":{
"type": "keyword"
},
"UPDATEFLAG":{
"type": "keyword"
}
}
}
2 新增一个文档 (需要把所有doc 字段全部赋值)
POST idx-t-hr-iteminfo/es_t_hr_iteminfo/VQW76871|1
{
"Id": "VQW76871|1",
"QRINFO": "VQW76871|1",
"QRSTATUS": "1100000000",
"PROJECTID": 46070
}
3 部分更新
POST idx-t-hr-iteminfo/es_t_hr_iteminfo/_update_by_query
{
"script": {
"source": "ctx._source['UPDATEFLAG'] = \"3\""
}
}
4 C# bulk 批量操作 (批量更新,支持单独几个字段的更新,只需要将需要更新的字段单独赋值即可)
BulkDescriptor descriptor = new BulkDescriptor(); foreach (var item in searchResult.Documents) { string areaCode = string.Empty; string areaCodeTwo = string.Empty; string updateFlag = "1"; es_t_hr_iteminfo es_T_Hr_Iteminfo = new es_t_hr_iteminfo() { QRINFO = item.QRINFO, UPDATEFLAG = updateFlag }; if (!string.IsNullOrWhiteSpace(areaCode)) { es_T_Hr_Iteminfo.AREACODE = areaCode; } if (!string.IsNullOrWhiteSpace(areaCodeTwo)) { es_T_Hr_Iteminfo.AREACODETWO = areaCodeTwo; } descriptor.Update<es_t_hr_iteminfo>(op => op.Id(item.QRINFO).Doc(es_T_Hr_Iteminfo).Index("idx-t-hr-iteminfo")); } Log.Information("Start bulk operaton"); var response = client.Bulk(descriptor); Log.Information("End bulk operaton");
总结
以上是 es 5版本的一些备注

浙公网安备 33010602011771号