ฉันกำลังใช้ functionScoreQuery ที่จัดทำโดย elastic-builder npm เพื่อสืบค้น elasticsearch ของฉัน กำลังสร้างแบบสอบถาม แต่ฉันไม่สามารถรับพารามิเตอร์การสืบค้นภายนอกสำหรับการสืบค้นของฉันดังที่แสดงด้านล่าง
นั่นคือพารามิเตอร์การสืบค้นภายนอกหายไป และนั่นคือสาเหตุที่การสืบค้นไม่ทำงาน ดังนั้นฉันจึงต้องต่อท้ายการสืบค้น { } ในร่างกายของฉันด้วยตนเอง ดังนั้นถ้าใครสามารถช่วยฉันและบอกฉันว่าฉันขาดอะไรไปในการสืบค้น 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"
}
}
}