有个index的字段是attrs,值是一个List,查询需求是精确匹配,所以在建立index的时候指定了这个字段的type是keyword。但是运行一段时间后type会变成text。
 
从这样:
 
有人知道可能是因为什么造成的吗?
 
我觉得是某个操作让字段启用了multi fields,所以现在创建index的时候,我修改了attrs字段的datatype为如下:
																				从这样:
{
    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"
                }
            }
        }
    }
  }
}
 
	
2 个回复
rochy - rochy_he
赞同来自: juin
你的第一个 Mapping 只针对 _type 为 album 才生效;
第二个 Mapping 是 针对 _type 为 doc 生效。
kaizhang
赞同来自:
改变后变成了下面这样子: