OddFar's Notes OddFar's Notes
首页
  • Java-Se

    • Java基础
    • Java面向对象
    • Java常用类
    • Java集合框架
  • Java-Se进阶

    • JUC多线程
  • Java-ee

    • JavaWeb
  • SQL 数据库

    • MySQL
  • NoSQL 数据库

    • Redis
    • ElasticSearch
    • MongoDB
  • 数据库

    • MyBatis
    • MyBatis-Plus
  • Spring

    • Spring
  • 中间件

    • RabbitMQ
  • Git
  • Docker
  • Jenkins
爬虫
  • Campus (opens new window)
  • 校园信息墙 (opens new window)
关于
归档
GitHub (opens new window)
首页
  • Java-Se

    • Java基础
    • Java面向对象
    • Java常用类
    • Java集合框架
  • Java-Se进阶

    • JUC多线程
  • Java-ee

    • JavaWeb
  • SQL 数据库

    • MySQL
  • NoSQL 数据库

    • Redis
    • ElasticSearch
    • MongoDB
  • 数据库

    • MyBatis
    • MyBatis-Plus
  • Spring

    • Spring
  • 中间件

    • RabbitMQ
  • Git
  • Docker
  • Jenkins
爬虫
  • Campus (opens new window)
  • 校园信息墙 (opens new window)
关于
归档
GitHub (opens new window)
  • MySQL

  • Redis

  • ElasticSearch

    • ElasticSearch - 知识体系
    • ES - ElasticSearch基础概念
    • ES - 安装ElasticSearch
    • ES - 索引和文档的基本操作
    • ES - 高级查询操作
    • ES - 索引管理
      • Mapping
        • 字段类型
        • 映射
      • 索引管理操作
      • 数据迁移
    • ES - 分词
  • MongoDB

  • 数据库
  • ElasticSearch
zhiyuan
2022-07-28
目录

ES - 索引管理

  • Mapping
    • 字段类型
    • 映射
  • 索引管理操作
  • 数据迁移

# Mapping

# 字段类型

官方文档:https://www.elastic.co/guide/en/elasticsearch/reference/7.17/mapping-types.html

核心数据类型

  • 字符串

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

  • 数值型

    整型: byte,short,integer,long 浮点型: float, half_float, scaled_float,double

  • 日期类型:date

  • 范围型

    integer_range, long_range, float_range,double_range,date_range

    gt是大于,lt是小于,e是equals等于。

    age_limit的区间包含了此值的文档都算是匹配。

  • 布尔

    boolean

  • 二进制

    binary 会把值当做经过 base64 编码的字符串,默认不存储,且不可搜索

复杂数据类型

  • 对象

    object一个对象中可以嵌套对象。

  • 数组

    Array:嵌套类型

    nested 用于json对象数组

# 映射

Mapping(映射)是用来定义一个文档(document),以及它所包含的属性(field)是如何存储和索引的。

看mapping信息:

GET bank/_mapping
1

# 索引管理操作

  • 创建索引并指定映射
PUT /my_index
{
  "mappings": {
    "properties": {
      "age": {
        "type": "integer"
      },
      "email": {
        "type": "keyword" # 指定为keyword
      },
      "name": {
        "type": "text" # 全文检索。保存时候分词,检索时候进行分词匹配
      }
    }
  }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
  • 查看映射
GET /my_index
1
  • 添加新的字段映射
PUT /my_index/_mapping
{
  "properties": {
    "employee-id": {
      "type": "keyword",
      "index": false # 字段不能被检索。检索
    }
  }

1
2
3
4
5
6
7
8
9

该index选项控制字段值是否被索引。它接受true orfalse并默认为true. 未编入索引的字段不可查询。

  • 修改映射

    不能更新映射,对于已经存在的字段映射不能更新。

    更新必须创建新的索引,进行数据迁移。

# 数据迁移

官方文档:https://www.elastic.co/guide/en/elasticsearch/reference/7.16/docs-reindex.html

先创建new_twitter的正确映射。

然后使用如下方式进行数据迁移,把twitter迁移到new_twitters

POST _reindex
{
  "source":{
      "index":"twitter"
   },
  "dest":{
      "index":"new_twitters"
   }
}
1
2
3
4
5
6
7
8
9
在 GitHub 上编辑此页 (opens new window)
最后更新: 2022/08/07, 3:08:00
ES - 高级查询操作
ES - 分词

← ES - 高级查询操作 ES - 分词→

Theme by Vdoing | Copyright © 2021-2023 oddfar | 冀ICP备20001094号
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式