NetCore 簡單操作 ElasticSearch


EasyElasticSearch 是一個操作ElasticSearch的基礎類庫

Elasticsearch 是一個分布式、高擴展、高實時的搜索與數據分析引擎。它能很方便的使大量數據具有搜索、分析和探索的能力,簡稱ES

EasyElasticSearch是支持ES的增刪改查的一個基礎類庫

支持表達式函數查詢
別名操作

查詢

 [HttpGet]
 public IActionResult Search()
 {
     var data = _searchProvider.Queryable<User>().Where(x => x.UserName == "52").ToList();
     return Ok(data);
 }

增加

 [HttpGet]
 public ActionResult Add()
 {
     var record = new RegistryRecord
     {
         UserId = "1268436794379079680",
         UserName = "es",
         RegistryTime = DateTime.Now
     };

     _indexProvider.Insert<RegistryRecord>(record);
     return Ok("Success");
 }

 /// <summary>
 /// 批量新增
 /// </summary>
 /// <returns></returns>
 [HttpGet]
 public ActionResult BulkAdd()
 {
     var records = new List<RegistryRecord>
     {
         new RegistryRecord{
               UserId = "1268436794379079680",
               UserName = "Bulkes1",
              RegistryTime = DateTime.Now
         },
         new RegistryRecord{
               UserId = "1268436794379079680",
               UserName = "Bulkes2",
              RegistryTime = DateTime.Now
         },
     };

     _indexProvider.InsertRange<RegistryRecord>(records);
     return Ok("Success");
 }

刪除

[HttpGet]
public IActionResult Delete()
{
    _deleteProvider.DeleteByQuery<RegistryRecord>(x => x.UserName == "Bulkes1");
    return Ok("Success");
}

.....

 

項目地址: https://github.com/wmchuang/EasyElasticSearch


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM