# Get all \*STORED\* fields from a query

**URL:** <https://discuss.elastic.co/t/get-all-stored-fields-from-a-query/5962>\
**Category:** Elasticsearch\
**Created:** [November 24, 2011, 12:04am UTC](https://discuss.elastic.co/t/get-all-stored-fields-from-a-query/5962 "2011-11-24T00:04:47Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![ikarius\_2](https://avatars.discourse-cdn.com/v4/letter/i/77aa72/32.png) [@ikarius\_2](https://discuss.elastic.co/u/ikarius_2)\
**Post date:** [November 24, 2011, 12:04am UTC](https://discuss.elastic.co/t/get-all-stored-fields-from-a-query/5962/1 "2011-11-24T00:04:47Z")

</div>

Hi all,

First, i'm a beginner with ES, so .. be kind (though i've a strong  
background with Lucene).

I'm trying to get all the stored fields (with a mapping) in my seach.  
These  
stored fields seems to be stored alright, thic code:

```
   SearchResponse rsp = getClient().prepareSearch(INDEX_SKIMM)
           .setSearchType(SearchType.DFS_QUERY_THEN_FETCH)
           .setQuery(q)
           .addField("firstname")
           .setFrom(startIndex)
           .setSize(limit > MAX_RESULTS ? MAX_RESULTS : limit )
           .setExplain(true)
           .execute()
           .actionGet();

```

returns me the 'firstname' field in my SearchHit;

But, if i remove the  
.addField("firstname")  
line, i do not get _ANY_ of my stored fields.

Is it normal ?

I've found a (ugly) workaround by adding this line in the search:  
.addField("\*")

and i gain access to all stored fields.

Thanks in advance for your answers !

---

<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:** [November 24, 2011, 1:52pm UTC](https://discuss.elastic.co/t/get-all-stored-fields-from-a-query/5962/2 "2011-11-24T13:52:31Z")

</div>

I assume that when you don't specify any field, and you get nothing back,  
is because you disabled the \_source field. If you want ot get all the  
stored fields, then yes, you need to do: addField("\*"), why is this ugly?

Btw, most times, going each field specifically stored is wrong, and \_source  
should be used.

On Thu, Nov 24, 2011 at 2:04 AM, ikarius [frederic.vergez@gmail.com](mailto:frederic.vergez@gmail.com) wrote:

> Hi all,
> 
> First, i'm a beginner with ES, so .. be kind (though i've a strong  
> background with Lucene).
> 
> I'm trying to get all the stored fields (with a mapping) in my seach.  
> These  
> stored fields seems to be stored alright, thic code:
> 
> ```
> SearchResponse rsp = getClient().prepareSearch(INDEX_SKIMM)
> .setSearchType(SearchType.DFS_QUERY_THEN_FETCH)
> .setQuery(q)
> .addField("firstname")
> .setFrom(startIndex)
> .setSize(limit > MAX_RESULTS ? MAX_RESULTS : limit )
> .setExplain(true)
> .execute()
> .actionGet();
> 
> ```
> 
> returns me the 'firstname' field in my SearchHit;
> 
> But, if i remove the  
> .addField("firstname")  
> line, i do not get _ANY_ of my stored fields.
> 
> Is it normal ?
> 
> I've found a (ugly) workaround by adding this line in the search:  
> .addField("\*")
> 
> and i gain access to all stored fields.
> 
> Thanks in advance for your answers !

---

<div class="post-metadata">

**Author:** ![ikarius\_2](https://avatars.discourse-cdn.com/v4/letter/i/77aa72/32.png) [@ikarius\_2](https://discuss.elastic.co/u/ikarius_2)\
**Post date:** [November 24, 2011, 5:09pm UTC](https://discuss.elastic.co/t/get-all-stored-fields-from-a-query/5962/3 "2011-11-24T17:09:30Z")

</div>

Thank you for your fast answer, will try \_source ASAP !

On 24 nov, 14:52, Shay Banon [kim...@gmail.com](mailto:kim...@gmail.com) wrote:

> I assume that when you don't specify any field, and you get nothing back,  
> is because you disabled the \_source field. If you want ot get all the  
> stored fields, then yes, you need to do: addField("\*"), why is this ugly?
> 
> Btw, most times, going each field specifically stored is wrong, and \_source  
> should be used.
> 
> On Thu, Nov 24, 2011 at 2:04 AM, ikarius [frederic.ver...@gmail.com](mailto:frederic.ver...@gmail.com) wrote:
> 
> > Hi all,
> 
> > First, i'm a beginner with ES, so .. be kind (though i've a strong  
> > background with Lucene).
> 
> > I'm trying to get all the stored fields (with a mapping) in my seach.  
> > These  
> > stored fields seems to be stored alright, thic code:
> 
> > ```
> > SearchResponse rsp = getClient().prepareSearch(INDEX_SKIMM)
> > .setSearchType(SearchType.DFS_QUERY_THEN_FETCH)
> > .setQuery(q)
> > .addField("firstname")
> > .setFrom(startIndex)
> > .setSize(limit > MAX_RESULTS ? MAX_RESULTS : limit )
> > .setExplain(true)
> > .execute()
> > .actionGet();
> > 
> > ```
> 
> > returns me the 'firstname' field in my SearchHit;
> 
> > But, if i remove the  
> > .addField("firstname")  
> > line, i do not get _ANY_ of my stored fields.
> 
> > Is it normal ?
> 
> > I've found a (ugly) workaround by adding this line in the search:  
> > .addField("\*")
> 
> > and i gain access to all stored fields.
> 
> > Thanks in advance for your answers !

---

<div class="post-metadata">

**Author:** ![ikarius\_2](https://avatars.discourse-cdn.com/v4/letter/i/77aa72/32.png) [@ikarius\_2](https://discuss.elastic.co/u/ikarius_2)\
**Post date:** [November 24, 2011, 5:12pm UTC](https://discuss.elastic.co/t/get-all-stored-fields-from-a-query/5962/4 "2011-11-24T17:12:00Z")

</div>

Well ugly was a bit too much. But is this option documented ?  
I tried this "at random" and it worked.

On 24 nov, 14:52, Shay Banon [kim...@gmail.com](mailto:kim...@gmail.com) wrote:

> I assume that when you don't specify any field, and you get nothing back,  
> is because you disabled the \_source field. If you want ot get all the  
> stored fields, then yes, you need to do: addField("\*"), why is this ugly?
> 
> Btw, most times, going each field specifically stored is wrong, and \_source  
> should be used.
> 
> On Thu, Nov 24, 2011 at 2:04 AM, ikarius [frederic.ver...@gmail.com](mailto:frederic.ver...@gmail.com) wrote:
> 
> > Hi all,
> 
> > First, i'm a beginner with ES, so .. be kind (though i've a strong  
> > background with Lucene).
> 
> > I'm trying to get all the stored fields (with a mapping) in my seach.  
> > These  
> > stored fields seems to be stored alright, thic code:
> 
> > ```
> > SearchResponse rsp = getClient().prepareSearch(INDEX_SKIMM)
> > .setSearchType(SearchType.DFS_QUERY_THEN_FETCH)
> > .setQuery(q)
> > .addField("firstname")
> > .setFrom(startIndex)
> > .setSize(limit > MAX_RESULTS ? MAX_RESULTS : limit )
> > .setExplain(true)
> > .execute()
> > .actionGet();
> > 
> > ```
> 
> > returns me the 'firstname' field in my SearchHit;
> 
> > But, if i remove the  
> > .addField("firstname")  
> > line, i do not get _ANY_ of my stored fields.
> 
> > Is it normal ?
> 
> > I've found a (ugly) workaround by adding this line in the search:  
> > .addField("\*")
> 
> > and i gain access to all stored fields.
> 
> > Thanks in advance for your answers !

---

<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:** [November 24, 2011, 6:23pm UTC](https://discuss.elastic.co/t/get-all-stored-fields-from-a-query/5962/5 "2011-11-24T18:23:38Z")

</div>

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

On Thu, Nov 24, 2011 at 7:12 PM, ikarius [frederic.vergez@gmail.com](mailto:frederic.vergez@gmail.com) wrote:

> Well ugly was a bit too much. But is this option documented ?  
> I tried this "at random" and it worked.
> 
> On 24 nov, 14:52, Shay Banon [kim...@gmail.com](mailto:kim...@gmail.com) wrote:
> 
> > I assume that when you don't specify any field, and you get nothing back,  
> > is because you disabled the \_source field. If you want ot get all the  
> > stored fields, then yes, you need to do: addField("\*"), why is this ugly?
> > 
> > Btw, most times, going each field specifically stored is wrong, and  
> > \_source  
> > should be used.
> > 
> > On Thu, Nov 24, 2011 at 2:04 AM, ikarius [frederic.ver...@gmail.com](mailto:frederic.ver...@gmail.com)  
> > wrote:
> > 
> > > Hi all,
> > 
> > > First, i'm a beginner with ES, so .. be kind (though i've a strong  
> > > background with Lucene).
> > 
> > > I'm trying to get all the stored fields (with a mapping) in my seach.  
> > > These  
> > > stored fields seems to be stored alright, thic code:
> > 
> > > ```
> > > SearchResponse rsp = getClient().prepareSearch(INDEX_SKIMM)
> > > .setSearchType(SearchType.DFS_QUERY_THEN_FETCH)
> > > .setQuery(q)
> > > .addField("firstname")
> > > .setFrom(startIndex)
> > > .setSize(limit > MAX_RESULTS ? MAX_RESULTS : limit )
> > > .setExplain(true)
> > > .execute()
> > > .actionGet();
> > > 
> > > ```
> > 
> > > returns me the 'firstname' field in my SearchHit;
> > 
> > > But, if i remove the  
> > > .addField("firstname")  
> > > line, i do not get _ANY_ of my stored fields.
> > 
> > > Is it normal ?
> > 
> > > I've found a (ugly) workaround by adding this line in the search:  
> > > .addField("\*")
> > 
> > > and i gain access to all stored fields.
> > 
> > > Thanks in advance for your answers !

---

<div class="post-metadata">

**Author:** ![ikarius\_2](https://avatars.discourse-cdn.com/v4/letter/i/77aa72/32.png) [@ikarius\_2](https://discuss.elastic.co/u/ikarius_2)\
**Post date:** [November 25, 2011, 9:42am UTC](https://discuss.elastic.co/t/get-all-stored-fields-from-a-query/5962/6 "2011-11-25T09:42:41Z")

</div>

Missed it, sorry.  
Thanks again

On 24 nov, 19:23, Shay Banon [kim...@gmail.com](mailto:kim...@gmail.com) wrote:

> Yea, its documented:[Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/search/fields.html).
> 
> On Thu, Nov 24, 2011 at 7:12 PM, ikarius [frederic.ver...@gmail.com](mailto:frederic.ver...@gmail.com) wrote:
> 
> > Well ugly was a bit too much. But is this option documented ?  
> > I tried this "at random" and it worked.
> 
> > On 24 nov, 14:52, Shay Banon [kim...@gmail.com](mailto:kim...@gmail.com) wrote:
> > 
> > > I assume that when you don't specify any field, and you get nothing back,  
> > > is because you disabled the \_source field. If you want ot get all the  
> > > stored fields, then yes, you need to do: addField("\*"), why is this ugly?
> 
> > > Btw, most times, going each field specifically stored is wrong, and  
> > > \_source  
> > > should be used.
> 
> > > On Thu, Nov 24, 2011 at 2:04 AM, ikarius [frederic.ver...@gmail.com](mailto:frederic.ver...@gmail.com)  
> > > wrote:
> > > 
> > > > Hi all,
> 
> > > > First, i'm a beginner with ES, so .. be kind (though i've a strong  
> > > > background with Lucene).
> 
> > > > I'm trying to get all the stored fields (with a mapping) in my seach.  
> > > > These  
> > > > stored fields seems to be stored alright, thic code:
> 
> > > > ```
> > > > SearchResponse rsp = getClient().prepareSearch(INDEX_SKIMM)
> > > > .setSearchType(SearchType.DFS_QUERY_THEN_FETCH)
> > > > .setQuery(q)
> > > > .addField("firstname")
> > > > .setFrom(startIndex)
> > > > .setSize(limit > MAX_RESULTS ? MAX_RESULTS : limit )
> > > > .setExplain(true)
> > > > .execute()
> > > > .actionGet();
> > > > 
> > > > ```
> 
> > > > returns me the 'firstname' field in my SearchHit;
> 
> > > > But, if i remove the  
> > > > .addField("firstname")  
> > > > line, i do not get _ANY_ of my stored fields.
> 
> > > > Is it normal ?
> 
> > > > I've found a (ugly) workaround by adding this line in the search:  
> > > > .addField("\*")
> 
> > > > and i gain access to all stored fields.
> 
> > > > Thanks in advance for your answers !

---

<div class="post-metadata">

**Author:** ![mathursharp](https://avatars.discourse-cdn.com/v4/letter/m/58f4c7/32.png) [@mathursharp](https://discuss.elastic.co/u/mathursharp)\
**Post date:** [September 9, 2013, 10:15am UTC](https://discuss.elastic.co/t/get-all-stored-fields-from-a-query/5962/7 "2013-09-09T10:15:27Z")

</div>

Hi,

Even though i enabled \_source during mapping, i am not getting results without .addField("\*"),  
I am also getting a score of 1 for all results.

Please help me 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:17am UTC](https://discuss.elastic.co/t/get-all-stored-fields-from-a-query/5962/8 "2017-07-06T02:17:32Z")

</div>


