V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
• 请不要在回答技术问题时复制粘贴 AI 生成的内容
jahan
V2EX  ›  程序员

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

  •  
  •   jahan · Mar 5, 2018 · 6542 views
    This topic created in 2988 days ago, the information mentioned may be changed or developed.

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

    7 replies    2020-06-12 15:26:36 +08:00
    jahan
        1
    jahan  
    OP
       Mar 5, 2018
    6.2 的 elasticsearch
    jahan
        2
    jahan  
    OP
       Mar 6, 2018
    {"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  
       Mar 6, 2018
    GET _template

    找到相应的模板名称,删除即可。
    jahan
        4
    jahan  
    OP
       Mar 6, 2018
    查到并且用 curl xdelete 给删除了,然后重新建 test index,get test/_mapping 神奇的 mapping 又出现了。
    我做错了什么?
    jahan
        5
    jahan  
    OP
       Mar 6, 2018
    做了一个模版是这样的,打算手工加载,
    {
    "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
       Mar 6, 2018
    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  
       Jun 12, 2020
    # 找到索引对应的模版
    GET _template
    # 删除相关模版
    DELETE /_template/target_template
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1239 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 34ms · UTC 17:28 · PVG 01:28 · LAX 10:28 · JFK 13:28
    ♥ Do have faith in what you're doing.