How can I deserialize the string in the field when pulling documents with nest in c#?

Viewed 59

I'm trying to deserialize the string json value in the responseBody field. After get the documents I can deserialize this in the foreach. But I think it would be better if there is a way to do this inside SearchAsync.

var searchResponse = await elasticClient.SearchAsync<TransactionsElasticDto>(s => s
                        .Size(1000)
                        .Query(q => q
                        .DateRange(r => r
                        .Field(f => f.CreatedDate).GreaterThanOrEquals(startDate).LessThan(endDate))
                    ).Scroll("30s"))

The following is an example of a document in elasticsearch

{
        "_index" : "test_transactions_202110",
        "_type" : "_doc",
        "_source" : {
          "consumerId" : 5420,
          "createdDate" : "2021-10-06T11:58:52.2270000",
          "responseBody" : """{"ProgramId":486435,"Test":{"TestId":9728783}}"""
        }
}
0 Answers
Related