不要急,总有办法的

字段类型意外的从keyword变成了text

Elasticsearch | 作者 hiwjd | 发布于2018年09月20日 | 阅读数:6315

有个index的字段是attrs,值是一个List,查询需求是精确匹配,所以在建立index的时候指定了这个字段的type是keyword。但是运行一段时间后type会变成text。
 
从这样:
{
album: {
mappings: {
album: {
attrs: {
full_name: "attrs",
mapping: {
attrs: {
type: "keyword"
}
}
}
}
}
}
}
变成了这样:
{
album: {
mappings: {
album: {
attrs: {
full_name: "attrs",
mapping: {
attrs: {
type: "text",
fields: {
keyword: {
type: "keyword",
ignore_above: 256
}
}
}
}
}
}
}
}
}

 
有人知道可能是因为什么造成的吗?
 
我觉得是某个操作让字段启用了multi fields,所以现在创建index的时候,我修改了attrs字段的datatype为如下:
{
"mappings": {
"album": {
"properties": {
"attrs": {
"type": "keyword",
"fields": {
"raw": {
"type": "keyword"
}
}
}
}
}
}
但是最终还是变成了text
已邀请:

rochy - rochy_he

赞同来自: juin

看起来你的 type 都不一样,应该是写入的时候 类型指定错误造成的
 
你的第一个 Mapping 只针对 _type 为 album 才生效;
第二个 Mapping 是 针对 _type 为 doc 生效。

kaizhang

赞同来自:

您好,我也出现了这样的问题,字段的type过一段时间从keyword变成了type,请问是什么原因导致的。
 
改变后变成了下面这样子:
{
"company": {
"mappings": {
"abnormal": {
"properties": {
"abnormalType": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"putDate": {
"type": "date"
},
"putDepartment": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"putReason": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"removeDate": {
"type": "date"
},
"removeDepartment": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"removeReason": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"rid": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"rname": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
}
}
}
}

要回复问题请先登录注册