elasticsearch 预测搜索解决方案
elasticsearch predective search solution
尝试进行预测性下拉搜索,如何让搜索始终从左到右开始
例如 "I_kimchy park" , "park"
如果我只搜索 "par" 我必须只得到 park in return ,但在这里我得到了两个词,如何将空 space 视为字符
POST /test1
{
"settings":{
"analysis":{
"analyzer":{
"autocomplete":{
"type":"custom",
"tokenizer":"standard",
"filter":[ "standard", "lowercase", "stop", "kstem", "edgeNgram" ,"whitespace"]
}
},
"filter":{
"ngram":{
"type":"edgeNgram",
"min_gram":2,
"max_gram":15,
"token_chars": [ "letter", "digit"]
}
}
}
}
}
PUT /test1/tweet/_mapping
{
"tweet" : {
"properties" : {
"user": {"type":"string", "index_analyzer" : "autocomplete","search_analyzer" : "autocomplete"}
}
}}
POST /test1/tweet/1
{"user" : "I_kimchy park"}
POST /test1/tweet/3
{ "user" : "park"}
GET /test1/tweet/_search
{
"query": {
"match_phrase_prefix": {
"user": "park"
}
}
}
发生这种情况是因为您的 standard
分词器将您的 user
字段用空格分开。您可以使用 Keyword Tokenizer 将整个字符串视为单个值(单个标记)。
请记住,此更改可能会影响您使用此字段的其他功能。为此,您可能需要添加专用的 "not tokenized" user
字段。
尝试进行预测性下拉搜索,如何让搜索始终从左到右开始 例如 "I_kimchy park" , "park" 如果我只搜索 "par" 我必须只得到 park in return ,但在这里我得到了两个词,如何将空 space 视为字符
POST /test1
{
"settings":{
"analysis":{
"analyzer":{
"autocomplete":{
"type":"custom",
"tokenizer":"standard",
"filter":[ "standard", "lowercase", "stop", "kstem", "edgeNgram" ,"whitespace"]
}
},
"filter":{
"ngram":{
"type":"edgeNgram",
"min_gram":2,
"max_gram":15,
"token_chars": [ "letter", "digit"]
}
}
}
}
}
PUT /test1/tweet/_mapping
{
"tweet" : {
"properties" : {
"user": {"type":"string", "index_analyzer" : "autocomplete","search_analyzer" : "autocomplete"}
}
}}
POST /test1/tweet/1
{"user" : "I_kimchy park"}
POST /test1/tweet/3
{ "user" : "park"}
GET /test1/tweet/_search
{
"query": {
"match_phrase_prefix": {
"user": "park"
}
}
}
发生这种情况是因为您的 standard
分词器将您的 user
字段用空格分开。您可以使用 Keyword Tokenizer 将整个字符串视为单个值(单个标记)。
请记住,此更改可能会影响您使用此字段的其他功能。为此,您可能需要添加专用的 "not tokenized" user
字段。