创建es索引和mapping

本文介绍了两种在Elasticsearch中创建索引和设置映射的方法。第一种通过Python操作,使用`es.indices.create()`和`es.indices.put_mapping()`函数;第二种采用curl命令,分别创建索引和设置映射,并提供了查看映射设置的命令。

创建es索引和mapping
第一种:
def set_mapping():
    my_mapping = {
        type_: {
            "properties": {
                "@timestamp": {
                    "type": "date"
                },
                "@version": {
                    "type": "keyword"
                },
                "channelSwitchDelay": {
                    "type": "long"
                },
                "frameDelay": {
                    "type": "long"
                },
                "host": {
                    "type": "keyword"
                },
                "iptvAccount": {
                    "type": "keyword"
                },
                "kaNum": {
                    "type": "long"
                },
                "mac": {
                    "type": "keyword"
                },
                "message": {
                    "type": "keyword"
                },
                "oui": {
                    "type": "keyword"
                },
                "path": {
                    "type": "keyword"
                },
                "productClass": {
                    "type": "keyword"
                },
                "responseDelay": {
                    "type": "long"
                },
                "rtpLossRate": {
                    "type": "long"
                },
                "softProbeOUI": {
                    "type": "keyword"
                },
                "streamBreak": {
                    "type": "long"
                },
                "type": {
                    "type": "keyword"
                }
            }
        }
    }
    creat_index = es.indices.create(index=index_insert, body=None)
    mapping_index = es.indices.put_mapping(index=index_insert, doc_type=type_, body=my_mapping)
    if creat_index['acknowledged'] != True or mapping_index['acknowledged'] != True:
        print("Index create failed")

第二种:
1、创建索引
curl -XPUT 'http://10.0.0.20:9200/iptv_test_3'
2、设置map
curl -XPUT 'http://10.0.0.20:9200/iptv_test_3/iptv-apk/_mapping?pretty' -d '{
    "iptv-apk": {
                    "properties": {
                        "@timestamp": {
                            "type": "date"
                        },
                        "@version": {
                            "type": "keyword"
                        },
                        "channelSwitchDelay": {
                            "type": "long"
                        },
                        "frameDelay": {
                            "type": "long"
                        },
                        "host": {
                            "type": "keyword"
                        },
                        "iptvAccount": {
                            "type": "keyword"
                        },
                        "kaNum": {
                            "type": "long"
                        },
                        "mac": {
                            "type": "keyword"
                        },
                        "message": {
                            "type": "keyword"
                        },
                        "oui": {
                            "type": "keyword"
                        },
                        "path": {
                            "type": "keyword"
                        },
                        "productClass": {
                            "type": "keyword"
                        },
                        "responseDelay": {
                            "type": "long"
                        },
                        "rtpLossRate": {
                            "type": "long"
                        },
                        "softProbeOUI": {
                            "type": "keyword"
                        },
                        "streamBreak": {
                            "type": "long"
                        },
                        "type": {
                            "type": "keyword"
                        }
                    }
                }
}'
3、查看设置的map
curl -XGET 'http://10.0.0.20:9200/iptv_test_3/_mapping?pretty'

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值