# Is there anyway to stop arrays with one element from being returned as a single value

**URL:** https://discuss.elastic.co/t/is-there-anyway-to-stop-arrays-with-one-element-from-being-returned-as-a-single-value/12704
**Category:** Elasticsearch
**Created:** [July 8, 2013, 3:07pm UTC](https://discuss.elastic.co/t/is-there-anyway-to-stop-arrays-with-one-element-from-being-returned-as-a-single-value/12704 "2013-07-08T15:07:25Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Raja\_Mukherji](https://avatars.discourse-cdn.com/v4/letter/r/6f9a4e/32.png) [@Raja\_Mukherji](https://discuss.elastic.co/u/Raja_Mukherji)
#### Post date: [July 8, 2013, 3:07pm UTC](https://discuss.elastic.co/t/is-there-anyway-to-stop-arrays-with-one-element-from-being-returned-as-a-single-value/12704/1 "2013-07-08T15:07:25Z")

</div>

I'm using elasticsearch as my main database. I'm using some fields as  
arrays, and always upload arrays for those fields even if there's only one  
element in the array. The \_source always contains the unchanged array, but  
a search request with specific fields converts arrays with a single element  
into a single value. Is there a way to prevent this behaviour?

--  
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: ![Boaz\_Leskes](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/boaz_leskes/32/723_2.png) [@Boaz\_Leskes](https://discuss.elastic.co/u/Boaz_Leskes)
#### Post date: [July 9, 2013, 12:13pm UTC](https://discuss.elastic.co/t/is-there-anyway-to-stop-arrays-with-one-element-from-being-returned-as-a-single-value/12704/2 "2013-07-09T12:13:18Z")

</div>

Hi Raja,

There is no way just yet but we are working on a solution (  
[Add finer control over `_source` retrieval, in `get`, `mget`, `get_source`, `explain` & `search` API · Issue #3301 · elastic/elasticsearch · GitHub](https://github.com/elasticsearch/elasticsearch/issues/3301) ). This  
behaviour has to do with the original intention of the fields parameter -  
exposing lucene stored fields. If you are using the search API you can use  
partial\_fields instead, which will leave the array intact

- [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/search/fields/)

Cheers,  
Boaz

On Monday, July 8, 2013 5:07:25 PM UTC+2, Raja Mukherji wrote:

> I'm using elasticsearch as my main database. I'm using some fields as  
> arrays, and always upload arrays for those fields even if there's only one  
> element in the array. The \_source always contains the unchanged array, but  
> a search request with specific fields converts arrays with a single element  
> into a single value. Is there a way to prevent this behaviour?

--  
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: ![Raja\_Mukherji](https://avatars.discourse-cdn.com/v4/letter/r/6f9a4e/32.png) [@Raja\_Mukherji](https://discuss.elastic.co/u/Raja_Mukherji)
#### Post date: [July 9, 2013, 3:10pm UTC](https://discuss.elastic.co/t/is-there-anyway-to-stop-arrays-with-one-element-from-being-returned-as-a-single-value/12704/3 "2013-07-09T15:10:01Z")

</div>

Hi Boaz,

Thanks, that works fine except for one case it seems. If I request a field  
"objectfield" of type object with "fields", the object value is returned.  
However for "partial\_fields", I have to request "objectfield.\*", requesting  
"objectfield" on its own does not return anything. I can work around this  
for now though.

Also, since partial\_fields is meant to match on wildcards, is there a  
performance penalty compared to just fields?

Thanks,  
Raja

On Tuesday, 9 July 2013 13:13:18 UTC+1, Boaz Leskes wrote:

> Hi Raja,
> 
> There is no way just yet but we are working on a solution (  
> [Add finer control over `_source` retrieval, in `get`, `mget`, `get_source`, `explain` & `search` API · Issue #3301 · elastic/elasticsearch · GitHub](https://github.com/elasticsearch/elasticsearch/issues/3301) ). This  
> behaviour has to do with the original intention of the fields parameter -  
> exposing lucene stored fields. If you are using the search API you can use  
> partial\_fields instead, which will leave the array intact -  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/search/fields/)
> 
> Cheers,  
> Boaz
> 
> On Monday, July 8, 2013 5:07:25 PM UTC+2, Raja Mukherji wrote:
> 
> > I'm using elasticsearch as my main database. I'm using some fields as  
> > arrays, and always upload arrays for those fields even if there's only one  
> > element in the array. The \_source always contains the unchanged array, but  
> > a search request with specific fields converts arrays with a single element  
> > into a single value. Is there a way to prevent this behaviour?

--  
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: ![Boaz\_Leskes](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/boaz_leskes/32/723_2.png) [@Boaz\_Leskes](https://discuss.elastic.co/u/Boaz_Leskes)
#### Post date: [July 9, 2013, 3:54pm UTC](https://discuss.elastic.co/t/is-there-anyway-to-stop-arrays-with-one-element-from-being-returned-as-a-single-value/12704/4 "2013-07-09T15:54:06Z")

</div>

Yeah - directly selecting objects (i.e. "obj" for { obj: { field: 1 } } ,  
instead of "obj.\*") is something I recently added and will be out with the  
next release.

As to overhead - if you are using fields to access lucene stored fields it  
may be faster because it doesn't need to load the \_source. How ever, if you  
retrieving many fields, it might be faster to just load the source once.  
For \_source extraction wild cards have a small overhead but it is very  
minor.

On Tue, Jul 9, 2013 at 5:10 PM, Raja Mukherji [rajamukherji@gmail.com](mailto:rajamukherji@gmail.com)wrote:

> Hi Boaz,
> 
> Thanks, that works fine except for one case it seems. If I request a field  
> "objectfield" of type object with "fields", the object value is returned.  
> However for "partial\_fields", I have to request "objectfield.\*", requesting  
> "objectfield" on its own does not return anything. I can work around this  
> for now though.
> 
> Also, since partial\_fields is meant to match on wildcards, is there a  
> performance penalty compared to just fields?
> 
> Thanks,  
> Raja
> 
> On Tuesday, 9 July 2013 13:13:18 UTC+1, Boaz Leskes wrote:
> 
> > Hi Raja,
> > 
> > There is no way just yet but we are working on a solution (  
> > [https://github.com/\*\*elasticsearch/elasticsearch/\*\*issues/3301](https://github.com/ **elasticsearch/elasticsearch/** issues/3301)[https://github.com/elasticsearch/elasticsearch/issues/3301](https://github.com/elasticsearch/elasticsearch/issues/3301)). This behaviour has to do with the original intention of the fields  
> > parameter - exposing lucene stored fields. If you are using the search API  
> > you can use partial\_fields instead, which will leave the array intact -  
> > [http://www.elasticsearch](http://www.elasticsearch).\*\*org/guide/reference/api/\*\*search/fields/[http://www.elasticsearch.org/guide/reference/api/search/fields/](http://www.elasticsearch.org/guide/reference/api/search/fields/)
> > 
> > Cheers,  
> > Boaz
> > 
> > On Monday, July 8, 2013 5:07:25 PM UTC+2, Raja Mukherji wrote:
> > 
> > > I'm using elasticsearch as my main database. I'm using some fields as  
> > > arrays, and always upload arrays for those fields even if there's only one  
> > > element in the array. The \_source always contains the unchanged array, but  
> > > a search request with specific fields converts arrays with a single element  
> > > into a single value. Is there a way to prevent this behaviour?
> > 
> > --  
> > You received this message because you are subscribed to a topic in the  
> > Google Groups "elasticsearch" group.  
> > To unsubscribe from this topic, visit  
> > [https://groups.google.com/d/topic/elasticsearch/1NEk7MXnMM8/unsubscribe](https://groups.google.com/d/topic/elasticsearch/1NEk7MXnMM8/unsubscribe).  
> > To unsubscribe from this group and all its topics, 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: ![Raja\_Mukherji](https://avatars.discourse-cdn.com/v4/letter/r/6f9a4e/32.png) [@Raja\_Mukherji](https://discuss.elastic.co/u/Raja_Mukherji)
#### Post date: [July 9, 2013, 4:24pm UTC](https://discuss.elastic.co/t/is-there-anyway-to-stop-arrays-with-one-element-from-being-returned-as-a-single-value/12704/5 "2013-07-09T16:24:57Z")

</div>

Sounds good, I'll look forward to the next release so.

Thanks again.

On Tuesday, 9 July 2013 16:54:06 UTC+1, Boaz Leskes wrote:

> Yeah - directly selecting objects (i.e. "obj" for { obj: { field: 1 } } ,  
> instead of "obj.\*") is something I recently added and will be out with the  
> next release.
> 
> As to overhead - if you are using fields to access lucene stored fields it  
> may be faster because it doesn't need to load the \_source. How ever, if you  
> retrieving many fields, it might be faster to just load the source once.  
> For \_source extraction wild cards have a small overhead but it is very  
> minor.
> 
> On Tue, Jul 9, 2013 at 5:10 PM, Raja Mukherji \<[rajamu...@gmail.com](mailto:rajamu...@gmail.com)\<javascript:\>
> 
> > wrote:
> 
> > Hi Boaz,
> > 
> > Thanks, that works fine except for one case it seems. If I request a  
> > field "objectfield" of type object with "fields", the object value is  
> > returned. However for "partial\_fields", I have to request "objectfield.\*",  
> > requesting "objectfield" on its own does not return anything. I can work  
> > around this for now though.
> > 
> > Also, since partial\_fields is meant to match on wildcards, is there a  
> > performance penalty compared to just fields?
> > 
> > Thanks,  
> > Raja
> > 
> > On Tuesday, 9 July 2013 13:13:18 UTC+1, Boaz Leskes wrote:
> > 
> > > Hi Raja,
> > > 
> > > There is no way just yet but we are working on a solution (  
> > > [https://github.com/\*\*elasticsearch/elasticsearch/\*\*issues/3301](https://github.com/ **elasticsearch/elasticsearch/** issues/3301)[https://github.com/elasticsearch/elasticsearch/issues/3301](https://github.com/elasticsearch/elasticsearch/issues/3301)). This behaviour has to do with the original intention of the fields  
> > > parameter - exposing lucene stored fields. If you are using the search API  
> > > you can use partial\_fields instead, which will leave the array intact -  
> > > [http://www.elasticsearch](http://www.elasticsearch).\*\*org/guide/reference/api/\*\*search/fields/[http://www.elasticsearch.org/guide/reference/api/search/fields/](http://www.elasticsearch.org/guide/reference/api/search/fields/)
> > > 
> > > Cheers,  
> > > Boaz
> > > 
> > > On Monday, July 8, 2013 5:07:25 PM UTC+2, Raja Mukherji wrote:
> > > 
> > > > I'm using elasticsearch as my main database. I'm using some fields as  
> > > > arrays, and always upload arrays for those fields even if there's only one  
> > > > element in the array. The \_source always contains the unchanged array, but  
> > > > a search request with specific fields converts arrays with a single element  
> > > > into a single value. Is there a way to prevent this behaviour?
> > > 
> > > --  
> > > You received this message because you are subscribed to a topic in the  
> > > Google Groups "elasticsearch" group.  
> > > To unsubscribe from this topic, visit  
> > > [https://groups.google.com/d/topic/elasticsearch/1NEk7MXnMM8/unsubscribe](https://groups.google.com/d/topic/elasticsearch/1NEk7MXnMM8/unsubscribe).  
> > > To unsubscribe from this group and all its topics, send an email to  
> > > [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > > 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:27am UTC](https://discuss.elastic.co/t/is-there-anyway-to-stop-arrays-with-one-element-from-being-returned-as-a-single-value/12704/6 "2017-07-06T02:27:26Z")

</div>


