# Object property vs array index

**URL:** <https://discuss.elastic.co/t/object-property-vs-array-index/17923>\
**Category:** Elasticsearch\
**Created:** [June 5, 2014, 10:07am UTC](https://discuss.elastic.co/t/object-property-vs-array-index/17923 "2014-06-05T10:07:09Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![random35743373](https://avatars.discourse-cdn.com/v4/letter/r/858c86/32.png) [@random35743373](https://discuss.elastic.co/u/random35743373)\
**Post date:** [June 5, 2014, 10:07am UTC](https://discuss.elastic.co/t/object-property-vs-array-index/17923/1 "2014-06-05T10:07:09Z")

</div>

When a field contains an object, in a terms aggregation I can specify a  
specific object property that contains the terms I want to use eg

{  
"terms": {  
"field": "fieldName.propertyContainingTerms"  
}  
}

So with a array type field that contains a list of strings ["first",  
"second", "third"] I should be able to do the same via array indices

{  
"terms": {  
"field": "fieldName[0]"  
}  
}

But this doesn't work. Am I using the wrong syntax or is this just not  
possible?

My current solution is to use objects with integers converted to strings as  
the property keys eg "fieldName.0", it works but feels wrong.

--  
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/002d9cd8-04b6-4dec-91a0-d49f5f187a2d%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/002d9cd8-04b6-4dec-91a0-d49f5f187a2d%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [June 16, 2014, 12:29pm UTC](https://discuss.elastic.co/t/object-property-vs-array-index/17923/2 "2014-06-16T12:29:17Z")

</div>

Hey,

that doesnt work like you want it to work. I am not sure, if I understood  
the intention of your query. Do you want to count on all first elements of  
all documents or do you just want to filter for that term? If its the  
first, maybe a script aggregations can help you, that just returns the  
first field of that array.

--Alex

On Thu, Jun 5, 2014 at 12:07 PM, [random35743373@googlemail.com](mailto:random35743373@googlemail.com) wrote:

> When a field contains an object, in a terms aggregation I can specify a  
> specific object property that contains the terms I want to use eg
> 
> {  
> "terms": {  
> "field": "fieldName.propertyContainingTerms"  
> }  
> }
> 
> So with a array type field that contains a list of strings ["first",  
> "second", "third"] I should be able to do the same via array indices
> 
> {  
> "terms": {  
> "field": "fieldName[0]"  
> }  
> }
> 
> But this doesn't work. Am I using the wrong syntax or is this just not  
> possible?
> 
> My current solution is to use objects with integers converted to strings  
> as the property keys eg "fieldName.0", it works but feels wrong.
> 
> --  
> 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/002d9cd8-04b6-4dec-91a0-d49f5f187a2d%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/002d9cd8-04b6-4dec-91a0-d49f5f187a2d%40googlegroups.com)  
> [https://groups.google.com/d/msgid/elasticsearch/002d9cd8-04b6-4dec-91a0-d49f5f187a2d%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/002d9cd8-04b6-4dec-91a0-d49f5f187a2d%40googlegroups.com?utm_medium=email&utm_source=footer)  
> .  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
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/CAGCwEM88H%2B9fnXiLKpx5HESfN-N2L5oU4804J8\_DF75ygAfp5A%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAGCwEM88H%2B9fnXiLKpx5HESfN-N2L5oU4804J8_DF75ygAfp5A%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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:22am UTC](https://discuss.elastic.co/t/object-property-vs-array-index/17923/3 "2017-07-06T01:22:10Z")

</div>


