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

(Shai Erera) #1

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.

(David Pilato) #2

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.

(Shai Erera) #3

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?

(David Pilato) #4

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

(Shai Erera) #5

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

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

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

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

(David Pilato) #6

Thanks a lot Shai. Super helpful.

It's indeed a bug we introduced in

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

(Shai Erera) #7

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

(Jimferenczi) #8

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).

(Shai Erera) #9

Thanks @jimczi!

(system) #10

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