Extracting @timestamp from Source within Hits

I am trying to extract @timestamp from .Source but whenever I type a dot after the word Source I do not get any options that Source can contain where I can grab @timestamp. Is there a specific way I can grab @timestamp from Source? I am using this in my application using elasticsearch NEST. Once I grab the @timestamp I am planning on sending it to my database.

Is there a way I can extract @timestamp so I can set var time to it?

enter image description here

So when you are debugging you can see the key value pair that holds @timestamp:

enter image description here

The only options I get when I do Source. are .ToString, .GetType, GetHashCode, Equals, Suffix

This is my attempt:

public async Task<int> InsertLogData()
        {

            SqlConnection connection = null;
            SqlCommand command = null;
            int numrows = 0;

            try
            {
                var response = await _elasticClient.SearchAsync<Object>(s => s
                    .Size(3000)
                    .Index("customer-simulation-es-app-logs*")
                    .Query(q => +q
                        .DateRange(dr => dr
                            .Field("@timestamp")
                                .GreaterThanOrEquals("2021-06-07T17:13:54.414-05:00")
                                .LessThanOrEquals(DateTime.Now))));

                connection = new SqlConnection("Data Source=.\\SQLExpress;Database=ElasticSearchService;Trusted_Connection=True;");
               

                foreach (var item in response.Hits)
                {
                    var id = item.Id;
                 //   var time = item.Source here is where i want to grab @timestamp
                    var sourceItem = item.Source;

                    var json = _elasticClient.RequestResponseSerializer.SerializeToString(sourceItem);

                    command = new SqlCommand("INSERT INTO EsLogs (ELKLogID, LogMessage, DateCreated) VALUES ('" + id + "','" + json + "', '" + /*time*/ + "')", connection);
                }


                connection.Open();
                numrows = command.ExecuteNonQuery();

            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
}

enter image description here

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