如何不区分大小写地搜索,但基于原始索引文档返回建议?
例如:搜索“ 贵族奖”,然后建议“ 诺贝尔奖”。
完整示例:
创建索引:
PUT test
{
"settings": {
"index": {
"number_of_shards": 1,
"analysis": {
"analyzer": {
"trigram": {
"type": "custom",
"tokenizer": "standard",
"filter": ["standard", "shingle"]
}
},
"filter": {
"shingle": {
"type": "shingle",
"min_shingle_size": 2,
"max_shingle_size": 3
}
}
}
}
},
"mappings": {
"test": {
"properties": {
"title": {
"type": "text",
"fields": {
"trigram": {
"type": "text",
"analyzer": "trigram"
}
}
}
}
}
}
}
索引文件:
POST test/test?refresh=true
{"title": "Nobel Prize"}
搜索:
POST test/_search
{
"suggest": {
"text": "noble prize",
"simple_phrase": {
"phrase": {
"field": "title.trigram",
"size": 1,
"gram_size": 3,
"direct_generator": [ {
"field": "title.trigram",
"suggest_mode": "always"
} ],
"highlight": {
"pre_tag": "<em>",
"post_tag": "</em>"
}
}
}
}
}
但是不会返回simple_phrase建议。 我希望它返回“诺贝尔奖”(区分大小写):
{
"suggest": {
"simple_phrase": [
{
"text": "noble prize",
"offset": 0,
"length": 11,
"options": [
{
"text": "Nobel Prize",
"highlighted": "<em>Nobel</em> Prize",
"score": 0.5508418
}
]
}
]
}
}