I have 2 sets of documents, which are joined by fragmentId . I have written a query that pulls both documents, but I am thinking is there any other way to write it.
Parent Document - There could be only 1 such document which has type = fragment and fragmentId = 1
Multiple Child Documents - All will have type=cf, and fragmentId = 1, they will have start and end values. which will distinguish the children.
GET test/_search
{
"query": {
"bool": {
"minimum_should_match": 1,
"should": [
{
"bool": {
"must": [
{
"term": {
"fragmentId": "1"
}
},
{
"term": {
"type": "fragment"
}
}
]
}
},
{
"bool": {
"must": [
{
"term": {
"fragmentId": "1"
}
},
{
"term": {
"type": "cf"
}
},
{
"range" :{
"start": {
"gte": 1,
"lte": 5
}
}
}
]
}
}
]
}
}
}
In the above query, you can see, I need to duplicate the condition for type and fragment id, as when type=cf, I have to add an extra range filter.
Is there a way to re-write this query in a more simple form, basically a join operation on fragmentId
like a parent-child relationship, with an extra check on child docs.?