V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
jahan
V2EX  ›  程序员

求教一下 elasticsearch 下面删除了 index,为何重建 index,原来下面的 mapping 还存在?

  •  
  •   jahan · 2018-03-05 23:54:08 +08:00 · 5693 次点击
    这是一个创建于 2242 天前的主题,其中的信息可能已经有所发展或是发生改变。

    场景是这样的,put test 建立了一个 index,以及一个 mapping,然后吧 index delete 了,想着 index 下面的 mapping 也就没了,确实用 get test/_mapping 报错了。不过重新 put test 这个 index 之后,get test/_mapping 又出现了。如何才能干净得删除一个 index 以及下面所有的 mapping 呢?

    7 条回复    2020-06-12 15:26:36 +08:00
    jahan
        1
    jahan  
    OP
       2018-03-05 23:55:26 +08:00
    6.2 的 elasticsearch
    jahan
        2
    jahan  
    OP
       2018-03-06 00:08:18 +08:00
    {"error":{"root_cause":[{"type":"illegal_argument_exception","reason":"Rejecting mapping update to [tYGi6U7cTsO_0YXJvN_W2g] as the final mapping would have more than 1 type: [t_gx_jgxx, t_kh_grjcxx]"}],"type":"illegal_argument_exception","reason":"Rejecting mapping update to [tYGi6U7cTsO_0YXJvN_W2g] as the final mapping would have more than 1 type: [t_gx_jgxx, t_kh_grjcxx]"},"status":400}
    Terenc3
        3
    Terenc3  
       2018-03-06 00:10:34 +08:00
    GET _template

    找到相应的模板名称,删除即可。
    jahan
        4
    jahan  
    OP
       2018-03-06 00:26:22 +08:00
    查到并且用 curl xdelete 给删除了,然后重新建 test index,get test/_mapping 神奇的 mapping 又出现了。
    我做错了什么?
    jahan
        5
    jahan  
    OP
       2018-03-06 00:30:24 +08:00
    做了一个模版是这样的,打算手工加载,
    {
    "index_patterns": ["tes*"],
    "settings" : {
    "index" : {
    "number_of_shards" : 3,
    "number_of_replicas" : 2
    }
    },

    "mappings" : {
    "t_df_dfxx" : {
    "properties" : {
    "ydaxj" : { "type" : "text" },
    "nbddh" : { "type" : "text" },
    "ajrds" : { "type" : "text" },

    }
    },

    "t_kd_grdfd" : {
    "properties" : {
    "kk" : { "type" : "text" },
    "zjdd" : { "type" : "text" },
    "yxjdf" : { "type" : "text" },

    }
    }
    }
    }
    查了文档,看的十分困惑,有的说这个不支持多个 type,说 7.0 就完全支持。有的例子就完全一样,说 6.0 支持这种写法。
    jahan
        6
    jahan  
    OP
       2018-03-06 08:18:06 +08:00
    https://www.elastic.co/guide/en/elasticsearch/reference/current/removal-of-types.html
    这里讲 6.0 和以后的版本都不支持多个 mapping,文档给出了这么一个解决方案。
    PUT twitter
    {
    "mappings": {
    "_doc": {
    "properties": {
    "type": { "type": "keyword" },
    "name": { "type": "text" },
    "user_name": { "type": "keyword" },
    "email": { "type": "keyword" },
    "content": { "type": "text" },
    "tweeted_at": { "type": "date" }
    }
    }
    }
    }

    PUT twitter/_doc/user-kimchy
    {
    "type": "user",
    "name": "Shay Banon",
    "user_name": "kimchy",
    "email": "[email protected]"
    }

    PUT twitter/_doc/tweet-1
    {
    "type": "tweet",
    "user_name": "kimchy",
    "tweeted_at": "2017-10-24T09:00:00Z",
    "content": "Types are going away"
    }

    GET twitter/_search
    {
    "query": {
    "bool": {
    "must": {
    "match": {
    "user_name": "kimchy"
    }
    },
    "filter": {
    "match": {
    "type": "tweet"
    }
    }
    }
    }
    }

    我的理解是这个把所有的字段混在一起,并不区分 mapping (传统意义上的表)或设置了一个虚拟的 mapping,然后在填充的时候确定 type。单个的例子容易实现,put 就可以了。我从 filebeat-》 logstash-〉 es 就有些理解不了了,加载 template 的时候,还是免不了出 mapping 下的 type 不能多余一个的错误。
    mzbb
        7
    mzbb  
       2020-06-12 15:26:36 +08:00
    # 找到索引对应的模版
    GET _template
    # 删除相关模版
    DELETE /_template/target_template
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5786 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 01:49 · PVG 09:49 · LAX 18:49 · JFK 21:49
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.