创建 mapping 时,可以为字符串(专指 keyword) 指定 ignore_above ,用来限定字符长度。超过 ignore_above 的字符会被存储,但不会被索引。
创建索引
127.0.0.1:9200/ceshi put请求
创建映射
127.0.0.1:9200/ceshi/_mapping put请求
body
{
"properties": {
"name": {
"type": "keyword",
"ignore_above": 10, //超过10个字符串长度
"index": true
}
}
}
创建数据
127.0.0.1:9200/ceshi/_doc/_bulk
body
{"index": {}}
{"name":"0123456"}
{"index": {}}
{"name":"0123456789"}
{"index": {}}
{"name":"01234567890"} //操作了10个
查询数据
127.0.0.1:9200/ceshi/_search
{
"query":{
"match":{
"name":"0123456" //可以查到数据,只有一条{"name":"0123456"}
//01234567890 查询不到了,因为操过10个字符,该值不能被索引
}
}
}
网友评论