本文小编为大家详细介绍“es如何创建索引和mapping”,内容详细,步骤清晰,细节处理妥当,希望这篇“es如何创建索引和mapping”文章能帮助大家解决疑惑,下面跟着小编的思路慢慢深入,一起来学习新知识吧。es创建索引和mapping索
本文小编为大家详细介绍“es如何创建索引和mapping”,内容详细,步骤清晰,细节处理妥当,希望这篇“es如何创建索引和mapping”文章能帮助大家解决疑惑,下面跟着小编的思路慢慢深入,一起来学习新知识吧。
创建index
Http://127.0.0.1:9200/negative/ put{ "settings": { "index": { "search": { "slowlog": { "threshold": { "fetch": { "debug": "5s" }, "query": { "warn": "20s" } } } }, "indexing": { "slowlog": { "threshold": { "index": { "info": "20s" } } } }, "number_of_shards": "1", "number_of_replicas": "0" } }}
创建mapping
http://127.0.0.1:9200/negative/negative/_mapping post{"properties":{ "id": { "type": "long" }, "yjlb": { "type": "text", "fields": { "keyWord": { "type": "keyword", "ignore_above": 256 } } }, "ejlb": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } }, "sjlb": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } }, "detail": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } }, "ssyj": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } }}}
(注意:mapping下面一层的key值 是type名称)
http://192.168.0.213:9200/announcement/ put{ "settings": { "index": { "search": { "slowlog": { "threshold": { "fetch": { "debug": "5s" }, "query": { "warn": "20s" } } } }, "indexing": { "slowlog": { "threshold": { "index": { "info": "20s" } } } }, "number_of_shards": "1", "number_of_replicas": "0" } }, "mappings": { "announcement": { "properties": { "id": { "type": "keyword" }, "createtime": { "type": "date", "fORMat": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis" }, "creatby": { "type": "keyword" }, "updatetime": { "type": "date", "format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis" }, "type": { "type": "keyword" }, "status": { "type": "keyword" }, "title": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } }, "cont": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } }, "files": { "type": "nested", "properties": { "id": { "type": "keyword" }, "filename": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } } } } } } }}
昨天研发说在kibana中统计userid字段不出图,后来查到该字段显示冲突了,然后再查看了GET test/_mapping下该索引的mapping,发现userid是long类型的,而userid.keyword是string类型的,出现这种情况的根本原因是日志中这个字段存的是数值类型的值,改成字符串类型即可,由于急着用,我司上线一般是下午6点30上线,所以临时修改了下该字段的类型,步骤如下:
GET test
/_mapping
找到userid这个字段,修改类型为keyword,如下:
{ "mappings": { "doc": { "properties": { "@timestamp": { "type": "date" }, "@version": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } }, "beat": { "properties": { "hostname": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } }, "name": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } }, "version": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } } } }, "code": { "type": "long" }, "dip": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } }, "fields": { "properties": { "log_topic": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } } } }, "host": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } }, "message": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } }, "method": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } }, "name": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } }, "offset": { "type": "long" }, "referer": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } }, "sip": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } }, "source": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } }, "tags": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } }, "time": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } }, "url": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } }, "userid": { "type": "keyword" #修改此处 } } } }}
PUT test-new{ "mappings": { "doc": { "properties": { "@timestamp": { "type": "date" }, "@version": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } }, "beat": { "properties": { "hostname": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } }, "name": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } }, "version": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } } } }, "code": { "type": "long" }, "dip": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } }, "fields": { "properties": { "log_topic": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } } } }, "host": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } }, "message": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } }, "method": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } }, "name": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } }, "offset": { "type": "long" }, "referer": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } }, "sip": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } }, "source": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } }, "tags": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } }, "time": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } }, "url": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } }, "userid": { "type": "keyword" } } } }}
注意,旧索引先停止新数据的写入
POST _reindex{ "source": { "index": "test" }, "dest": { "index": "test-new" }}
DELETE test
PUT test{ "mappings": { "doc": { "properties": { "@timestamp": { "type": "date" }, "@version": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } }, "beat": { "properties": { "hostname": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } }, "name": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } }, "version": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } } } }, "code": { "type": "long" }, "dip": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } }, "fields": { "properties": { "log_topic": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } } } }, "host": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } }, "message": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } }, "method": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } }, "name": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } }, "offset": { "type": "long" }, "referer": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } }, "sip": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } }, "source": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } }, "tags": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } }, "time": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } }, "url": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } }, "userid": { "type": "keyword" } } } }}
POST _reindex{ "source": { "index": "test-new" }, "dest": { "index": "test" }}
GET test/_mapping,执行命令后,可以看到userid的字段类型为keyword类型了
然后再打开该索引接收新数据的开关
读到这里,这篇“es如何创建索引和mapping”文章已经介绍完毕,想要掌握这篇文章的知识点还需要大家自己动手实践使用过才能领会,如果想了解更多相关内容的文章,欢迎关注编程网精选频道。
--结束END--
本文标题: es如何创建索引和mapping
本文链接: https://lsjlt.com/news/350050.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0