Elasticsearch 移除 type 之后的新姿势

随着 7.0 版本的即将发布,type 的移除也是越来越近了,在 6.0 的时候,已经默认只能支持一个索引一个 type 了,7.0 版本新增了一个参数 include_type_name ,即让所有的 API 是 type 相关的,这个参数在 7.0 默认是 true,不过在 8.0 的时候,会默认改成 false,也就是不包含 type 信息了,这个是 type 用于移除的一个开关。

让我们看看最新的使用姿势吧,当 include_type_name 参数设置成 false 后:

  • 索引操作:PUT {index}/{type}/{id}需要修改成PUT {index}/_doc/{id}
  • Mapping 操作:PUT {index}/{type}/_mapping 则变成 PUT {index}/_mapping
  • 所有增删改查搜索操作返回结果里面的关键字 _type 都将被移除
  • 父子关系使用 join 字段来构建
  • #创建索引
    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"
    }
    
    #搜索
    GET twitter/_search
    {
      "query": {
        "bool": {
          "must": {
            "match": {
              "user_name": "kimchy"
            }
          },
          "filter": {
            "match": {
              "type": "tweet" 
            }
          }
        }
      }
    }
    
    #重建索引
    POST _reindex
    {
      "source": {
        "index": "twitter"
      },
      "dest": {
        "index": "new_twitter"
      }
    }

    原文链接

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值