คำถามเกี่ยวกับ functionScoreQuery ของ elastic-builder npm สำหรับ elasticsearch

ฉันกำลังใช้ 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"
}
}
}

person Yash Tandon    schedule 07.08.2019    source แหล่งที่มา


คำตอบ (1)


คุณควรล้อมสิ่งนี้ด้วย elasticbuilder.requestBodySearch()

ในกรณีของคุณ

elasticbuilder.requestBodySearch().query(not_body)

ควรจะทำงาน

person Pierre Mallet    schedule 07.08.2019
comment
คุณช่วยฉันเกี่ยวกับปัญหานี้ได้ไหม ลิงก์: stackoverflow.com/q/57691108/11432290 - person Yash Tandon; 28.08.2019
comment
@YashTandon ใช้โซลูชันของ Val มันเป็นวิธีที่ดี และอย่าใช้ความคิดเห็นเพื่อชี้คำถามใหม่ๆ มันไม่ใช่จุดประสงค์ของพวกเขา - person Pierre Mallet; 28.08.2019
comment
เขาตอบหลังจากที่ฉันโพสต์ความคิดเห็นนี้ นอกจากนี้ ฉันไม่พบวิธีใด ๆ เพื่อที่จะสามารถแบ่งปันคำถามของฉันกับคุณได้ ดังนั้นฉันจึงคิดว่าจะโพสต์ไว้ที่นี่ ขอบคุณสำหรับเวลาของคุณ - person Yash Tandon; 28.08.2019