在elasticsearch 8.3版本中声明以下索引:
PUT analyzer_test
{
"settings": {
"index": {
"max_ngram_diff": "30"
},
"analysis": {
"analyzer": {
"ngram_analyzer": {
"tokenizer": "ngram_tokenizer"
}
},
"filter": [
"lowercase"
],
"tokenizer": {
"ngram_tokenizer": {
"token_chars": [
"letter",
"digit"
],
"min_gram": "1",
"max_gram": "30",
"type": "ngram"
}
}
}
},
"mappings": {
"properties": {
"message": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 20
}
},
"analyzer": "ngram_analyzer",
"search_analyzer": "standard"
}
}
}
}
插入一条数据,
POST analyzer_test/_doc/1
{
"message":"DM2860"
}
进行match查询:
GET analyzer_test/_search
{
"query": {
"match": {
"message": "2860"
}
}
}
可以返回数据,
但以下查询为什么查不到数据?
GET analyzer_test/_search
{
"query": {
"match": {
"message": "DM2860"
}
}
}
GET analyzer_test/_search
{
"query": {
"match": {
"message": "DM"
}
}
}
PUT analyzer_test
{
"settings": {
"index": {
"max_ngram_diff": "30"
},
"analysis": {
"analyzer": {
"ngram_analyzer": {
"tokenizer": "ngram_tokenizer"
}
},
"filter": [
"lowercase"
],
"tokenizer": {
"ngram_tokenizer": {
"token_chars": [
"letter",
"digit"
],
"min_gram": "1",
"max_gram": "30",
"type": "ngram"
}
}
}
},
"mappings": {
"properties": {
"message": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 20
}
},
"analyzer": "ngram_analyzer",
"search_analyzer": "standard"
}
}
}
}
插入一条数据,
POST analyzer_test/_doc/1
{
"message":"DM2860"
}
进行match查询:
GET analyzer_test/_search
{
"query": {
"match": {
"message": "2860"
}
}
}
可以返回数据,
但以下查询为什么查不到数据?
GET analyzer_test/_search
{
"query": {
"match": {
"message": "DM2860"
}
}
}
GET analyzer_test/_search
{
"query": {
"match": {
"message": "DM"
}
}
}
1 个回复
charlesfang
赞同来自:
"ngram_analyzer": {
"tokenizer": "ngram_tokenizer",
"filter": "lowercase"
}