gpt4 book ai didi

search - 搜索时保留位置

转载 作者:行者123 更新时间:2023-12-02 22:41:52 25 4
gpt4 key购买 nike

我需要进行Elasticsearch查询以使用多个单词。我正在使用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"
}
}
]
}
}
}

最佳答案

您可以使用boost将数据放在最上面。

{
"query": {
"bool": {
"should": [
{
"query_string": {
"fields": [
"title",
"region"
],
"query":"gold cine",
"boost": 3
}
},
{
"fuzzy": {
"title": {
"value":"gold cine",
"min_similarity": 0.5,
"max_expansions": 50,
"prefix_length": 0
}
}
}
]
}
}
}

如果您使用的是1.0.0。及更高版本,则应使用 function score query

希望能帮助到你..!

关于search - 搜索时保留位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23776517/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com