Joining of documents in search results


(Sandeep Reddy) #1

We have a requirement where we need to combine the documents in search results. Below example depicts it.

Assuming we have two documents say
Teachers.json
{
"id": "Teacher1",
"contextType": "Teacher",
"Subject" : "English"
"foreign_key": [
"Student1"
]
}

Student1.json
{
"id": "Student1",
"contextType": "STUDENT"
}
So, the requirement is that we need to display the combined output in a single document, as below

"response": {
"numFound": 1,
"start": 0,
"docs": [
{
"id": "Teacher1",
"contextType": "TEACHER",
"Subject" : "English",
"Student":[{
"id": "Student1",
"contextType": "STUDENT"
}],
}
]
}

I tried using parent child relationships in elastic search, but didnt had any luck.
Please let me know if this is possible in elastic search

P.S : I am new bie to elastic search


(Mark Walkom) #2

It's not possible.


(Geunmoon Oh) #3

it's not possible.
but, how about using nested object like below?

{
"id": "Teacher1",
"contextType": "Teacher",
"Subject" : "English"
"student_nested": [
{
"id": "Student1",
"contextType": "STUDENT"
}
]
}


(Martijn Van Groningen) #4

It isn't possible to join arbitrary document in the response.
However with either nested or parent/child it is possible to inline the children docs into the parent hit with inner hits: https://www.elastic.co/guide/en/elasticsearch/reference/2.1/search-request-inner-hits.html


(system) #5