• 谷粒商城学习——P119-121映射


    映射定义文档如何被存储和检索的

    @映射字段类型

    text类型⽤于全⽂索引,搜索时会自动使用分词器进⾏分词再匹配
    keyword 不分词,搜索时需要匹配完整的值

    创建索引并指定映射

    PUT /my_index
    {
      "mappings": {
        "properties": {
          "age": {
            "type": "integer" #整数存入如不指定类型会默认为long
          },
          "email": {
            "type": "keyword" #keyword检索时会精确匹配匹配
          },
          "name": {
            "type": "text" #检索时候进行分词匹配
          }
        }
      }
    }

    创建带检索

    添加新的字段映射

    PUT /my_index/_mapping
    {
      "properties": {
        "employee-id": {
          "type": "keyword",
          "index": false # 字段不能被检索。默认所有字段的index都是true的,只相当于一个冗余存储信息
        }
      }
    }

    更新映射

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

    数据迁移

    先创建bank的正确映射newbank

    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" : "keyword"
            },
            "gender" : {
              "type" : "keyword"
            },
            "lastname" : {
              "type" : "text",
              "fields" : {
                "keyword" : {
                  "type" : "keyword",
                  "ignore_above" : 256
                }
              }
            },
            "state" : {
              "type" : "keyword",
              "fields" : {
                "keyword" : {
                  "type" : "keyword",
                  "ignore_above" : 256
                }
              }
            }
          }
      }
    }
    View Code

    再将bank中的数据迁移到newbank中

    POST _reindex
    {
      "source": {
        "index": "bank"
        ,"type": "account"
      },
      "dest": {
        "index": "newbank"
      }
    }

    source指定老数据索引,dest指定新索引

    ,"type": "account"之所以加了删除线,是因为新版本不需要指定这个类型,6.0之前的老版本需要指定(我试了一下不加也是可以的)

    数据迁移及查询

     迁移后所有的_type都是_doc了。感觉迁移叫复制比较好,因为老bank数据还存在

     
  • 相关阅读:
    【转】正则基础之——/b 单词边界
    【转】空格变成问号的怪问题
    【转】正则基础之——NFA引擎匹配原理
    【转】 .NET正则基础之——平衡组
    【转】正则基础之——环视
    【转】正则应用之——日期正则表达式
    【转】正则基础之——小数点
    【转】[ ] 字符组(Character Classes)
    【转】正则表达式30分钟入教程
    【转】正则基础之——非捕获组
  • 原文地址:https://www.cnblogs.com/yanan7890/p/15168234.html
Copyright © 2020-2023  润新知