zoukankan      html  css  js  c++  java
  • 谷粒商城学习——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数据还存在

     
  • 相关阅读:
    Rman-10038: Database Session For Channel D1 Terminated Unexpectedly
    MySQL从入门到项目实践 pdf下载
    Oracle_优化器使用(oracle11g)
    当sqlserver启用sa账户时,出现Microsoft SQL Server 错误代号: 15535 解决方法 (转)
    sqlserver 如何分析“死锁调度程序”转储?
    AtCoder Beginner Contest 213
    LOJ
    [学习笔记] 计算几何
    [COCI 2009-2010 #6] XOR
    BZOJ
  • 原文地址:https://www.cnblogs.com/yanan7890/p/15168234.html
Copyright © 2011-2022 走看看