Php 如何在Elasticsearch中使用带有函数_分数的布尔查询?
我有3种类型的数据[医生、文章、地点],我希望基于bool查询匹配它们的文档。但是我想给doctor type增加3,place type增加2,article增加1。我有一个搜索查询,它使用Php 如何在Elasticsearch中使用带有函数_分数的布尔查询?,php,jquery,
elasticsearch,scoring,booleanquery,Php,Jquery,
elasticsearch,Scoring,Booleanquery,我有3种类型的数据[医生、文章、地点],我希望基于bool查询匹配它们的文档。但是我想给doctor type增加3,place type增加2,article增加1。我有一个搜索查询,它使用function\u score和bool Query匹配文档。但问题是它抛出了一个异常,即没有注册名为[bool]的函数。。我的问题是: GET /my_index/doctor,article,place/_search { "query": { "function_score"
function\u score
和bool Query
匹配文档。但问题是它抛出了一个异常,即没有注册名为[bool]的函数。。我的问题是:
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
}
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"
}
}
}
我编辑的查询直接复制自惊奇漫画感知:
{
"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
}
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"
}
}
}
试试这个:
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"
}
}
}
我看到了你的第一篇帖子(最后被删除了),我仍然不明白你想做什么。也许,您已经在es网站上看到了关于
函数评分的语法,您得到的错误应该不会让您感到惊讶。你到底想用你的数据和这个查询做什么?@andrestefan,我想用bool query搜索文档,但不同类型的文档需要不同的boost。不,用真实数据解释。“我有医生、文章和地方,我想……”Andreestefan,完成了,请再看一看。这三种类型都有一个标题字段?我看到了你的第一篇帖子(最后被删除),我仍然不明白你想做什么。也许,您已经在es网站上看到了关于函数评分的语法,您得到的错误应该不会让您感到惊讶。你到底想用你的数据和这个查询做什么?@andrestefan,我想用bool query搜索文档,但不同类型的文档需要不同的boost。不,用真实数据解释。“我有医生、文章和地方,我想……”Andreastefan,完成了,请再看一看。这三种类型都有一个标题字段?现在它抛出另一个异常,表示嵌套:QueryParsingException[[my_index]没有注册名为[weight]的函数。]该查询对我有效。确保你的拷贝粘贴正确。我已经三次检查了我的请求。感谢您的尝试,但它在PostES的编辑部分给出了错误您使用的是什么版本?版本号:“1.3.4”现在它引发另一个异常,该异常表示嵌套:QueryParsingException[[my_index]没有注册名为[weight]的函数。]该查询对我有效。确保你的拷贝粘贴正确。我已经三次检查了我的请求。感谢您的尝试,但在PostES的编辑部分出现错误您使用的是什么版本?版本号:“1.3.4”