• java
  • go
  • 数据库
  • linux
  • 中间件
  • 书
  • 源码
  • 夕拾

  • java
  • go
  • 数据库
  • linux
  • 中间件
  • 书
  • 源码
  • 夕拾

es mapping

dynamic mapping

类型得自动识别

json类型 es类型
字符串 日期格式—Date , 配置数字为float或long,默认关闭, 设置text,会增加keyword子字段
布尔 boolean
浮点数 float
整数 long
对象 Object
数组 由第一个非空数值得类型决定
空 忽略
1
2
3
4
5
6
7
{
"maapings":{
"_doc":{
"dynamic": false
}
}
}

dynamic三个值,true,false,strict.

true false strict
文档被索引 yes yes no(写入会出错)
字段被索引 yes no no
mapping更新 yes no no

自定义mapping

  • 参考api手册,纯手写
  • 减少工作量
    1. 创建临时index,写入一些样本数据
    2. 访问mapping-api获取mapping定义
    3. 修改后使用
    4. 删除临时索引

控制字段是否被索引

1
2
3
4
5
6
7
8
9
10
{
"mappings": {
"properties":{
"filed1":{
"type":"text",
"index":false //是否被索引,默认为true. 无法按照该字段搜索
}
}
}
}

null

需要对null实现索引

1
2
3
4
5
6
7
8
9
10
{
"mappings": {
"properties":{
"filed1":{
"type":"keyword",//keyword类型支持设定null value
"null_value":"NULL"
}
}
}
}

数组

es不专门提供数组类型,但是任何字段,都可以包含多个相同类型的类型数值

copy_to

copy_to的目标字段不出现在_source中

1
2
3
4
5
6
7
8
9
10
11
12
13
14
{
"mappings": {
"properties":{
"filed1":{
"type":"text",
"copy_to": "filed_total"
},
"filed2":{
"type":"text",
"copy_to": "filed_total"
}
}
}
}

数组类型

倒排索引得不同级别

  • docs - 记录docId
  • freqs - 记录docId和term frequencies
  • positions - 记录docId /term frequencies / term position
  • offsets - doc id / term frequencies / term position / character offects

text类型默认为positions,其他为docs

记录内容越多,占用内存越多

mybatis-sqlSession
filebeat的配置
  1. 1. dynamic mapping
  2. 2. 自定义mapping
    1. 2.1. 控制字段是否被索引
    2. 2.2. null
    3. 2.3. 数组
    4. 2.4. copy_to
    5. 2.5. 数组类型
    6. 2.6. 倒排索引得不同级别
© 2023 haoxp
Hexo theme