# JSON-REF and interdocument link traversal for indexing and retrieving related docs

**URL:** <https://discuss.elastic.co/t/json-ref-and-interdocument-link-traversal-for-indexing-and-retrieving-related-docs/7896>\
**Category:** Elasticsearch\
**Created:** [May 29, 2012, 6:25pm UTC](https://discuss.elastic.co/t/json-ref-and-interdocument-link-traversal-for-indexing-and-retrieving-related-docs/7896 "2012-05-29T18:25:51Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mat1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mat1/32/1679_2.png) [@mat1](https://discuss.elastic.co/u/mat1)\
**Post date:** [May 29, 2012, 6:25pm UTC](https://discuss.elastic.co/t/json-ref-and-interdocument-link-traversal-for-indexing-and-retrieving-related-docs/7896/1 "2012-05-29T18:25:51Z")

</div>

Please can you advise on the best way to implement the use of  
inter-document references eg based on JSON-REF  
([draft-pbryan-zyp-json-ref-03 - JSON Reference](https://datatracker.ietf.org/doc/draft-pbryan-zyp-json-ref/)) as a special  
field type of field to represent nesting or parent/child type relationships  
between documents that are stored and indexed and updated seperately but  
which can be queried and retrieved together.

For example I might have 2 type types of docs - blogs, and users, with an  
author field on the blog post which references a user doc..

\*POST /index/user/usr1 {

> name : "Mat"  
> email: "mat@email.not"  
> }  
> POST /index/blog/doc1 {  
> title : "Doc title 1"  
> author: { $ref:"/index/user/usr1" }  
> body : "This is the body of the doc"  
> }\*

I would then like to be able to query for blog posts written by 'mat', and  
perhaps also pass an additional request params to indicate which source  
$ref fields should be expanded in the \_source of the results. This  
behavior, as well as boosting and other controls might also of course be  
managed through mapping parameters for $ref field types.

\*GET /index/blog/\_search {  
expand: ["author"],  
query: {  
term: {  
author.name : "Mat"  
}  
}  
}

> > > {  
> > > ...  
> > > hits: [ {  
> > > \_index:  
> > > \_type: "blog"  
> > > \_id: "doc1"  
> > > \_score: 1  
> > > \_source: {  
> > > title:'Doc Title 1"  
> > > author: {  
> > > name: "Mat" ,  
> > > email: "mat@email.not"  
> > > },  
> > > body:"This is the body of the doc"  
> > > }  
> > > ...  
> > > } ]  
> > > } \*

- 
-

---

<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:26am UTC](https://discuss.elastic.co/t/json-ref-and-interdocument-link-traversal-for-indexing-and-retrieving-related-docs/7896/2 "2017-07-06T03:26:32Z")

</div>


