I have projects, and in each project I have tasks, and in each task I have comments. So it looks like:
-> Projects
-> Tasks
-> Comments
I have used nested documents to store the data in the index in Elastic search. My structure looks like this:
PUT projects/
{
"mappings": {
"properties": {
"proj_number": {
"type": "keyword"
},
"proj_name": {
"type": "text"
},
"tasks": {
"type": "nested",
"properties": {
"proj_nam_id": {
"type": "integer"
},
"task_name": {
"type": "text"
},
"proj_tas_id": {
"type": "integer"
},
"comments": {
"type": "nested",
"properties": {
"proj_com_id": {
"type": "integer"
},
"message": {
"type": "text"
},
"task_id": {
"type": "integer"
},
"proj_nam_id": {
"type": "integer"
}
}
}
}
}
}
}
Now I have a task page where I show all tasks of all projects, and there I want to add a search, where if user searches anything and if that searched text is present in task name, or in its comments, then I need to show only those tasks.
So I want that if something is searched from the child then I get its parent's (only those tasks which have searched comments or if its in task name). One more thing that I want is that I have one more page of projects, and there too I need to show all projects and need to add a search box, there if user searches anything, I need to search in projects, tasks and comments, and need to display project in which its task or comment is found. I have tried using inner_hits, and following is my query:
GET projects/_search
{
"query": {
"bool": {
"should": [
{
"nested": {
"path": "tasks",
"query": {
"bool": [
{
"must": [
{
"bool": {
"should": [
{
"multi_match": {
"query": "task",
"lenient": "true",
"fields": [
"tasks.task_name"
],
"type": "best_fields",
"operator": "and"
}
}
]
}
}
]
}
]
},
"inner_hits": {
"size": 100
}
}
},
{
"nested": {
"path": "tasks.comments",
"query": {
"bool": {
"must": [
{
"bool": {
"should": [
{
"multi_match": {
"query": "task",
"lenient": "true",
"fields": [
"tasks.comments.message"
],
"type": "best_fields",
"operator": "and"
}
}
]
}
}
]
}
},
"inner_hits": {
"size": 100
}
}
}
]
}
}
}
But here I have issues:
- I am not getting results as I want, in the inner_hits, I am getting searched comments, and in doc result, I am getting all the tasks, so I will have to filter the tasks (as I want tasks) using task_id from comments. Is there a good way to do it, as I don't think this method is good to proceed.
- We cannot get more than 150 records for inner_hits, as that is its maximum limit.
Please let me know how should I do it. Thanks