# Use objects in array type and nested objects as root object type

**URL:** <https://discuss.elastic.co/t/use-objects-in-array-type-and-nested-objects-as-root-object-type/2819>\
**Category:** Elasticsearch\
**Created:** [February 17, 2010, 8:36am UTC](https://discuss.elastic.co/t/use-objects-in-array-type-and-nested-objects-as-root-object-type/2819 "2010-02-17T08:36:48Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![eugeis](https://avatars.discourse-cdn.com/v4/letter/e/278dde/32.png) [@eugeis](https://discuss.elastic.co/u/eugeis)\
**Post date:** [February 17, 2010, 8:36am UTC](https://discuss.elastic.co/t/use-objects-in-array-type-and-nested-objects-as-root-object-type/2819/1 "2010-02-17T08:36:48Z")

</div>

Hello,

a) how can I use a object in array type.

e.g.

folder : {  
path : "C:/Windows",  
files (should be an array of filetype) :  
[  
{  
name : "File1.txt",  
description : "Example file 1"  
},  
{  
name : "File2.txt",  
description : "Example file 2"  
}  
]  
}

Files array type should be array of file object type

b) What I have to do, to have the file object type as a root object  
type. The folder (root object type) would have nested file root object  
type.

Thank You

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [February 17, 2010, 1:53pm UTC](https://discuss.elastic.co/t/use-objects-in-array-type-and-nested-objects-as-root-object-type/2819/2 "2010-02-17T13:53:14Z")

</div>

You send a single JSON to be indexed, what you have in the JSON will be  
indexed. If you want to search for a specific file name, you can (using your  
JSON) use folder.files.name:something (that 'folder.files.name" can be used  
anywhere in elasticsearch that accepts a field).

-shay.banon

On Wed, Feb 17, 2010 at 10:36 AM, eugeis [eoeisler@googlemail.com](mailto:eoeisler@googlemail.com) wrote:

> Hello,
> 
> a) how can I use a object in array type.
> 
> e.g.
> 
> folder : {  
> path : "C:/Windows",  
> files (should be an array of filetype) :  
> [  
> {  
> name : "File1.txt",  
> description : "Example file 1"  
> },  
> {  
> name : "File2.txt",  
> description : "Example file 2"  
> }  
> ]  
> }
> 
> Files array type should be array of file object type
> 
> b) What I have to do, to have the file object type as a root object  
> type. The folder (root object type) would have nested file root object  
> type.
> 
> Thank You

---

<div class="post-metadata">

**Author:** ![eugeis](https://avatars.discourse-cdn.com/v4/letter/e/278dde/32.png) [@eugeis](https://discuss.elastic.co/u/eugeis)\
**Post date:** [February 17, 2010, 3:47pm UTC](https://discuss.elastic.co/t/use-objects-in-array-type-and-nested-objects-as-root-object-type/2819/3 "2010-02-17T15:47:12Z")

</div>

Thanks, it works with query "folder.files.name",  
but "folder" objects are found, but like expected with all  
"files" (matched and unmatched "files").

It is possible to search "folder" and "file" objects? I want something  
like

a) curl -XGET http://...:9200/indexname/folder/\_search?q=folder.path:_xxx_  
=\> "folder" objects are found  
b) curl -XGET http://...:9200/indexname/folder/files/\_search?q=folder.files.name:_xxx_  
=\> "file" objects are found

Therefore I thought that nested "file" object should be also "root"  
object.

-eugeis

On 17 Feb., 14:53, Shay Banon [shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) wrote:

> You send a single JSON to be indexed, what you have in the JSON will be  
> indexed. If you want to search for a specific file name, you can (using your  
> JSON) use folder.files.name:something (that 'folder.files.name" can be used  
> anywhere in elasticsearch that accepts a field).
> 
> -shay.banon
> 
> On Wed, Feb 17, 2010 at 10:36 AM, eugeis [eoeis...@googlemail.com](mailto:eoeis...@googlemail.com) wrote:
> 
> > Hello,
> 
> > a) how can I use a object in array type.
> 
> > e.g.
> 
> > folder : {  
> > path : "C:/Windows",  
> > files (should be an array of filetype) :  
> > [  
> > {  
> > name : "File1.txt",  
> > description : "Example file 1"  
> > },  
> > {  
> > name : "File2.txt",  
> > description : "Example file 2"  
> > }  
> > ]  
> > }
> 
> > Files array type should be array of file object type
> 
> > b) What I have to do, to have the file object type as a root object  
> > type. The folder (root object type) would have nested file root object  
> > type.
> 
> > Thank You

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [February 17, 2010, 5:54pm UTC](https://discuss.elastic.co/t/use-objects-in-array-type-and-nested-objects-as-root-object-type/2819/4 "2010-02-17T17:54:01Z")

</div>

You can only navigate from the top level object and downwards. What you can  
do, is define the pathType for object mapping as explained here:  
[http://www.elasticsearch.com/docs/elasticsearch/mapping/object\_type/#pathType](http://www.elasticsearch.com/docs/elasticsearch/mapping/object_type/#pathType)  
.

-shay.banon

On Wed, Feb 17, 2010 at 5:47 PM, eugeis [eoeisler@googlemail.com](mailto:eoeisler@googlemail.com) wrote:

> Thanks, it works with query "folder.files.name",  
> but "folder" objects are found, but like expected with all  
> "files" (matched and unmatched "files").
> 
> It is possible to search "folder" and "file" objects? I want something  
> like
> 
> a) curl -XGET http://...:9200/indexname/folder/\_search?q=folder.path:_xxx_  
> =\> "folder" objects are found  
> b) curl -XGET http://  
> ...:9200/indexname/folder/files/\_search?q=folder.files.name:_xxx_  
> =\> "file" objects are found
> 
> Therefore I thought that nested "file" object should be also "root"  
> object.
> 
> -eugeis
> 
> On 17 Feb., 14:53, Shay Banon [shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) wrote:
> 
> > You send a single JSON to be indexed, what you have in the JSON will be  
> > indexed. If you want to search for a specific file name, you can (using  
> > your  
> > JSON) use folder.files.name:something (that 'folder.files.name" can be  
> > used  
> > anywhere in elasticsearch that accepts a field).
> > 
> > -shay.banon
> > 
> > On Wed, Feb 17, 2010 at 10:36 AM, eugeis [eoeis...@googlemail.com](mailto:eoeis...@googlemail.com)  
> > wrote:
> > 
> > > Hello,
> > 
> > > a) how can I use a object in array type.
> > 
> > > e.g.
> > 
> > > folder : {  
> > > path : "C:/Windows",  
> > > files (should be an array of filetype) :  
> > > [  
> > > {  
> > > name : "File1.txt",  
> > > description : "Example file 1"  
> > > },  
> > > {  
> > > name : "File2.txt",  
> > > description : "Example file 2"  
> > > }  
> > > ]  
> > > }
> > 
> > > Files array type should be array of file object type
> > 
> > > b) What I have to do, to have the file object type as a root object  
> > > type. The folder (root object type) would have nested file root object  
> > > type.
> > 
> > > Thank You

---

<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, 4:25am UTC](https://discuss.elastic.co/t/use-objects-in-array-type-and-nested-objects-as-root-object-type/2819/5 "2017-07-06T04:25:39Z")

</div>


