es 已有记录增加分词字段
es 已有index,新增字段进行分词
·
项目中接入车辆的抓拍记录,接数据时车牌号直接存入es数据库中,未进行分词。现在需要对车牌号进行模糊查询,通过kibana对es的test索引进行实验。对过程进行整理。
1、关闭索引test
POST test/_close
2、自定义分词器autocomplete
PUT test/_settings
{
"settings": {
"analysis": {
"filter": {
"autocomplete_filter": {
"type": "edge_ngram",
"min_gram": 1,
"max_gram": 20
}
},
"analyzer": {
"autocomplete": {
"type": "custom",
"tokenizer": "standard",
"filter": [
"lowercase",
"autocomplete_filter"
]
}
}
}
}
}
3、增加字段my_text,绑定自定义分词器
PUT test/_mapping
{
"properties": {
"my_text": {
"type": "text",
"analyzer": "autocomplete" ,
"search_analyzer": "standard"
}
}
}
4、打开索引test
POST test/_open
5、将已有的字段carNum 更新到新增字段my_text。
ps:es不支持对已有的字段修改分词器,所以新增字段
POST /test/_update_by_query
{
"query": {
"constant_score": {
"filter": {
"exists": {
"field": "carNum"
}
}
}
},
"script": {
"source": "ctx._source.my_text = ctx._source.carNum",
"lang": "painless"
}
}
6、查看新增字段的分词结果
验证分词结果: GET /{index}/{type}/{id}/_termvectors?fields={fieldName}
查看index是test的id=1021383235722694658的字段fieldName = my_text 的分词结果
GET /test/_doc/1021383235722694658/_termvectors?fields=my_text
更多推荐
已为社区贡献2条内容
所有评论(0)