三、ElasticSerach-映射操作

上一章学习了Es的文档操作,ElasticSerach-文档操作,本章我们来学习索引中映射的操作

1、创建映射

######创建索引

#创建索引
PUT /my_index_mapping


#查看索引
get /my_index_mapping


#查看索引结果
{
  "my_index_mapping" : {
    "aliases" : { },
    "mappings" : { },#没有添加映射的时候,mappings没有相应的映射
    "settings" : {
      "index" : {
        "creation_date" : "1650800495453",
        "number_of_shards" : "1",
        "number_of_replicas" : "1",
        "uuid" : "pBmFJEmAQMWmnYBUbE6vBg",
        "version" : {
          "created" : "7080099"
        },
        "provided_name" : "my_index_mapping"
      }
    }
  }
}

######新增映射

#新增映射
POST /my_index_mapping/_mapping
{
  "properties" : {
         "id" : {"type":"integer"},
         "first_name" : {"type":"text"},
         "last_name" : {"type":"text"},
         "age" : {"type":"integer"},
         "about" : {"type":"text"},
         "interests" : {"type":"text"}
       } 
}

#再次查看索引结果为
{
  "my_index_mapping" : {
    "aliases" : { },
    "mappings" : {
      "properties" : {
        "about" : {
          "type" : "text"
        },
        "age" : {
          "type" : "integer"
        },
        "first_name" : {
          "type" : "text"
        },
        "id" : {
          "type" : "integer"
        },
        "interests" : {
          "type" : "text"
        },
        "last_name" : {
          "type" : "text"
        }
      }
    },
    "settings" : {
      "index" : {
        "creation_date" : "1650799809497",
        "number_of_shards" : "1",
        "number_of_replicas" : "1",
        "uuid" : "cH4nc2PEQSKv5kxDV3REIw",
        "version" : {
          "created" : "7080099"
        },
        "provided_name" : "my_index_mapping"
      }
    }
  }
}

######映射数据说明

  • 字段名:任意填写,下面指定许多属性,例如:titlesubtitleimagesprice
  • type :类型, Elasticsearch 中支持的数据类型非常丰富
  1. String 类型,又分两种:text:可分词,keyword :不可分词,数据会作为完整字段进行匹配
  2. Numerical:数值类型,分两类  
    基本数据类型: long integer short byte double float half_float
    浮点数的高精度类型: scaled_float
  3. Data:日期类型
  4. Array:数组类型
  5. Object:对象
  • index :是否索引,默认为 true ,也就是说你不进行任何配置,所有字段都会被索引。
  1. true :字段会被索引,则可以用来进行搜索
  2. false :字段不会被索引,不能用来搜索
  • store :是否将数据进行独立存储,默认为 false
    原始的文本会存储在_source 里面,默认情况下其他提取出来的字段都不是独立存储 的,是从 _source 里面提取出来的。当然你也可以独立的存储某个字段,只要设置 "store": true 即可,获取独立存储的字段要比从 _source 中解析快得多,但是也会占用 更多的空间,所以要根据实际业务需求来设置。

    2、查看映射

    #查看映射
    get /my_index_mapping/_mapping
    
    {
      "my_index_mapping" : {
        "mappings" : {
          "properties" : {
            "about" : {
              "type" : "text"
            },
            "age" : {
              "type" : "integer"
            },
            "first_name" : {
              "type" : "text"
            },
            "id" : {
              "type" : "integer"
            },
            "interests" : {
              "type" : "text"
            },
            "last_name" : {
              "type" : "text"
            }
          }
        }
      }
    }
    

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值