gpt4 book ai didi

php - 如何在 Elasticsearch 中使用带有 function_score 的 bool 查询?

转载 作者:行者123 更新时间:2023-12-03 00:33:49 26 4
gpt4 key购买 nike

我有 3 种类型的数据 [doctor,article,place],我想根据 bool 查询匹配它们的文档。但我想给医生类型提升 3,地点类型提升 2,文章提升 1。我有一个使用 function_scorebool query 的搜索查询来匹配文档。但问题是它抛出一个异常,提示 No function with the name [bool] is registered.。这是我的查询:

GET /my_index/doctor,article,place/_search
{
"query": {
"function_score": {
"bool": {
"should":
[
{
"common": {
"title": {
"query":"$q",
"cutoff_frequency": 0.001,
"low_freq_operator": "and"
}
}
},
{
"prefix": {
"title": "$q"
}

},
{
"match_phrase_prefix" : {
"title" : {
"query": "$q",
"slop": 10
}
}
}
]
},
"functions":[
{
"filter":{
"type":{
"value":"doctor"
}
},
"weight":3
},
{
"filter":{
"type":{
"value":"place"
}
},
"weight":2
},
{
"filter":{
"type":{
"value":"article"
}
},
"weight":1
}
],
"score_mode":"first",
"boost_mode":"multiply"
}
}
}

感谢您的帮助。

编辑:

错误:

{
"error": "SearchPhaseExecutionException[Failed to execute phase [query], all shards failed;
shardFailures {[fWqkaeoLSva_QwhrYHnG3A][darmanjoo][0]:
SearchParseException[[darmanjoo][0]: from[-1],size[-1]:
Parse Failure [Failed to parse source [
{
"query": {
"function_score": {
"query": {
"bool": {
"should": [
{
"common": {
"title": {
"query": "دکتر",
"cutoff_frequency": 0.001,
"low_freq_operator": "and"
}
}
},
{
"prefix": {
"title": "دکتر"
}
},
{
"match_phrase_prefix": {
"title": {
"query": "دکتر",
"slop": 10
}
}
}
]
}
},
"functions": [
{
"filter": {
"type": {
"value": "doctor"
}
},
"weight": 3
},
{
"filter": {
"type": {
"value": "place"
}
},
"weight": 2
},
{
"filter": {
"type": {
"value": "article"
}
},
"weight": 1
}
],
"score_mode": "first",
"boost_mode": "multiply"
}
}
}
]]];
nested: QueryParsingException[[darmanjoo] No function with the name [weight] is registered.]; }{[fWqkaeoLSva_QwhrYHnG3A][darmanjoo][1]:
SearchParseException[[darmanjoo][1]: from[-1],size[-1]:
Parse Failure [Failed to parse source [
{
"query": {
"function_score": {
"query": {
"bool": {
"should": [
{
"common": {
"title": {
"query": "دکتر",
"cutoff_frequency": 0.001,
"low_freq_operator": "and"
}
}
},
{
"prefix": {
"title": "دکتر"
}
},
{
"match_phrase_prefix": {
"title": {
"query": "دکتر",
"slop": 10
}
}
}
]
}
},
"functions": [
{
"filter": {
"type": {
"value": "doctor"
}
},
"weight": 3
},
{
"filter": {
"type": {
"value": "place"
}
},
"weight": 2
},
{
"filter": {
"type": {
"value": "article"
}
},
"weight": 1
}
],
"score_mode": "first",
"boost_mode": "multiply"
}
}
}
]]];
nested: QueryParsingException[[darmanjoo] No function with the name [weight] is registered.]; }{[fWqkaeoLSva_QwhrYHnG3A][darmanjoo][4]:
SearchParseException[[darmanjoo][4]: from[-1],size[-1]:
Parse Failure [Failed to parse source [
{
"query": {
"function_score": {
"query": {
"bool": {
"should": [
{
"common": {
"title": {
"query": "دکتر",
"cutoff_frequency": 0.001,
"low_freq_operator": "and"
}
}
},
{
"prefix": {
"title": "دکتر"
}
},
{
"match_phrase_prefix": {
"title": {
"query": "دکتر",
"slop": 10
}
}
}
]
}
},
"functions": [
{
"filter": {
"type": {
"value": "doctor"
}
},
"weight": 3
},
{
"filter": {
"type": {
"value": "place"
}
},
"weight": 2
},
{
"filter": {
"type": {
"value": "article"
}
},
"weight": 1
}
],
"score_mode": "first",
"boost_mode": "multiply"
}
}
}
]]];
nested: QueryParsingException[[darmanjoo] No function with the name [weight] is registered.]; }]",
"status": 400
}

我直接从 MARVEL SENSE 复制的编辑查询:

GET /darmanjoo/doctor,article,place/_search
{
"query": {
"function_score": {
"query": {
"bool": {
"should": [
{
"common": {
"title": {
"query": "$q",
"cutoff_frequency": 0.001,
"low_freq_operator": "and"
}
}
},
{
"prefix": {
"title": "$q"
}
},
{
"match_phrase_prefix": {
"title": {
"query": "$q",
"slop": 10
}
}
}
]
}
},
"functions": [
{
"filter": {
"type": {
"value": "doctor"
}
},
"weight": 3
},
{
"filter": {
"type": {
"value": "place"
}
},
"weight": 2
},
{
"filter": {
"type": {
"value": "article"
}
},
"weight": 1
}
],
"score_mode": "first",
"boost_mode": "multiply"
}
}
}

最佳答案

试试这个:

GET /my_index/doctor,article,place/_search
{
"query": {
"function_score": {
"query": {
"bool": {
"should": [
{
"common": {
"title": {
"query": "$q",
"cutoff_frequency": 0.001,
"low_freq_operator": "and"
}
}
},
{
"prefix": {
"title": "$q"
}
},
{
"match_phrase_prefix": {
"title": {
"query": "$q",
"slop": 10
}
}
}
]
}
},
"functions": [
{
"filter": {
"type": {
"value": "doctor"
}
},
"boost_factor": 3
},
{
"filter": {
"type": {
"value": "place"
}
},
"boost_factor": 2
},
{
"filter": {
"type": {
"value": "article"
}
},
"boost_factor": 1
}
],
"score_mode": "first",
"boost_mode": "multiply"
}
}
}

关于php - 如何在 Elasticsearch 中使用带有 function_score 的 bool 查询?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27187680/

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