# Elasticsearch nested fields

**URL:** <https://discuss.elastic.co/t/elasticsearch-nested-fields/14253>\
**Category:** Elasticsearch\
**Created:** [November 4, 2013, 11:31pm UTC](https://discuss.elastic.co/t/elasticsearch-nested-fields/14253 "2013-11-04T23:31:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![tmanta7](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tmanta7/32/1953_2.png) [@tmanta7](https://discuss.elastic.co/u/tmanta7)\
**Post date:** [November 4, 2013, 11:31pm UTC](https://discuss.elastic.co/t/elasticsearch-nested-fields/14253/1 "2013-11-04T23:31:26Z")

</div>

Hi guys,

I'm currently facing an issue with ES and its integration with Kibana on a  
specific subject: nested fields.

My goal was to implement a terms panel using nested fields. I used nested  
fields to manage some key/values :

{

```
"mappings" : { 

    "fkv" : { 

        "properties" : { 

            "kv" : { 

                "type" : "nested", 

                "include_in_parent" : false, 

                "properties" : { 

                    "name" : {"type" : "string"}, 

                    "value" : {"type" : "string"} 

                } 

            } 

        } 

    } 

} 

```

}

Unfortunately I read somewhere that this integration was not done by Kibana  
authors. So I started to wonder if using nested fields was really  
necessary..  
Ok it's helpful to manage key/value but why shouldn't I use the "column  
oriented" mechanism of Elasticsearch? I mean, using simply the key as a  
column :

{

```
"kv" : [ 

    { 

        "key" : "id", 

        "value" : "part1" 

    }, 

    { 

        "key" : "state", 

        "value" : "released" 

    } 

] 

```

}

Excuse me if my questions is stupid, I'm a beginner with Elasticsearch but  
in my simple case (managing key/value) I can't see any advantages of using  
nested fields.

Thanks in advance for your help!

--  
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).  
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:** [November 5, 2013, 12:10am UTC](https://discuss.elastic.co/t/elasticsearch-nested-fields/14253/2 "2013-11-05T00:10:50Z")

</div>

With nested fields, a query will only return document whose nested  
documents match all the fields in the query. In your example, a  
query/filter on key & value most match the same fields in the same  
document. Without nested fields, elasticsearch/Lucene will flatten multiple  
values into an array. For example:

key : [id, state]  
value : [part1, released]

Without nested documents, a query for key:id & value:released will return  
the above document although they do not match the same sub-object. With  
nested documents, your query will not match.

Cheers,

Ivan

On Mon, Nov 4, 2013 at 3:31 PM, [tmanta7@gmail.com](mailto:tmanta7@gmail.com) wrote:

> Hi guys,
> 
> I'm currently facing an issue with ES and its integration with Kibana on a  
> specific subject: nested fields.
> 
> My goal was to implement a terms panel using nested fields. I used nested  
> fields to manage some key/values :
> 
> {
> 
> ```
> "mappings" : {
> 
> "fkv" : {
> 
> "properties" : {
> 
> "kv" : {
> 
> "type" : "nested",
> 
> "include_in_parent" : false,
> 
> "properties" : {
> 
> "name" : {"type" : "string"},
> 
> "value" : {"type" : "string"}
> 
> }
> 
> }
> 
> }
> 
> }
> 
> }
> 
> ```
> 
> }
> 
> Unfortunately I read somewhere that this integration was not done by  
> Kibana authors. So I started to wonder if using nested fields was really  
> necessary..  
> Ok it's helpful to manage key/value but why shouldn't I use the "column  
> oriented" mechanism of Elasticsearch? I mean, using simply the key as a  
> column :
> 
> {
> 
> ```
> "kv" : [
> 
> {
> 
> "key" : "id",
> 
> "value" : "part1"
> 
> },
> 
> {
> 
> "key" : "state",
> 
> "value" : "released"
> 
> }
> 
> ]
> 
> ```
> 
> }
> 
> Excuse me if my questions is stupid, I'm a beginner with Elasticsearch but  
> in my simple case (managing key/value) I can't see any advantages of using  
> nested fields.
> 
> Thanks in advance for your help!
> 
> --  
> 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).  
> 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).  
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, 2:08am UTC](https://discuss.elastic.co/t/elasticsearch-nested-fields/14253/3 "2017-07-06T02:08:57Z")

</div>


