使用edge-ngram索引时,通常还希望按匹配百分比对结果进行排名。 例如: 输入是 应用 苹果, aa
如果查询为aa,则排名应为 aa> appl>苹果
但是默认排名使用的是tfidf,因此排名是相同的。
PUT my_index
{
"settings": {
"analysis": {
"analyzer": {
"autocomplete": {
"tokenizer": "autocomplete","filter": [
"lowercase"
]
},"autocomplete_search": {
"tokenizer": "lowercase"
}
},"tokenizer": {
"autocomplete": {
"type": "edge_ngram","min_gram": 2,"max_gram": 10,"token_chars": [
"letter"
]
}
}
}
},"mappings": {
"properties": {
"title": {
"type": "text","analyzer": "autocomplete","search_analyzer": "autocomplete_search"
}
}
}
}
PUT my_index/_doc/1
{
"title": "apple"
}
PUT my_index/_doc/2
{
"title": "appl"
}
GET my_index/_search
{
"query": {
"match": {
"title": {
"query": "ap","operator": "and"
}
}
}
}
结果是 苹果和苹果,他们的分数都一样