# Include\_in\_root deprecated

**URL:** <https://discuss.elastic.co/t/include-in-root-deprecated/91508>\
**Category:** Elasticsearch\
**Created:** [July 1, 2017, 10:14am UTC](https://discuss.elastic.co/t/include-in-root-deprecated/91508 "2017-07-01T10:14:00Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![panda2004](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/panda2004/32/19473_2.png) [@panda2004](https://discuss.elastic.co/u/panda2004)\
**Post date:** [July 1, 2017, 10:14am UTC](https://discuss.elastic.co/t/include-in-root-deprecated/91508/1 "2017-07-01T10:14:00Z")

</div>

Hello,

I understand that `include_in_root` / `include_in_parent` is now deprecated for the use of `copy_to`.  
How can I use [copy\_to](https://www.elastic.co/guide/en/elasticsearch/reference/current/copy-to.html) for this purpose?

This is my guess:

```
PUT orders
{
	"mappings" : {
		"Order" : {
			"properties" : {
				"BuyersNames" : {
					"type" : "keyword"
				},
				"Buyers" : {
					"type" : "nested",
					"properties" : {
						"Name" : {
							"type" : "keyword",
							// DEPRECATED: "include_in_root": "true",
							"copy_to" : "BuyersName" 
						}
					}
				}
			}
		}
	}
}

```

Will this allow making something like this?

Request: `GET orders/order/1`

Response :

```
{
	"BuyersNames" : ["John", "George"],
	"Buyers" : [{
			"Name" : "John"
		}, {
			"Name" : "George"
		}
	]
}

```

By the way, is it really helpful in matter of search performance? Meaning that making a `term query` (BuyersNames include John) is much faster than making a `nested query` ([BuyersNames.Name](http://BuyersNames.Name) = John)?

---

<div class="post-metadata">

**Author:** ![jpountz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jpountz/32/45836_2.png) [@jpountz](https://discuss.elastic.co/u/jpountz)\
**Post date:** [July 3, 2017, 1:29pm UTC](https://discuss.elastic.co/t/include-in-root-deprecated/91508/2 "2017-07-03T13:29:37Z")

</div>

It is not deprecated yet, we are only discussing it for now.

Conceptually, yes, your document would be indexed as if it had `"BuyersNames" : ["John", "George"]`. However, note that the `_source` will not reflect this.

> By the way, is it really helpful in matter of search performance? Meaning that making a term query (BuyersNames include John) is much faster than making a nested query (BuyersNames.Name = John)?

Yes, this will be much faster. I can't quantify, but probably noticeable.

---

<div class="post-metadata">

**Author:** ![panda2004](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/panda2004/32/19473_2.png) [@panda2004](https://discuss.elastic.co/u/panda2004)\
**Post date:** [July 4, 2017, 7:41am UTC](https://discuss.elastic.co/t/include-in-root-deprecated/91508/3 "2017-07-04T07:41:40Z")

</div>

I have tried this mapping today, and it worked just as expected.  
Thank you for the remark about the `_source`, it was very confusing at first!

One last discussion: how smart is this copying?

1. If I have 2 buyers with the name "John", then `BuyersNames` array will include "John" twice? I believe it will and it's fine This way I can count the number of buyers by the length of `BuyersNames` instead of following the nested documents.
2. If a buyer is deleted, then his/her name will be removed from `BuyersNames`? I believe it won't - and it's fine. After all it is called "copy" not "binding", and in addition it's not common to delete a nested document nor updating it.
3. Does `include_in_*` behave the same - concerning questions 1+2?

---

<div class="post-metadata">

**Author:** ![jpountz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jpountz/32/45836_2.png) [@jpountz](https://discuss.elastic.co/u/jpountz)\
**Post date:** [July 4, 2017, 8:06am UTC](https://discuss.elastic.co/t/include-in-root-deprecated/91508/4 "2017-07-04T08:06:06Z")

</div>

> If I have 2 buyers with the name "John", then BuyersNames array will include "John" twice? I believe it will and it's fine This way I can count the number of buyers by the length of BuyersNames instead of following the nested documents.

Actually `keyword` fields are aware of duplicates for scoring, but not for aggregations. So if you count the number of buyers, all johns will count as 1.

> If a buyer is deleted, then his/her name will be removed from BuyersNames? I believe it won't - and it's fine. After all it is called "copy" not "binding", and in addition it's not common to delete a nested document nor updating it.

It will be removed. Elasticsearch does not perform in-place updates. If you update a document, we actually compute the new updated document and reindex it entirely.

> Does include\_in\_\* behave the same - concerning questions 1+2?

Yes.

---

<div class="post-metadata">

**Author:** ![panda2004](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/panda2004/32/19473_2.png) [@panda2004](https://discuss.elastic.co/u/panda2004)\
**Post date:** [July 4, 2017, 8:21am UTC](https://discuss.elastic.co/t/include-in-root-deprecated/91508/5 "2017-07-04T08:21:49Z")

</div>

Thanks for the quick reply!

> Actually keyword fields are aware of duplicates for scoring, but not for aggregations. So if you count the number of buyers, all johns will count as 1.

Didn't know that, it's very interesting!  
Lets say I've got 2 documents, each with 3 Johns. When a terms aggregation will be made about all the documents who's got "john", the result will be "john": 6, or "john": 2?

---

<div class="post-metadata">

**Author:** ![jpountz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jpountz/32/45836_2.png) [@jpountz](https://discuss.elastic.co/u/jpountz)\
**Post date:** [July 4, 2017, 9:19am UTC](https://discuss.elastic.co/t/include-in-root-deprecated/91508/6 "2017-07-04T09:19:31Z")

</div>

john:2

---

<div class="post-metadata">

**Author:** ![panda2004](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/panda2004/32/19473_2.png) [@panda2004](https://discuss.elastic.co/u/panda2004)\
**Post date:** [July 15, 2017, 7:48pm UTC](https://discuss.elastic.co/t/include-in-root-deprecated/91508/7 "2017-07-15T19:48:21Z")

</div>

Hey again @jpountz. Sorry for bumping again the thread, but I want to ask again about your last insight concerning "exactly once" in Keyword data type. Since Array data type and Object data type act like their own inner data types (Keyword in my use case), it means that they can't assist here. Does it mean that only Nested data type containing a Keyword field will do the job, in case I need to count duplicate values?

By the way, I think it should really be documented in Keyword data type.

---

<div class="post-metadata">

**Author:** ![jpountz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jpountz/32/45836_2.png) [@jpountz](https://discuss.elastic.co/u/jpountz)\
**Post date:** [July 17, 2017, 6:57am UTC](https://discuss.elastic.co/t/include-in-root-deprecated/91508/8 "2017-07-17T06:57:13Z")

</div>

I think you are right that only `nested` could do the job in that case indeed. For the record, this is not specific to keywords, but to aggregations: aggregations count documents, not values. So if a given document has twice the same value, it still only counts 1 since there is only 1 document. I think this is expected since the name of the field in the response is called `doc_count`?

---

<div class="post-metadata">

**Author:** ![panda2004](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/panda2004/32/19473_2.png) [@panda2004](https://discuss.elastic.co/u/panda2004)\
**Post date:** [July 17, 2017, 10:25pm UTC](https://discuss.elastic.co/t/include-in-root-deprecated/91508/9 "2017-07-17T22:25:36Z")

</div>

Actually what you have said totally makes sense. Haven't noticed until now that some aggregations return "doc\_count" while others return "value". Thanks again!

---

<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:** [August 14, 2017, 10:25pm UTC](https://discuss.elastic.co/t/include-in-root-deprecated/91508/10 "2017-08-14T22:25:51Z")

</div>

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