I have a following index which stores the course details (I have truncated some attributes for brevity):
{
"settings": {
"index": {
"number_of_replicas": "1",
"number_of_shards": "1"
}
},
"aliases": {
"course": {
}
},
"mappings": {
"properties": {
"name": {
"type": "text"
},
"id": {
"type": "integer"
},
"max_per_user": {
"type": "integer"
},
"event_user_id": {
"type": "integer"
},
"event_current_count": {
"type": "integer"
},
"course_event": {
"type": "join",
"relations": {
"course": "event"
}
}
}
}
}
Here max_per_user is number of times a user can complete the course. A user is allowed through a course multiple times but not more than max_per_user for a course. event_current_count tracks the number of times a user has gone through the course. The parent document will have fields - name,id and max_per_user. The child documents will have values for event_user_id and event_current_count . How do I construct a search query to get all parent documents i.e courses for a given user_id where event_current_count<max_per_user
. Basically I have a user_id and for that user I want to find all courses where the user is still eligible.