Hi I have document of following format:
{
“_id”: “Employee::33243”,
“userID”: 33243,
“type”: “Employee”,
“firstName”: “Kevin”,
“gender” : “M”,
“nationality” : “US”,
“departmentCode” : “DB”,
“birthDate” : “1981-03-26”,
“joiningDate” : “2014-03-29”,
“employeeStatuses”: [
{
“status”: “IN”,
“statusChangedDate”: “2017-07-20T08:20:00Z”,
},
{
“status”: “OUT”,
“statusChangedDate”: “2017-07-20T21:21:00Z”,
},
{
“status”: “IN”,
“statusChangedDate”: “2017-07-21T08:25:00Z”,
},
{
“status”: “OUT”,
“statusChangedDate”: “2017-07-21T20:21:00Z”,
}
.
.
.
.
]
}
and two other documents of similar structure but different ‘type’.
I have created a simple query to show basic details of and their statuses using unnest and combined the results of those three queries using union all
but this query is taking a lot of time. This query is executed every time the report page is loaded and it takes approx. 15 seconds to load. the report has further filtering options on name, gender, date etc.
Select * From
(
Select d.firstName, d.lastName, d.gender, s.status, s.statuschangedDate
From default d
unnest employeeStatuses s
where d.type = ‘Employee’
and d.departmentCode = ‘DB’
Union All
Select d.firstName, d.lastName, d.gender, s.status, s.statuschangedDate
From default d
unnest staffStatuses s
where d.type = ‘Staff’
and d.departmentCode = “HS”
Union All
Select d.firstName, d.lastName, d.gender, s.status, s.statuschangedDate
From default d
unnest visitorStatuses s
where d.type = ‘Visitor’
and d.departmentCode = ‘EE’
) PersonInfo
ORDER BY PersonInfo.firstName ASC LIMIT 10 OFFSET 0;
Can you please suggest me a good index or mapreduce view to improve the query execution time?
*Note : The actual document design and fields are different and sample document is shown here for privacy purpose.