# GetResponse.getFields() is deprecated, but no alternative?

**URL:** https://discuss.elastic.co/t/getresponse-getfields-is-deprecated-but-no-alternative/67955
**Category:** Elasticsearch
**Created:** [December 4, 2016, 4:38pm UTC](https://discuss.elastic.co/t/getresponse-getfields-is-deprecated-but-no-alternative/67955 "2016-12-04T16:38:59Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![Shai\_Erera](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/shai_erera/32/13492_2.png) [@Shai\_Erera](https://discuss.elastic.co/u/Shai_Erera)
#### Post date: [December 4, 2016, 4:38pm UTC](https://discuss.elastic.co/t/getresponse-getfields-is-deprecated-but-no-alternative/67955/1 "2016-12-04T16:38:59Z")

</div>

I use ES 5.0.2 and Transport 5.0.2. The `GetResponse.getFields()` is marked deprecated with a notice to use `.getSource()` instead. However, if I submit a Get request with `stored_fields=x,y,z`, I get back a 'fields' element, and calling `.getSource()` returns an empty map, while `getFields()` returns the stored fields.

So how should I retrieve stored fields? I know I can fetch the entire source and then filter in the client, but I wish to filter at the server side already, so I load only requested fields.

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [December 4, 2016, 5:33pm UTC](https://discuss.elastic.co/t/getresponse-getfields-is-deprecated-but-no-alternative/67955/2 "2016-12-04T17:33:41Z")

</div>

If you are storing fields then use store fields to retrieve them.  
If your JSON doc is not super big, using \_source might be better.

If you want to get both, also add \_source as on the fields you want to retrieve.

---

<div class="post-metadata">

### Author: ![Shai\_Erera](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/shai_erera/32/13492_2.png) [@Shai\_Erera](https://discuss.elastic.co/u/Shai_Erera)
#### Post date: [December 4, 2016, 7:37pm UTC](https://discuss.elastic.co/t/getresponse-getfields-is-deprecated-but-no-alternative/67955/3 "2016-12-04T19:37:41Z")

</div>

Thanks @dadoonet, but my question is about the deprecation of getFields() in the transport client. If it's deprecated, what should I use instead? Currently it looks like if I want to retrieve stored fields, I must use that API. If so, why is it deprecated?

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [December 4, 2016, 10:25pm UTC](https://discuss.elastic.co/t/getresponse-getfields-is-deprecated-but-no-alternative/67955/4 "2016-12-04T22:25:42Z")

</div>

On a mobile ATM. Is there a getStoredFields or something?

---

<div class="post-metadata">

### Author: ![Shai\_Erera](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/shai_erera/32/13492_2.png) [@Shai\_Erera](https://discuss.elastic.co/u/Shai_Erera)
#### Post date: [December 5, 2016, 8:50am UTC](https://discuss.elastic.co/t/getresponse-getfields-is-deprecated-but-no-alternative/67955/5 "2016-12-05T08:50:53Z")

</div>

No, there is no `.getStoredFields()`. Here's `.getFields()` docs:

```auto
    /**
     * @deprecated Use {@link GetResponse#getSource()} instead
     */
    @Deprecated
    public Map<String, GetField> getFields() {
        return getResult.getFields();
    }

```

And `GetResult` itself holds the fields and source in different class fields:

```auto
    private Map<String, GetField> fields;
    private BytesReference source;

```

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [December 5, 2016, 9:26am UTC](https://discuss.elastic.co/t/getresponse-getfields-is-deprecated-but-no-alternative/67955/6 "2016-12-05T09:26:44Z")

</div>

Thanks a lot Shai. Super helpful.

It's indeed a bug we introduced in [https://github.com/elastic/elasticsearch/pull/20166](https://github.com/elastic/elasticsearch/pull/20166)

We are going to add missing getStoredFields() method. @jimczi is on it 🙂

---

<div class="post-metadata">

### Author: ![Shai\_Erera](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/shai_erera/32/13492_2.png) [@Shai\_Erera](https://discuss.elastic.co/u/Shai_Erera)
#### Post date: [December 5, 2016, 9:28am UTC](https://discuss.elastic.co/t/getresponse-getfields-is-deprecated-but-no-alternative/67955/7 "2016-12-05T09:28:52Z")

</div>

Thanks @dadoonet, so I will continue to use `getFields()` until a new version of the client is released.

---

<div class="post-metadata">

### Author: ![jimczi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jimczi/32/47985_2.png) [@jimczi](https://discuss.elastic.co/u/jimczi)
#### Post date: [December 5, 2016, 2:49pm UTC](https://discuss.elastic.co/t/getresponse-getfields-is-deprecated-but-no-alternative/67955/8 "2016-12-05T14:49:36Z")

</div>

Thanks for the report @Shai_Erera. I removed the deprecation of these functions, the comment was misleading and I think that the naming is fine. The `fields` in the response are the requested stored fields + the metadata fields which is why we will continue to call it getField(s).

---

<div class="post-metadata">

### Author: ![Shai\_Erera](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/shai_erera/32/13492_2.png) [@Shai\_Erera](https://discuss.elastic.co/u/Shai_Erera)
#### Post date: [December 5, 2016, 8:06pm UTC](https://discuss.elastic.co/t/getresponse-getfields-is-deprecated-but-no-alternative/67955/9 "2016-12-05T20:06:53Z")

</div>

Thanks @jimczi!

---

<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: [January 2, 2017, 8:07pm UTC](https://discuss.elastic.co/t/getresponse-getfields-is-deprecated-but-no-alternative/67955/10 "2017-01-02T20:07:00Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
