【发布时间】:2014-05-21 07:19:37
【问题描述】:
我需要使用弹性搜索查询来处理多个单词。我正在使用edgeNgram tokenizer 来支持自动完成功能,并且我正在使用 query_string 进行搜索。
文档
{
"title":"Gold digital cinema",
"region":"Mumbai"
}
{
"title":"cine park",
"region":"Mumbai"
}
{
"title":"Premier Gold",
"region":"mumbai"
}
查询
{
"query": {
"bool": {
"should": [
{
"query_string": {
"fields": [
"title",
"region"
],
"query":"gold cine"
}
},
{
"fuzzy": {
"title": {
"value":"gold cine",
"min_similarity": 0.5,
"max_expansions": 50,
"prefix_length": 0
}
}
}
]
}
}
}
当我搜索黄金电影时,我需要 "title":"Gold digital cinema" 才能出现在顶部结果中。但我得到了"title":"cine park" 和"title":"Premier Gold" 在顶部。
有什么方法可以在搜索时保留位置吗? 提前致谢。
更新
{
"query":{
"bool":{
"should":[{
"query_string":{
"fields":["title.default_title^10",
"title.ngrams_front^2",
"title.ngrams_back"],
"query":"gold cine",
"boost":2
}
},
{
"function_score":{
"query":{
"query_string":{
"fields":["region"],
"query":"MUMBAI"
}
},
"functions":[{
"script_score":{
"script":"_score + 0.6"}
}
],
"score_mode":"max",
"boost_mode":"avg"
}
}
]
}
}
}
【问题讨论】:
标签: search elasticsearch