ElasticSearch操作实例大全---文档结构操作(2)
2016-08-22 10:19
639 查看
接上一篇 ElasticSearch操作实例大全---文档结构操作(1)
前提条件--开发环境已安装 (自行百度)
客户端用的是nest
学习elasticSearch主要是要掌握像sqlserver要会操作数据结构的增删改和数据的增删改查,这里主要写elasticSearch的文档结构操作和文档数据操作
一、如果你已经建好了索引,但是需求改变需要新增一个字段,那就改了之后要进行映射,映射主要是确定字段的数据类型
二、刷新索引
三、优化索引
四、关闭索引
五、打开索引
文档结构的操作基本就是以上操作
前提条件--开发环境已安装 (自行百度)
客户端用的是nest
学习elasticSearch主要是要掌握像sqlserver要会操作数据结构的增删改和数据的增删改查,这里主要写elasticSearch的文档结构操作和文档数据操作
一、如果你已经建好了索引,但是需求改变需要新增一个字段,那就改了之后要进行映射,映射主要是确定字段的数据类型
/// <summary> /// 创建mapping /// </summary> /// <typeparam name="T">需要创建的mapping类型</typeparam> /// <param name="indexName">索引名</param> /// <param name="analyzer">分词器</param> /// <returns></returns> public bool AddMapping<T>(string indexName = null, string analyzer = "ik") where T : class { if (string.IsNullOrWhiteSpace(indexName)) { indexName = IndexName; } //对参数进行判断 if (string.IsNullOrWhiteSpace(indexName)) { OriginalException = new Exception("索引名不允许为空"); return false; } //如果索引名称已经存在,则不插入 if (!IsExists(indexName)) { OriginalException = new Exception("索引不存在"); return false; } var response = Client.Map<T>(m => m.MapFromAttributes().IndexAnalyzer(analyzer).Index(indexName)); return Helper.ConvertIResponse(response, OriginalException); }
二、刷新索引
/// <summary> /// 刷新索引 /// </summary> /// <returns></returns> public bool Refresh() { var response = Client.Refresh(r => r.Index(IndexName)); return Helper.ConvertIResponse(response, OriginalException); }
三、优化索引
/// <summary> /// 优化索引 /// </summary> /// <returns></returns> public bool Optimize(long max_num_segments = 1, bool flush = true) { var response = Client.Optimize(o => o .Index(IndexName) .MaxNumSegments(max_num_segments) .Flush(flush) ); return Helper.ConvertIResponse(response, OriginalException); }
四、关闭索引
/// <summary> /// 关闭索引 /// </summary> /// <param name="indexName">索引名</param> /// <returns></returns> public bool Close() { var response = Client.CloseIndex(IndexName); return Helper.ConvertIResponse(response, OriginalException); }
五、打开索引
/// <summary> /// 打开索引 /// </summary> /// <param name="indexName">索引名</param> /// <returns></returns> public bool Open() { var response = Client.OpenIndex(IndexName); return Helper.ConvertIResponse(response, OriginalException); }
文档结构的操作基本就是以上操作
相关文章推荐
- ElasticSearch操作实例大全---文档结构操作(1)
- 基于WebForm的操作Word文档实例
- 位操作技巧实例大全
- php中DOMElement操作xml文档实例演示
- python文件和目录操作方法大全(含实例)
- python文件和目录操作方法大全(含实例)
- MFC浅析(2) 文档视图结构中文档操作流程
- jquery文档操作wrap()方法实例简述
- mysql常用字符串操作函数大全,以及实例
- MFC浅析(2) 文档视图结构中文档操作流程
- 数据结构7-关于“图”的生成与操作的实例
- MFC浅析(2) 文档视图结构中文档操作流程
- Asp.net XML文档进行添加删改操作的实例代码
- 用MFC ODBC操作Access数据库 (怎么添加数据源,单文档和对话框实例)
- js操作dom文档大全
- 经典SQL语句大全(实例)非常不错的和excel等文档实例结合的sql
- 位操作技巧实例大全
- MFC浅析(2) 文档视图结构中文档操作流程
- LigerUi中TAB的操作实例大全(更新中)
- python文件和目录操作方法大全(含实例)