_ttl metafield in IGetResponse

Hi everyone!

Could someone help with reading _ttl metafield from the response of Get API? Here is typical response containing _ttl field:

{ "_index" : "attachment-v2", "_type" : "attachments", "_id" : "f2a7fcc7-0c04-45d6-8a8d-a9d604d28612", "_version" : 1, "_routing" : "Ida36e508a-9020-42e2-8c67-bb58987e7fb2", "_ttl" : 1898062282, "_parent" : "Ida36e508a-9020-42e2-8c67-bb58987e7fb2", "found" : true }

Corresponding GetResponse class contains fields Type, Index and so on but doesn't contain field for _ttl. GetResponse.Fields also doesn't contain _ttl field even if _ttl was included in fields parameter of the request.

I'm using NEST 2.4. In the NEST 1.x _ttl field was in the .FieldsValues.

Hello Kirill_Teplinskiy,

The _ttl is the per document time to live. It specifies when the document will expire/get deleted.

As of 2.0.0-beta2, this field has been deprecated.

Please, refer to https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-ttl-field.html


Thanks for the answer!

I know about deprecation of _ttl field and the ways to avoid using _ttl. However, the field is still returned in the response and setting TTL is still supported by ES and NEST. Also, _ttl field exists in IHit. Shouldn't it be in the GetResponse too?

Hey @Kirill_Teplinskiy! It looks like this and some other metadata fields were missed from IGetResponse<T> in the 2.x refactoring; I've added an issue to address this.

In the meantime, you can work around this by deserializing the response yourself using the lowlevel client, defining a type that has the missing metafields. Let me know if you need some pointers here and I can drum up an example.

@forloop Thanks for the answer!

Another way to work around this is using .Search with .Ids and calling Hits.Single().Ttl on the result.

That'll work too :slight_smile:

I've submitted a PR to get this in the next release :thumbsup: