我有一个非常奇怪的问题,在我的ElasticSearch查询。我做了一个自动完成搜索在我的网站,我有一个问题。
例如,有一个邻居在我的国家称为“Recreio dos Bandeirantes”当我搜索“bandeirant”(而用户正在键入)查询找到邻居,但是,当完成类型“bandeirantes”找不到相同的邻居。
这是我的查询
{
query: {
bool: {
must: [
{
match: {
'city.name': city,
},
},
{
match: {
'city.state': state,
},
},
{
match: {
keyword: {
query, // The query is 'bandeirant' or 'bandeirantes'
},
},
},
],
},
},
highlight: {
fields: {
keyword: {
number_of_fragments: 9,
},
},
},
size: 20,
}
最终邻域值为“Recreio dos Bandeirantes,Rio de Janeiro,RJ”
此字段的Map如下:
{
"search-neighborhood-01": {
"mappings": {
"properties": {
"city": {
//.....
},
"keyword": {
"type": "text",
"analyzer": "autocomplete",
"search_analyzer": "standard"
},
"name": {
"type": "text",
"analyzer": "autocomplete",
"search_analyzer": "standard"
}
}
}
}
}
我的分析仪设置
{
"search-neighborhood-01": {
"settings": {
"index": {
// .......
"analysis": {
"filter": {
"autocomplete_filter": {
"token_chars": [
"letter"
],
"min_gram": "1",
"type": "edge_ngram",
"max_gram": "10"
}
},
"analyzer": {
"autocomplete": {
"filter": [
"lowercase",
"autocomplete_filter",
"asciifolding"
],
"type": "custom",
"tokenizer": "standard"
}
}
},
// .....
}
}
}
}
我的回应是bandeirant
// .....
{
//.....
"_source": {
"city": {
"name": "Rio de Janeiro",
"state": "RJ",
"keyword": "Rio de Janeiro, RJ"
},
"name": "Recreio dos Bandeirantes",
"keyword": "Recreio dos Bandeirantes, Rio de Janeiro, RJ"
},
"highlight": {
"keyword": [
"Recreio dos <em>Bandeirantes</em>, Rio de Janeiro, RJ"
]
}
}
我的bandeirantes
响应为空:/
我该怎么做才能解决这个问题呢?
谢谢
2条答案
按热度按时间rkkpypqq1#
出现此问题的原因是Ngram过滤器令牌具有
"max_gram": "10"
配置,这意味着长度超过10的单词将不会被索引。我的建议是增加这个数量沿着
“min_gram”
配置。bqf10yzr2#
我把max_ngram改成了20,然后工作了:)