elasticsearch索引怎么创建
发表于:2024-10-22 作者:千家信息网编辑
千家信息网最后更新 2024年10月22日,本篇内容主要讲解"elasticsearch索引怎么创建",感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习"elasticsearch索引怎么创建"吧!索引查看
千家信息网最后更新 2024年10月22日elasticsearch索引怎么创建
本篇内容主要讲解"elasticsearch索引怎么创建",感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习"elasticsearch索引怎么创建"吧!
索引
查看所有索引
rst, _ := client.CatIndices().Do(ctx)buf, _ := json.Marshal(rst)fmt.Println(string(buf))
返回
[ { "health": "yellow", "status": "open", "index": "user", "uuid": "F4eP0Sq-S9a9pBJhN_eYVQ", "pri": "1", "rep": "3", "docs.count": "0", "docs.deleted": "0", "creation.date": "0", "creation.date.string": "", "store.size": "208b", "pri.store.size": "208b", "completion.size": "", "pri.completion.size": "", "fielddata.memory_size": "", "pri.fielddata.memory_size": "", "fielddata.evictions": "0", "pri.fielddata.evictions": "0", "query_cache.memory_size": "", "pri.query_cache.memory_size": "", "query_cache.evictions": "0", "pri.query_cache.evictions": "0", "request_cache.memory_size": "", "pri.request_cache.memory_size": "", "request_cache.evictions": "0", "pri.request_cache.evictions": "0", "request_cache.hit_count": "0", "pri.request_cache.hit_count": "0", "request_cache.miss_count": "0", "pri.request_cache.miss_count": "0", "flush.total": "0", "pri.flush.total": "0", "flush.total_time": "", "pri.flush.total_time": "", "get.current": "0", "pri.get.current": "0", "get.time": "", "pri.get.time": "", "get.total": "0", "pri.get.total": "0", "get.exists_time": "", "pri.get.exists_time": "", "get.exists_total": "0", "pri.get.exists_total": "0", "get.missing_time": "", "pri.get.missing_time": "", "get.missing_total": "0", "pri.get.missing_total": "0", "indexing.delete_current": "0", "pri.indexing.delete_current": "0", "indexing.delete_time": "", "pri.indexing.delete_time": "", "indexing.delete_total": "0", "pri.indexing.delete_total": "0", "indexing.index_current": "0", "pri.indexing.index_current": "0", "indexing.index_time": "", "pri.indexing.index_time": "", "indexing.index_total": "0", "pri.indexing.index_total": "0", "indexing.index_failed": "0", "pri.indexing.index_failed": "0", "merges.current": "0", "pri.merges.current": "0", "merges.current_docs": "0", "pri.merges.current_docs": "0", "merges.current_size": "", "pri.merges.current_size": "", "merges.total": "0", "pri.merges.total": "0", "merges.total_docs": "0", "pri.merges.total_docs": "0", "merges.total_size": "", "pri.merges.total_size": "", "merges.total_time": "", "pri.merges.total_time": "", "refresh.total": "0", "pri.refresh.total": "0", "refresh.external_total": "0", "pri.refresh.external_total": "0", "refresh.time": "", "pri.refresh.time": "", "refresh.external_time": "", "pri.refresh.external_time": "", "refresh.listeners": "0", "pri.refresh.listeners": "0", "search.fetch_current": "0", "pri.search.fetch_current": "0", "search.fetch_time": "", "pri.search.fetch_time": "", "search.fetch_total": "0", "pri.search.fetch_total": "0", "search.open_contexts": "0", "pri.search.open_contexts": "0", "search.query_current": "0", "pri.search.query_current": "0", "search.query_time": "", "pri.search.query_time": "", "search.query_total": "0", "pri.search.query_total": "0", "search.scroll_current": "0", "pri.search.scroll_current": "0", "search.scroll_time": "", "pri.search.scroll_time": "", "search.scroll_total": "0", "pri.search.scroll_total": "0", "search.throttled": "false", "segments.count": "0", "pri.segments.count": "0", "segments.memory": "", "pri.segments.memory": "", "segments.index_writer_memory": "", "pri.segments.index_writer_memory": "", "segments.version_map_memory": "", "pri.segments.version_map_memory": "", "segments.fixed_bitset_memory": "", "pri.segments.fixed_bitset_memory": "", "warmer.current": "0", "pri.warmer.current": "0", "warmer.total": "0", "pri.warmer.total": "0", "warmer.total_time": "", "pri.warmer.total_time": "", "suggest.current": "0", "pri.suggest.current": "0", "suggest.time": "", "pri.suggest.time": "", "suggest.total": "0", "pri.suggest.total": "0", "memory.total": "", "pri.memory.total": "" }]
查看 us 开头的索引
rst, _ := client.CatIndices().Index("us*").Do(ctx)buf, _ := json.Marshal(rst)fmt.Println(string(buf))
返回
同上
查看索引信息
rst, _ := client.IndexGet("user").Do(ctx)buf, _ := json.Marshal(rst)fmt.Println(string(buf))
返回
{ "user": { "aliases": {}, "mappings": { "properties": { "name": { "type": "keyword" } } }, "settings": { "index": { "creation_date": "1599207187635", "number_of_replicas": "1", "number_of_shards": "1", "provided_name": "user", "uuid": "F4eP0Sq-S9a9pBJhN_eYVQ", "version": { "created": "7080099" } } }, "warmers": null }}
查看 mapping
rst, _ := client.GetMapping().Index("user").Do(ctx)buf, _ := json.Marshal(rst)fmt.Println(string(buf))
返回
{ "user": { "mappings": { "properties": { "name": { "type": "keyword" } } } }}
查看 settings
rst, _ := client.IndexGetSettings("user").Do(ctx)buf, _ := json.Marshal(rst)fmt.Println(string(buf))
返回
{ "user": { "settings": { "index": { "creation_date": "1599207187635", "number_of_replicas": "1", "number_of_shards": "1", "provided_name": "user", "uuid": "F4eP0Sq-S9a9pBJhN_eYVQ", "version": { "created": "7080099" } } } }}
创建索引
rst, _ := client.CreateIndex("user").Do(ctx)buf, _ := json.Marshal(rst)fmt.Println(string(buf))
返回
{ "acknowledged": true, "shards_acknowledged": true, "index": "user" }
创建索引时指定 mapping 和 settings
bd := `{ "mappings" : { "properties" : { "name" : { "type" : "keyword" } } }, "settings" : { "index" : { "number_of_shards" : 1, "number_of_replicas" : 2 } }}`rst, _ := client.CreateIndex("user").Body(bd).Do(ctx)buf, _ := json.Marshal(rst)fmt.Println( string(buf))
返回
{ "acknowledged": true, "shards_acknowledged": true, "index": "user" }
创建索引,然后置顶 mapping
_, err := client.CreateIndex("user").Do(ctx)if err != nil { panic(err.Error())}bd := `{ "properties" : { "name" : { "type" : "keyword" } }}`rst, _ := client.PutMapping().Index("user").BodyString(bd).Do(ctx)buf, _ := json.Marshal(rst)fmt.Println(string(buf))
返回
{ "acknowledged": true, "shards_acknowledged": false }
创建文档时自动创建索引
rst, _ := client.Index().Index("user").BodyJson(&User{Name: "noname1"}).Do(ctx)buf, _ := json.Marshal(rst)fmt.Println(string(buf))
返回
{ "_index": "user", "_type": "_doc", "_id": "Y70mWHQBIsMSghaJdERa", "_version": 1, "result": "created", "_shards": { "total": 2, "successful": 1, "failed": 0 }, "_primary_term": 1}
修改副本数量
bd := `{ "index" : { "number_of_replicas" : 3 }}`rst, _ := client.IndexPutSettings("user").BodyString(bd).Do(ctx)buf, _ := json.Marshal(rst)fmt.Println(string(buf))
返回
{ "acknowledged": true, "shards_acknowledged": false }
修改分片数量
bd := `{ "index" : { "number_of_shards" : 2 }}`rst, err := client.IndexPutSettings("user").BodyString(bd).Do(ctx)if err != nil { fmt.Println(err.Error()) return}buf, _ := json.Marshal(rst)fmt.Println(string(buf))
返回
elastic: Error 400 (Bad Request): Can't update non dynamic settings [[index.number_of_shards]] for open indices [[user/F4eP0Sq-S9a9pBJhN_eYVQ]] [type=illegal_argument_exception]
说明:分片数量,必须在索引创建时指定,创建后无法修改。尝试修改时会报错
删除索引
rst, _ := client.DeleteIndex("user").Do(ctx)buf, _ := json.Marshal(rst)fmt.Println(string(buf))
返回
{ "acknowledged": true }
到此,相信大家对"elasticsearch索引怎么创建"有了更深的了解,不妨来实际操作一番吧!这里是网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!
索引
数量
内容
学习
实用
更深
信息
兴趣
副本
实用性
实际
开头
操作简单
文档
方法
更多
朋友
网站
频道
会报
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
软件开发人员公司
ios数据库mysql
断开某个数据库的所有连接
咸鱼之王忘记了自己的服务器
成都万家互联网科技有限公司
防水网络技术
网络安全先进个人成绩
自动化运动控制软件开发
手机软件开发流程工具
奉贤区项目数据库服务活动简介
网络安全监控中心职责
数据库中一对一的实现方式
游戏服务器战斗开发难点
mpp的数据库问题
手机上怎么打开服务器
委托软件开发费用会计分录
华工信息网络技术有限公司
资料共享数据库
软件开发费用增值税进项税额
软件开发工具应用于哪个阶段
湖北云超算套料软件开发商
福建网络安全宣传周期
类似共享单车软件开发
初中毕业学软件开发有前途吗
我的世界小萱服务器
宿城区网络安全管理
哪个服务器是怀旧服的联盟服
窦维网络技术服务中心
成立一个公司外包软件开发
华为传输网络技术