Elasticsearch 6.x 新变化,elasticsearch6.x
1、Removal of mapping types
虽然一直知道es已经更新到6.x以上,但之前的项目中一直没有升级,也没有关注版本更新后有哪些变化。昨天要在新项目中也加入ES,遂直接下载了最新版本的es和logstash,照原先的方法做却发现出现了新的问题,查阅之后才发现,ES6.0之后版本mapping有了个大变化,它移除了多types的写法。按照ES的计划,在之后的版本中,会逐渐淘汰 /index/type/id 中的type这一参数,原因及计划见文档。
官方文档地址
https://www.elastic.co/guide/en/elasticsearch/reference/6.2/removal-of-types.html
Mapping新写法
上图表明6.0后要求一个index只能有一个type,所以现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"
}
}
}
}
}
可以看出,它是将原先的单独的type的字段取并集放入了一个type中,在put数据时可以指定具体的type,进行区分, 据说这样可以更好的提交效率。
本站文章为和通数据库网友分享或者投稿,欢迎任何形式的转载,但请务必注明出处.
同时文章内容如有侵犯了您的权益,请联系QQ:970679559,我们会在尽快处理。