# Extracting @timestamp from Source within Hits

**URL:** <https://discuss.elastic.co/t/extracting-timestamp-from-source-within-hits/278306>\
**Category:** Elasticsearch\
**Created:** [July 9, 2021, 8:22pm UTC](https://discuss.elastic.co/t/extracting-timestamp-from-source-within-hits/278306 "2021-07-09T20:22:56Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![NoviceESCoder](https://avatars.discourse-cdn.com/v4/letter/n/ec9cab/32.png) [@NoviceESCoder](https://discuss.elastic.co/u/NoviceESCoder)\
**Post date:** [July 9, 2021, 8:22pm UTC](https://discuss.elastic.co/t/extracting-timestamp-from-source-within-hits/278306/1 "2021-07-09T20:22:56Z")

</div>

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](https://i.stack.imgur.com/NNcr3.png)](https://i.stack.imgur.com/NNcr3.png)

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

[![enter image description here](https://i.stack.imgur.com/oeJo2.png)](https://i.stack.imgur.com/oeJo2.png)

_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](https://i.stack.imgur.com/sgw6I.png)](https://i.stack.imgur.com/sgw6I.png)

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [August 6, 2021, 8:23pm UTC](https://discuss.elastic.co/t/extracting-timestamp-from-source-within-hits/278306/2 "2021-08-06T20:23:42Z")

</div>

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