Php 弹性搜索查询搜索父文档并考虑至少有一个孩子
我已经在elasticsearch中实现了父子关系,父类型名称为Php 弹性搜索查询搜索父文档并考虑至少有一个孩子,php,laravel,
elasticsearch,Php,Laravel,
elasticsearch,我已经在elasticsearch中实现了父子关系,父类型名称为participant\u tests,其子类型名称为participant\u test\u question\u answers,我对父类型的搜索条件如下: query": { "bool":{ "should":[ { "range":{ "created_at":{ "gte":"2016-01-01", "lte
participant\u tests
,其子类型名称为participant\u test\u question\u 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"
}
}
]
}
}
上面的查询返回结果,但如果我想检查是否有子项
则未返回结果。
我在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": {}
}
}
}
]
}
}
}
您使用的完整查询是什么?