public static DeleteResponse DeleteDocument <TEntity>(this IElasticClient elasticClient , TEntity entity , string indexName ) { string idValue = ElasticsearchKit.GetIdPropertyValue(entity).ToStrAndTrim(); return(DeleteDocument(elasticClient, indexName, idValue)); }
/// <summary> /// Update Document /// </summary> /// <typeparam name="TEntity"></typeparam> /// <param name="elasticClient"></param> /// <param name="entity"></param> /// <returns></returns> public static UpdateResponse <TEntity> UpdateDocument <TEntity>(this IElasticClient elasticClient , TEntity entity ) where TEntity : class { string idValue = ElasticsearchKit.GetIdPropertyValue(entity).ToStrAndTrim(); // [ 全文更新 ] UpdateResponse <TEntity> response = elasticClient.Update <TEntity>(idValue, t => t.Doc(entity)); return(response); }
//https://blog.csdn.net/weixin_44526839/article/details/106386260?spm=1001.2014.3001.5502 /// <summary> /// Create Document /// </summary> /// <typeparam name="TEntity"></typeparam> /// <param name="elasticClient"></param> /// <param name="indexName">索引名称</param> /// <param name="entity"></param> /// <param name="id">文档Id需为唯一标识。文档Id主要用途:1.修改 / 删除 数据时,需指定文档Id</param> /// <returns></returns> public static CreateResponse CreateDocument <TEntity>(this IElasticClient elasticClient , TEntity entity , string indexName ) where TEntity : class { string idValue = ElasticsearchKit.GetIdPropertyValue(entity).ToStrAndTrim(); CreateResponse response = elasticClient.Create <TEntity>(entity, t => t.Index(indexName).Id(idValue)); return(response); }
/// <summary> /// 部分更新 /// </summary> /// <typeparam name="TEntity"></typeparam> /// <typeparam name="TPartialEntity"></typeparam> /// <param name="elasticClient"></param> /// <param name="request"></param> /// <returns></returns> public static UpdateResponse <TEntity> UpdateDocumentPartial <TEntity>(this IElasticClient elasticClient , TEntity entity , object partialEntity , string indexName = null ) where TEntity : class { string idValue = ElasticsearchKit.GetIdPropertyValue(entity).ToStrAndTrim(); IUpdateRequest <TEntity, object> request = new UpdateRequest <TEntity, object>(indexName, idValue) { Doc = partialEntity }; //[ 部分字段/局部更新 (TPartialEntity中的字段) ] UpdateResponse <TEntity> response = elasticClient.Update(request); return(response); }