
Elasticsearch 显式Mapping设置与常见参数介绍
如何显示的定义一个Mapping
Put movies
{
"mappings" {
//define your mappings here
}
}
自定义Mapping的一些建议
- 可以参考 API 手册,纯手写
- 为了减少输入的工作量,减少出错概率,可以依照以下步骤
- 创建一个临时的 index,写入一些样本数据
- 通过访问 Mapping API 获得该临时文件的动态Mapping定义
- 修改后用,使用该配置创建你的索引
- 删除临时索引
控制当前字段是否被索引
index -控制当前字段是否被索引。默认为true。如果设置成false,该字段不可被搜索。举例,这里不允许mobile字段被索引。
PUT users
{
mappings: {
"properties": {
"firstName": {
"type": "text"
},
"lastName": {
"type": "text"
},
"mobile": {
"type": "text",
"index": false
}
}
}
}
index Options
PUT users
{
mappings: {
"properties": {
"firstName": {
"type": "text"
},
"lastName": {
"type": "text"
},
"mobile": {
"type": "text",
"index": false
},
"bio": {
"type": "text",
"index_options": "offsets"
}
}
}
}
四种不同级别的 Index Options 配置,可以控制倒排索引记录的内容
docs | 记录 doc id |
freqs | 记录 doc id 和 term frequencies |
positions | 记录 doc id / term frequencies / term position |
offsets | doc id /term frequencies / term posistion / character offects |
Text 类型默认记录 postions,其他默认为 docs
需要注意的是:记录内容越多,占用存储空间越大
关于Null_value
当我们需要对Null值实现搜索时我们可以这样做
PUT users
{
mappings: {
"properties": {
"name": {
"type": "text"
},
"mobile": {
"type": "keyword",
"null_value": "NULL"
}
}
}
}
#查询出数据
GET users/_search?q=mobile:NULL
只有Keyword类型支持设定 Null_Value
Copy_to 设置
PUT users
{
mappings: {
"properties": {
"firstName": {
"type": "text",
"copy_to": "fullName"
},
"lastName": {
"type": "text",
"copy_to": "fullName"
}
}
}
}
#查询
Get users/_search?q=fullName:(Bob He)
- _all 在 7 中被 copy_to 所替代
- 满足一些特定的搜索需要
- copy_to 将字段的数值拷贝到目标字段,实现类似_all的作用
- copy_to 的目标字段(fullName)不出现在_source中
数组类型
Elasticsearch中不提供专门的数组类型。但是任何字段,都可以包含多个相同类型的数值
Put users/_doc/1
{
"name":"onebird",
"iinterests":"reading"
}
Put users/_doc/2
{
"name": "twobirds",
"interests":["reading","music"]
}
欢迎加群讨论技术,1群:677373950(满了,可以加,但通过不了),2群:656732739
评价
排名
2
文章
657
粉丝
44
评论
93
docker中Sware集群与service
尘叶心繁 : 想学呀!我教你呀
一个bug让程序员走上法庭 索赔金额达400亿日元
叼着奶瓶逛酒吧 : 所以说做程序员也要懂点法律知识
.net core 塑形资源
剑轩 : 收藏收藏
映射AutoMapper
剑轩 :
好是好,这个对效率影响大不大哇,效率高不高
一个bug让程序员走上法庭 索赔金额达400亿日元
剑轩 : 有点可怕
ASP.NET Core 服务注册生命周期
剑轩 :
http://www.tnblog.net/aojiancc2/article/details/167
ICP备案 :渝ICP备18016597号-1
网站信息:2018-2025TNBLOG.NET
技术交流:群号656732739
联系我们:contact@tnblog.net
公网安备:
50010702506256


欢迎加群交流技术