ES 5.* 版本常用操作

2021/5/30 10:20:11

本文主要是介绍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版本的一些备注



这篇关于ES 5.* 版本常用操作的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程