Ram*_*min 1 php jquery scoring elasticsearch booleanquery
我有 3 种类型的数据 [doctor,article,place],我想根据 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"
}
}
}
Run Code Online (Sandbox Code Playgroud)
谢谢你的帮助。
编辑:
错误 :
{
"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
}
Run Code Online (Sandbox Code Playgroud)
我编辑的查询直接从 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"
}
}
}
Run Code Online (Sandbox Code Playgroud)
尝试这个:
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"
}
}
}
Run Code Online (Sandbox Code Playgroud)