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

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.

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.

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?

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

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;

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:

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

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

Thanks @jimczi!

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