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

2018-03-05 23:54:08 +08:00
 jahan

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

5703 次点击
所在节点    程序员
7 条回复
jahan
2018-03-05 23:55:26 +08:00
6.2 的 elasticsearch
jahan
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
2018-03-06 00:10:34 +08:00
GET _template

找到相应的模板名称,删除即可。
jahan
2018-03-06 00:26:22 +08:00
查到并且用 curl xdelete 给删除了,然后重新建 test index,get test/_mapping 神奇的 mapping 又出现了。
我做错了什么?
jahan
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
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": "shay@kimchy.com"
}

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
2020-06-12 15:26:36 +08:00
# 找到索引对应的模版
GET _template
# 删除相关模版
DELETE /_template/target_template

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/435146

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX