zoukankan      html  css  js  c++  java
  • es7.+(三)mapping

    1.mapping

    用来定义一个文档如何被处理的,这些属性字段是怎么被存储和被检索的

    • 使用哪个mapping去定义哪个String字段应该被当做全文检索字段
    • 哪一个字段包含数值、日期或者地理位置坐标
    • 文档中的所有属性是否都能被索引(_all配置)
    • 日期的格式化数据
    • 自定义映射规则来执行动态添加属性

    es会自动的为数据定义mapping,但有的时候需要自定义

    1.1查询已经存有数据的索引index的信息

    GET /bank/_mapping
    返回结果

    {
      "bank" : {
        "mappings" : {
          "properties" : {
            "account_number" : {
              "type" : "long"
            },
            "address" : {
              "type" : "text",
              "fields" : {
                "keyword" : {
                  "type" : "keyword",
                  "ignore_above" : 256
                }
              }
            },
            "age" : {
              "type" : "long"
            },
            "balance" : {
              "type" : "long"
            },
    ...
    

    1.2如何自定义映射

    • 创建一个索引
      PUT /my_index
    • 在新索引保存数据之前,可以先创建映射规则
    {
      "mappings": {
        "properties": {
          "age":{
            "type": "integer"
          },
          "email":{
            "type": "keyword"
          },
          "name":{
            "type": "text"
          }
        }
      }
    }
    

    返回内容

        {
          "acknowledged" : true,
          "shards_acknowledged" : true,
          "index" : "my_index"
        }
    

    1.3添加新的字段映射

    比如我们需要新增一个字段,名字是 employee-id

    该index选项控制是否对字段值建立索引。它接受true 或false,默认为true。未索引的字段不可查询
    index选项控制这个属性的值能不能被索引,为true或false,默认是true。如果一个字段的index为false那么他就不会被检索到,他是来控制这个字段是不是参与检索的

    PUT /my_index/_mapping
    {
      "properties":{
        "employee-id":{
          "type": "keyword",
          "index": false
        }
      }
    }
    

    1.4修改映射数据迁移

    对于已经存在的映射字段,我们不能更新,更新必须创建新的索引进行数据迁移。

    我们先来创建新的映射关系,稍后我们将进行数据迁移

    PUT /newbank
    {
      "mappings": {
        "properties": {
          "account_number" : {
              "type" : "long"
            },
            "address" : {
              "type" : "text"
            },
            "age" : {
              "type" : "integer"
            },
            "balance" : {
              "type" : "long"
            },
            "city" : {
              "type" : "keyword"
            },
            "email" : {
              "type" : "keyword"
            },
            "employer" : {
              "type" : "keyword"
            },
            "firstname" : {
              "type" : "text"
            },
            "gender" : {
              "type" : "keyword"
            },
            "lastname" : {
              "type" : "text",
              "fields" : {
                "keyword" : {
                  "type" : "keyword",
                  "ignore_above" : 256
                }
              }
            },
            "state" : {
              "type" : "keyword"
            }
        }
      }
    }
    

    进行数据迁移

    • 7.+版本
        POST _reindex
        {
            "source":{
                "index": "bank"
            },
            "dest":{
                "index": "newbank"
            }
        }
    
    • 7.+版本之前(还使用type的版本)
    POST _reindex
    {
      "source": {
        "index": "bank",
        "type": "account"
      },
      "dest": {
        "index": "newbank"
      }
    }
    

    关于es7-去掉type的概念

  • 相关阅读:
    在vim中设置将tab自动转化为4个空格
    nginx1.4.6+php5.5.11+mysql5.6.17+mecache+opcache
    Centos7安装杀毒软件ClamAV
    网页中meta标记
    js刷新页面方法大全
    微信第三方登陆,无需注册一键登录,获取用户信息,PHP实现方法
    phpcms v9 如何实现用户登录
    web页面自适应手机屏幕宽度
    微信公共平台消息回复类
    自动回复微信消息
  • 原文地址:https://www.cnblogs.com/psyduck/p/14472015.html
Copyright © 2011-2022 走看看