欢迎投稿

今日深度:

Elasticsearch 6.x 新变化,elasticsearch6.x

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,进行区分, 据说这样可以更好的提交效率。

www.htsjk.Com true http://www.htsjk.com/Elasticsearch/35881.html NewsArticle Elasticsearch 6.x 新变化,elasticsearch6.x 1、Removal of mapping types 虽然一直知道es已经更新到6.x以上,但之前的项目中一直没有升级,也没有关注版本更新后有哪些变化。昨天要在新项目中也加...
相关文章
    暂无相关文章
评论暂时关闭