# How do you set \_parent using Tire in a Rails model?

**URL:** <https://discuss.elastic.co/t/how-do-you-set--parent-using-tire-in-a-rails-model/9007>\
**Category:** Elasticsearch\
**Created:** [September 13, 2012, 1:43am UTC](https://discuss.elastic.co/t/how-do-you-set--parent-using-tire-in-a-rails-model/9007 "2012-09-13T01:43:27Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Meltemi](https://avatars.discourse-cdn.com/v4/letter/m/a87d85/32.png) [@Meltemi](https://discuss.elastic.co/u/Meltemi)\
**Post date:** [September 13, 2012, 1:43am UTC](https://discuss.elastic.co/t/how-do-you-set--parent-using-tire-in-a-rails-model/9007/1 "2012-09-13T01:43:27Z")

</div>

Apologies for my dense-ity. Elasticsearch & Tire have my head spinning...

I'm looking for an example of how to index a parent[http://www.elasticsearch.org/guide/reference/mapping/parent-field.html](http://www.elasticsearch.org/guide/reference/mapping/parent-field.html)child relationship between a  
Page and a Report model in Rails.

Should I use the report\_id attribute of Page and index it as "\_parent" or  
do something like Karmi suggests here[http://stackoverflow.com/questions/11692560/elasticsearch-tire-and-nested-queries-associations-with-activerecord](http://stackoverflow.com/questions/11692560/elasticsearch-tire-and-nested-queries-associations-with-activerecord).  
And if so will the \_parent relationship be established automatically?

In my Page model I have:

class Page \< ActiveRecord::Base  
include Tire::Model::Search  
include Tire::Model::Callbacks

belongs\_to :report  
attr\_accessible :filename, :page\_num, :parent\_code

tire.mapping do  
indexes :id, :type =\> 'integer'  
indexes :_report\_id_, :type =\> 'integer' # but how is this  
associated with _\_parent_?  
indexes :parent\_code  
...  
end  
end

--

---

<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 6, 2017, 3:12am UTC](https://discuss.elastic.co/t/how-do-you-set--parent-using-tire-in-a-rails-model/9007/2 "2017-07-06T03:12:59Z")

</div>

Closed on July 6, 2017, 3:12am UTC


