Hi all!
I'm trying to solve a problem of searching across 2 'entities' and sorting
and paging the results. I have been unable to come up with a solution so
far, so thought I would ask here, and would greatly appreciate anyone's
help!
I have considered storing these entities in various ways; as separate
documents (using a parent/child relationship), as a combined document and
as nested documents. In each case I hit problems!
The complexity is around how we want to group, sort, page and count the
results.
I have tried to outline the problem below.
Please let me know what you think!
Cheers, James.
curl -XPUT localhost:9200/jobs/company/1 -d'{
"name": "Company A",
"location": "America"
}'
curl -XPUT localhost:9200/jobs/company/2 -d'{
"name": "Company B",
"location": "Britain"
}'
curl -XPUT localhost:9200/jobs/employee/1 -d'{
"name": "Alice",
"job_title": "Astronaut"
}'
curl -XPUT localhost:9200/jobs/employee/2 -d'{
"name": "Bob",
"job_title": "Builder"
}'
====
Alice works for Company A and Company B
Bob works for Company B
The relationship between Employee and Company is many-to-many.
====
Example search: Employees that are Astronauts that work for Companies in
America or Britain
Desired result count: 1 (Only 1 Alice, despite the fact she works for 2
Companies)
Desired display:
Company A |
---|
Alice |
Company B |
---|
Alice |
So the result count is the count of unique Employees, and each page should
display a fixed number of Employees, but the results are grouped by Company
and primarily sorted by properties of Company (name, location etc.)
Example search: All
Company A |
---|
Alice |
Company B |
---|
Alice |
Bob |
--