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 不能多余一个的错误。