首页 > 移动平台 > 详细

elasticsearch 6.0.0及之后移除了一个索引允许映射多个类型的操作(Removal of mapping types)

时间:2018-02-25 21:27:53      阅读:196      评论:0      收藏:0      [点我收藏+]

标签:user   版本   解决   ase   asc   adding   course   新的   blog   

用到了6.2,还以为像5.X 一样允许建立 父-子关系文档 ,即一个索引下允许映射多个类型,操作后发现行不通

如下代码:

PUT /company
{
  "mappings": {
    "branch": {},
    "employee": {
      "_parent": {
        "type": "branch" 
      }
    }
  }
}

 

找到最新的官方文档,给出了说明,大意是:

6.0.0移除了一个索引允许映射多个类型,虽然还支持同索引多类型查询,但是Elasticsearch 7.0.0的版本将完全放弃。

 

不过官方给了另外的方案解决

Custom type fieldedit
Of course, there is a limit to how many primary shards can exist in a cluster so you may not want to waste an entire shard for a collection of only a few thousand documents. In this case, you can implement your own custom type field which will work in a similar way to the old _type.

Let’s take the user/tweet example above. Originally, the workflow would have looked something like this:

PUT twitter
{
  "mappings": {
    "user": {
      "properties": {
        "name": { "type": "text" },
        "user_name": { "type": "keyword" },
        "email": { "type": "keyword" }
      }
    },
    "tweet": {
      "properties": {
        "content": { "type": "text" },
        "user_name": { "type": "keyword" },
        "tweeted_at": { "type": "date" }
      }
    }
  }
}

PUT twitter/user/kimchy
{
  "name": "Shay Banon",
  "user_name": "kimchy",
  "email": "shay@kimchy.com"
}

PUT twitter/tweet/1
{
  "user_name": "kimchy",
  "tweeted_at": "2017-10-24T09:00:00Z",
  "content": "Types are going away"
}

GET twitter/tweet/_search
{
  "query": {
    "match": {
      "user_name": "kimchy"
    }
  }
}
You could achieve the same thing by adding a custom type field as follows:

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" 
        }
      }
    }
  }
}
   

The explicit type field takes the place of the implicit _type field.

  这是官网的6.x的关于此点的描述:https://www.elastic.co/guide/en/elasticsearch/reference/current/removal-of-types.html

elasticsearch 6.0.0及之后移除了一个索引允许映射多个类型的操作(Removal of mapping types)

标签:user   版本   解决   ase   asc   adding   course   新的   blog   

原文:https://www.cnblogs.com/liugx/p/8470369.html

(0)
(0)
   
举报
评论 一句话评论(0
0条  
登录后才能评论!
© 2014 bubuko.com 版权所有 鲁ICP备09046678号-4
打开技术之扣,分享程序人生!
             

鲁公网安备 37021202000002号