Как использовать bool Query с function_score в Elasticsearch?

У меня есть 3 типа данных [доктор, статья, место], которые я хочу сопоставить с их документами на основе запроса bool. но я хочу дать типу доктора повышение 3, типу места повышение 2 и статьи повышение 1. У меня есть поисковый запрос, который использует function_score а также bool 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:

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"}
}
}

0

Решение

Попробуй это:

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"}
}
}
3

Другие решения

Других решений пока нет …