# Difference about the "nested" type and "object" type?

**URL:** <https://discuss.elastic.co/t/difference-about-the-nested-type-and-object-type/15374>\
**Category:** Elasticsearch\
**Created:** [January 23, 2014, 7:41am UTC](https://discuss.elastic.co/t/difference-about-the-nested-type-and-object-type/15374 "2014-01-23T07:41:42Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ivan\_Ji](https://avatars.discourse-cdn.com/v4/letter/i/d78d45/32.png) [@Ivan\_Ji](https://discuss.elastic.co/u/Ivan_Ji)\
**Post date:** [January 23, 2014, 7:41am UTC](https://discuss.elastic.co/t/difference-about-the-nested-type-and-object-type/15374/1 "2014-01-23T07:41:42Z")

</div>

Hi, all

I am wondering what the difference between the two types in the mappings.

I know the nested object can be query using nested query. but can the  
object type field be query using other queries, such as term query?

ex, what's the difference when I change the type of "variation " to object?

{  
"cloth" : {  
"properties" : {  
"name" : {"type" : "string", "store" : "yes", "index" : "analyzed"},  
"variation" : {  
"type" : "nested",  
"properties" : {  
"size" : {"type" : "string", "store" : "yes", "index" :  
"not\_analyzed"},  
"color" : {"type" : "string", "store" : "yes", "index" :  
"not\_analyzed"}  
}  
}  
}  
}  
}

In both types, I can also use "variation.size" to denote the field. So I  
can use the notation "variation.size" to query this field, such as term  
query:

"query" : {  
"term" : {  
"variation.size" : "crime"  
}  
}

Is that ok ?

Because the object type seems friendly to me, could you give me some  
opinion about it?

Thanks a lot.

Regards,

Ivan

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/1be470c2-36c0-45c2-9131-907d35baf8c7%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/1be470c2-36c0-45c2-9131-907d35baf8c7%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)\
**Post date:** [January 23, 2014, 7:52am UTC](https://discuss.elastic.co/t/difference-about-the-nested-type-and-object-type/15374/2 "2014-01-23T07:52:31Z")

</div>

The elasticsearch site has a short writeup about the benefits of the nested  
type:

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

Basically, with object types, multiple instances of a field are flattened  
as an unordered array. In your example, if you would not be possible to  
search for an object that has a specific size and color since the query  
could match on a parent object that contains an object child with the  
desired size and another child with the color. Nested documents will allow  
you to return only the parent documents that contain children matching all  
the conditions.

Cheers,

Another Ivan

On Wed, Jan 22, 2014 at 11:41 PM, Ivan Ji [hxuanji@gmail.com](mailto:hxuanji@gmail.com) wrote:

> Hi, all
> 
> I am wondering what the difference between the two types in the mappings.
> 
> I know the nested object can be query using nested query. but can the  
> object type field be query using other queries, such as term query?
> 
> ex, what's the difference when I change the type of "variation " to  
> object?
> 
> {  
> "cloth" : {  
> "properties" : {  
> "name" : {"type" : "string", "store" : "yes", "index" : "analyzed"},  
> "variation" : {  
> "type" : "nested",  
> "properties" : {  
> "size" : {"type" : "string", "store" : "yes", "index" :  
> "not\_analyzed"},  
> "color" : {"type" : "string", "store" : "yes", "index" :  
> "not\_analyzed"}  
> }  
> }  
> }  
> }  
> }
> 
> In both types, I can also use "variation.size" to denote the field. So I  
> can use the notation "variation.size" to query this field, such as term  
> query:
> 
> "query" : {  
> "term" : {  
> "variation.size" : "crime"  
> }  
> }
> 
> Is that ok ?
> 
> Because the object type seems friendly to me, could you give me some  
> opinion about it?
> 
> Thanks a lot.
> 
> Regards,
> 
> Ivan
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/1be470c2-36c0-45c2-9131-907d35baf8c7%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/1be470c2-36c0-45c2-9131-907d35baf8c7%40googlegroups.com)  
> .  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQBC9OCV%2BpL7sLV8RTe%2BLgtrgNkr0Vdn55X%3De8e%2BPKA8dw%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQBC9OCV%2BpL7sLV8RTe%2BLgtrgNkr0Vdn55X%3De8e%2BPKA8dw%40mail.gmail.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Ivan\_Ji](https://avatars.discourse-cdn.com/v4/letter/i/d78d45/32.png) [@Ivan\_Ji](https://discuss.elastic.co/u/Ivan_Ji)\
**Post date:** [January 24, 2014, 7:00am UTC](https://discuss.elastic.co/t/difference-about-the-nested-type-and-object-type/15374/3 "2014-01-24T07:00:59Z")

</div>

Hi, Ivan

I got it!

Thanks.

Another Ivan

Ivan Brusic於 2014年1月23日星期四UTC+8下午3時52分31秒寫道：

> The elasticsearch site has a short writeup about the benefits of the  
> nested type:  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/mapping-nested-type.html)
> 
> Basically, with object types, multiple instances of a field are flattened  
> as an unordered array. In your example, if you would not be possible to  
> search for an object that has a specific size and color since the query  
> could match on a parent object that contains an object child with the  
> desired size and another child with the color. Nested documents will allow  
> you to return only the parent documents that contain children matching all  
> the conditions.
> 
> Cheers,
> 
> Another Ivan
> 
> On Wed, Jan 22, 2014 at 11:41 PM, Ivan Ji \<[hxu...@gmail.com](mailto:hxu...@gmail.com) \<javascript:\>\>wrote:
> 
> > Hi, all
> > 
> > I am wondering what the difference between the two types in the mappings.
> > 
> > I know the nested object can be query using nested query. but can the  
> > object type field be query using other queries, such as term query?
> > 
> > ex, what's the difference when I change the type of "variation " to  
> > object?
> > 
> > {  
> > "cloth" : {  
> > "properties" : {  
> > "name" : {"type" : "string", "store" : "yes", "index" : "analyzed"},  
> > "variation" : {  
> > "type" : "nested",  
> > "properties" : {  
> > "size" : {"type" : "string", "store" : "yes", "index" :  
> > "not\_analyzed"},  
> > "color" : {"type" : "string", "store" : "yes", "index" :  
> > "not\_analyzed"}  
> > }  
> > }  
> > }  
> > }  
> > }
> > 
> > In both types, I can also use "variation.size" to denote the field. So I  
> > can use the notation "variation.size" to query this field, such as term  
> > query:
> > 
> > "query" : {  
> > "term" : {  
> > "variation.size" : "crime"  
> > }  
> > }
> > 
> > Is that ok ?
> > 
> > Because the object type seems friendly to me, could you give me some  
> > opinion about it?
> > 
> > Thanks a lot.
> > 
> > Regards,
> > 
> > Ivan
> > 
> > --  
> > You received this message because you are subscribed to the Google Groups  
> > "elasticsearch" group.  
> > To unsubscribe from this group and stop receiving emails from it, send an  
> > email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > To view this discussion on the web visit  
> > [https://groups.google.com/d/msgid/elasticsearch/1be470c2-36c0-45c2-9131-907d35baf8c7%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/1be470c2-36c0-45c2-9131-907d35baf8c7%40googlegroups.com)  
> > .  
> > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/f4adc713-a5f2-4d66-b918-5e0ad1bc7192%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/f4adc713-a5f2-4d66-b918-5e0ad1bc7192%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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, 1:55am UTC](https://discuss.elastic.co/t/difference-about-the-nested-type-and-object-type/15374/4 "2017-07-06T01:55:03Z")

</div>


