How to use ttl in elasticsearch bulk api (NEST)

804 views Asked by At

I'm trying to use bulk API using NEST client. How can I specify a TTL value based on an attribute of a collection. Consider the following code snippet, how can I specify a "ttl" to say person.Age > 50 --> 1 month, otherwise 6 months?:

var coll = new List<Person>();
// fill the collection from db etc...

var desc = new BulkDescriptor();
foreach(var p in coll)
{
    //  desc.Index<Person>( .... );  
    //  How can I say, "if person.Age > 50, ttl = 1 month, otherwise 6 months?
}

var result = client.Bulk(desc);
1

There are 1 answers

1
Greg Marzouka On BEST ANSWER
desc.Index<Person>(i => i
    .Document(p)
    .Ttl(p.Age > 50 ? "1M" : "6M")
);