一、重建表 cn ,并迁移数据
    原因:
    因 cn 表之前建的 mapping 类型有问题,导致以bug,
    不能按时间筛选,text类型的字段类型聚合报错

    执行流程:

    • 新建索引
    • 导出数据到新的索引
    • 删除老的数据
    • 新索引建别名

    二、新建索引

    
    curl -XPUT 127.0.0.1:9200/cn-new -H 'Content-Type: application/json' -d '
    {"settings":{"index":{"mapping":{"total_fields":{"limit":"10000"}},"number_of_shards":"6","max_result_window":"2000000","number_of_replicas":"0"}},"mappings":{"properties":{"targetHost":{"type":"keyword"},"beginAt":{"format":"yyyy-MM-dd HH:mm:ss","type":"date"},"parentTaskID":{"type":"keyword"},"ping":{"dynamic":"false","properties":{"country":{"type":"keyword"},"duplicates":{"type":"long"},"address":{"type":"keyword"},"max":{"type":"long"},"ip":{"type":"keyword"},"received":{"type":"long"},"transmitted":{"type":"long"},"loss":{"type":"double"},"isIPv6":{"type":"long"},"avg":{"type":"long"},"min":{"type":"long"},"connectivity":{"type":"boolean"},"province":{"type":"keyword"},"provider":{"type":"keyword"},"region":{"type":"keyword"},"stddev":{"type":"long"}}},"storageAt":{"format":"yyyy-MM-dd HH:mm:ss","type":"date"},"dns":{"dynamic":"false","properties":{"rtt":{"type":"long"},"data":{"dynamic":"false","properties":{"name":{"type":"keyword"},"class":{"type":"keyword"},"ttl":{"type":"long"},"rrtype":{"type":"keyword"},"target":{"type":"keyword"}}}}},"errorMessage":{"dynamic":"true","type":"object"},"endAt":{"format":"yyyy-MM-dd HH:mm:ss","type":"date"},"isResultOK":{"type":"boolean"},"nodeOperator":{"type":"long"},"web":{"dynamic":"false","properties":{"connectDuration":{"type":"long"},"contentDuration":{"type":"long"},"firstByteDuration":{"type":"long"},"status":{"type":"long"}}},"nodeID":{"type":"keyword"},"taskID":{"type":"keyword"},"nodeProvince":{"type":"long"}}}}'
    

    三、导出数据到新的索引

    elasticdump --input http://127.0.0.1:9200/cn --output http://127.0.0.1:9200/cn-new --type=data --limit 5000

    四、删除老的数据
    curl -XDELETE '127.0.0.1:9200/cn'

    五、新索引建别名

    curl -XPOST '127.0.0.1:9200/_aliases' -H 'Content-Type: application/json' -d '{"actions" : [{"add" : {"index" : "cn-new" , "alias" : "cn"}}]}'

    作者:admin  创建时间:2023-07-20 14:23
    最后编辑:admin  更新时间:2024-12-22 19:32