gpt4 book ai didi

php - ElasticSearch查询以搜索父文档并认为至少有一个 child

转载 作者:行者123 更新时间:2023-12-02 23:30:24 25 4
gpt4 key购买 nike

我在elasticsearch中实现了父子关系船,父类型名称是participant_tests,其子类型名称是participant_test_question_answers,我对父类型有一些搜索条件,如下所示:

query": {
"bool":{
"should":[
{
"range":{
"created_at":{
"gte":"2016-01-01",
"lte":"2016-05-11",
"format":"YYYY-MM-dd"
}
}
},
{
"terms":{
"created_by.id":["1000001"]
}
},
{
"multi_match":{
"query":"test human time",
"fields":[
"course_tests.course_id.course_no",
"participant_test_questions.answer_text",
"participants.first_name",
"participants.last_name",
"participants.promote_unique_user_id","result"
],
"operator":"OR"
}
}
]
}
}

以上查询返回结果,但是如果我要检查 has_child,则没有返回结果。
我在 bool类之后添加了这些行。
"has_child": {
"type": "participant_test_question_answers",
"min_children": 1,
"query": {
"match_all": {}
}
}

最佳答案

试试这个查询:

{
"query": {
"bool": {
"should": [
{
"range": {
"created_at": {
"gte": "2016-01-01",
"lte": "2016-05-11",
"format": "YYYY-MM-dd"
}
}
},
{
"terms": {
"created_by.id": [
"1000001"
]
}
},
{
"multi_match": {
"query": "test human time",
"fields": [
"course_tests.course_id.course_no",
"participant_test_questions.answer_text",
"participants.first_name",
"participants.last_name",
"participants.promote_unique_user_id",
"result"
],
"operator": "OR"
}
}
],
"must": [
{
"has_child": {
"type": "participant_test_question_answers",
"min_children": 1,
"query": {
"match_all": {}
}
}
}
]
}
}
}

关于php - ElasticSearch查询以搜索父文档并认为至少有一个 child ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37161431/

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