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版本的一些备注

相关文章:

  • 2021-09-28
  • 2021-10-02
  • 2021-07-01
  • 2022-01-15
  • 2021-12-09
  • 2022-12-23
  • 2022-12-23
  • 2021-08-14
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-20
  • 2021-06-09
  • 2021-09-22
  • 2021-12-02
相关资源
相似解决方案