gpt4 book ai didi

elasticsearch - 用于Elasticsearch的Elastic-Builder npm的functionScoreQuery的查询

转载 作者:行者123 更新时间:2023-12-03 01:28:22 25 4
gpt4 key购买 nike

我正在使用由Elastic-builder npm提供的functionScoreQuery来查询我的elasticsearch,正在创建查询,但无法为我的查询获取外部查询参数,如下所示。

即缺少外部查询参数,这就是为什么查询不执行的原因,因此我不得不在我的 body 中手动附加查询{}。因此,如果有人可以帮助我并告诉我我在npm查询中缺少的内容以获取那些查询参数。

var not_body = elasticbuilder.functionScoreQuery()
.query(elasticbuilder.matchAllQuery())
.functions([
elasticbuilder.weightScoreFunction()
.filter(elasticbuilder.boolQuery().mustNot([
elasticbuilder.hasChildQuery(
elasticbuilder.boolQuery().must([
elasticbuilder.matchPhraseQuery("name", "raju" )
])
).type('student')
]))
.weight(2),

elasticbuilder.weightScoreFunction()
.filter(elasticbuilder.boolQuery().must([
elasticbuilder.hasChildQuery(
elasticbuilder.boolQuery().must([
elasticbuilder.matchPhraseQuery("class", "12")
])
).type('info')
]))
.weight(2)
]).minScore(4).scoreMode('sum');

通过此查询的当前输出主体:
  {
"function_score": {
"functions": [
{
"filter": {
"bool": {
"must_not": {
"has_child": {
"query": {
"bool": {
"must": {
"match_phrase": {
"name" : "raju"
}
}
}
},
"type": "student"
}
}
}
},
"weight": 2
},
{
"filter": {
"bool": {
"must": {
"has_child": {
"query": {
"bool": {
"must": {
"match_phrase": {
"class" : "12"
}
}
}
},
"type": "info"
}
}
}
},
"weight": 2
}
],
"query": {
"match_all": {}
},
"min_score": 4,
"score_mode": "sum"
}
}

预期输出主体:
{    
"query": {
"function_score": {
"functions": [
{
"filter": {
"bool": {
"must_not": {
"has_child": {
"query": {
"bool": {
"must": {
"match_phrase": {
"name" : "raju"
}
}
}
},
"type": "student"
}
}
}
},
"weight": 2
},
{
"filter": {
"bool": {
"must": {
"has_child": {
"query": {
"bool": {
"must": {
"match_phrase": {
"class" : "12"
}
}
}
},
"type": "info"
}
}
}
},
"weight": 2
}
],
"query": {
"match_all": {}
},
"min_score": 4,
"score_mode": "sum"
}
}
}

最佳答案

您应该将其包装在elasticbuilder.requestBodySearch()

就你而言

elasticbuilder.requestBodySearch().query(not_body)

应该做的工作

关于elasticsearch - 用于Elasticsearch的Elastic-Builder npm的functionScoreQuery的查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57389773/

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