1
您好,我正在尝试设置一个搜索框,它将对某些字段执行部分搜索并对其他字段执行标准搜索。我快到了,但我不能让过去的以下障碍:弹性不匹配初始字符的多匹配查询
这是我的索引:
PUT /my_index
{
"mappings": {
"blogpost": {
"properties": {
"firstname": {
"fields": {
"autocomplete": {
"index_analyzer": "autocomplete",
"type": "string"
},
"firstname": {
"index_analyzer": "standard",
"type": "string"
}
},
"type": "string"
}
}
}
},
"settings": {
"index": {
"analysis": {
"analyzer": {
"autocomplete": {
"tokenizer": "ngram_tokenizer",
"type": "custom"
},
"standard": {
"type": "standard"
}
},
"tokenizer": {
"ngram_tokenizer": {
"max_gram": "20",
"min_gram": "2",
"type": "nGram"
}
}
},
"creation_date": "1431690991641",
"number_of_replicas": "0",
"number_of_shards": "3",
"uuid": "W4Ug6IadS9mYuN5_Pqlhow",
"version": {
"created": "1040499"
}
}
}
}
指数1号文件:
PUT /my_index/blogpost/1
{"firstname" : "Albert"}
简单的查询:
/_search?q=Albert
返回Albert。都好。
Multi_match查询:
{
"query": {
"multi_match": {
"query": "Albert",
"fields": [
"firstname",
"firstname.autocomplete"
]
}
}
}
也返回伟业。都好。
如果我用伯特替代艾伯特,它会返回艾伯特。都好。
但是“Al”或“al”或“Alber”或“alber”不会!包含开头字母的任何搜索都会失败。
然而
/my_index/_search?firstname.autocomplete:Al
都好。
请帮忙。