# Indexing Hierarchical Couchbase Documents

**URL:** <https://discuss.elastic.co/t/indexing-hierarchical-couchbase-documents/70400>\
**Category:** Elasticsearch\
**Created:** [January 3, 2017, 7:45am UTC](https://discuss.elastic.co/t/indexing-hierarchical-couchbase-documents/70400 "2017-01-03T07:45:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dogugun\_Ozkaya](https://avatars.discourse-cdn.com/v4/letter/d/ea5d25/32.png) [@Dogugun\_Ozkaya](https://discuss.elastic.co/u/Dogugun_Ozkaya)\
**Post date:** [January 3, 2017, 7:45am UTC](https://discuss.elastic.co/t/indexing-hierarchical-couchbase-documents/70400/1 "2017-01-03T07:45:58Z")

</div>

Hi Everyone,  
I'm quite a newbie in elasticsearch. I have a problem regarding indexing referenced documents.  
I'm using couchbase as the db of my project. And most of the documents are linked to each other hierarchically. Below is an example:

```
document 1:
{
	"documentid": "docid1",
	"properties": [
		{
			"size": "XL"
		},
		{
			"color": "red"
		},
		{
			"image": "docid2"
		}
	]
}
document 2:
{
	"documentid": "docid2",
	"properties": [
		{
			"resolution": "1024*768"
		},
		{
			"type": "jpg"
		}
	]
}

```

"documentid" fields are document id's in the couchbase.  
I have set up couchbase - elasticsearch plugin and it replicates data from couchbase to ES succesfully. However, when I want to search with image type property - "jpeg" - it gives me id of the document "docid2". However I want to get the parent document "docid1".

There are a couple of examples I found online. But in those examples document id's are mapped as:  
"docid1::docid2" which cannot be done in my case. Also since the CB-ES connector did the whole indexing, I cannot change the indexing(I guess, tried and constantly getting error).

Now I'm thinking of replicating the related bucket to another node and nest the documents as:

```
{"documentid": "docid1",
	"properties": [
		{
			"size": "XL"
		},
		{
			"color": "red"
		},
		{
			"image": {
				"documentid": "docid2",
				"properties": [
					{
						"resolution": "1024*768"
					},
					{
						"type": "jpg"
					}
				]
			}
		}
	]}

```

and replicate it again to ES with this form.

Can you guys please suggest a more elaborate and economical way?

---

<div class="post-metadata">

**Author:** ![Mark\_Harwood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_harwood/32/10538_2.png) [@Mark\_Harwood](https://discuss.elastic.co/u/Mark_Harwood)\
**Post date:** [January 3, 2017, 9:19am UTC](https://discuss.elastic.co/t/indexing-hierarchical-couchbase-documents/70400/2 "2017-01-03T09:19:53Z")

</div>

From the example documents you supplied there's no indication that doc 2 should be related to doc 1.

You have 3 options :

- Collapse all source docs into a single "flat" JSON doc
- Collapse all source docs into a single "nested" JSON doc [1]
- Store parent and child source docs separately but relate them when you add them [2]

The decision process for why you would choose one approach over another is roughly this:

 ![](https://us1.discourse-cdn.com/elastic/original/2X/b/b56cea352b3d9b5d8ea17615dd753a2f3cc6798e.png)

I'm unfamiliar with the couchbase plugin and to what extent it can be made to work with elasticsearch's parent/child indexing API.

[1] [https://www.elastic.co/guide/en/elasticsearch/guide/2.x/nested-objects.html](https://www.elastic.co/guide/en/elasticsearch/guide/2.x/nested-objects.html)  
[2] [https://www.elastic.co/guide/en/elasticsearch/guide/2.x/parent-child.html](https://www.elastic.co/guide/en/elasticsearch/guide/2.x/parent-child.html)

---

<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:** [January 31, 2017, 9:19am UTC](https://discuss.elastic.co/t/indexing-hierarchical-couchbase-documents/70400/3 "2017-01-31T09:19:55Z")

</div>

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