# Rails nested models render JSON

**URL:** <https://discuss.elastic.co/t/rails-nested-models-render-json/89862>\
**Category:** Elasticsearch\
**Created:** [June 18, 2017, 8:59pm UTC](https://discuss.elastic.co/t/rails-nested-models-render-json/89862 "2017-06-18T20:59:48Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![sadboy](https://avatars.discourse-cdn.com/v4/letter/s/4af34b/32.png) [@sadboy](https://discuss.elastic.co/u/sadboy)\
**Post date:** [June 18, 2017, 8:59pm UTC](https://discuss.elastic.co/t/rails-nested-models-render-json/89862/1 "2017-06-18T20:59:49Z")

</div>

Let's say I have a Rails model called 'Company'. The company :has\_many employees. Each employee has a name.

I want to perform an elasticsearch on the Company model to look for all the employees that match a specific query on their 'name' attribute. I want to provide the user with such popup: "[Employee name] works for [Company name]".  
In order to be able to do so, I need to render an ES result(JSON) with both the Employee model and the Company he belongs to.  
Is it possible to achieve in ES? I know how to search a single model, but have never tried this scenario.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 16, 2017, 9:00pm UTC](https://discuss.elastic.co/t/rails-nested-models-render-json/89862/2 "2017-07-16T21:00:19Z")

</div>

Closed on July 16, 2017, 9:00pm UTC

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
