1

I'm currently facing an issue with my elasticsearch, when i'm trying to fetch data from it.

I have a timestamp value that gets saved like the following:

Timestamp = DateTime.UtcNow;

And the Timestamp property is looking like this in my object

public DateTime Timestamp { get; }

When using Kibana to look at the data the timestamp has the following value:

timestamp:June 19th 2019, 16:29:24.997

When I try to retrieve the data with the following code:

var searchResponse = await elastic.SearchAsync<SupplierPricelistStatistic>(s => s
                .From(0)
                .Take(2000)
                .Query(q => +q
                    .Match(m => m
                        .Field(f => f.SupplierId)
                        .Query(id.ToString())
                    )
                )
                .Scroll("10m")
            ).ConfigureAwait(false);

And loop through it like this:

var resultList = new List<SupplierPricelistStatistic>();

        while (searchResponse.Documents.Any())
        {
            foreach (var doc in searchResponse.Hits)
            {
                resultList.Add(doc.Source);
            }
            searchResponse = await elastic.ScrollAsync<SupplierPricelistStatistic>("10m", searchResponse.ScrollId);
        }

All of my timestamps has the following value:

{01-01-0001 00:00:00}

Looking at the mapping for timestamp it looks like the following:

 "timestamp": {
          "type": "date"
        }

I can't figure out why this is happening. Maybe i'm missing some configuration somewhere?

EDIT:

Upon request:

I'm using NEST version 6.6.0 and elasticsearch 6.6.2

Complete method for collecting data:

public async Task <List<SupplierPricelistStatistic>> GetSupplierPricelistStatistic(Guid id, IElasticClient elastic, int year, string month)
        {
            var searchResponse = await elastic.SearchAsync<SupplierPricelistStatistic>(s => s
                .From(0)
                .Take(2000)
                .Query(q => +q
                    .Match(m => m
                        .Field(f => f.SupplierId)
                        .Query(id.ToString())
                    )
                )
                .Scroll("10m")
            ).ConfigureAwait(false);

        var resultList = new List<SupplierPricelistStatistic>();

        while (searchResponse.Documents.Any())
        {
            foreach (var doc in searchResponse.Hits)
            {
                var tempSupStat = doc.Source;
                DateTime dateTime;
                if (month != "0")
                {
                    int.TryParse(month, out int intMonth);
                    dateTime = new DateTime(year, intMonth, DateTime.Now.Day);
                    if (tempSupStat.Timestamp.Year == dateTime.Year && tempSupStat.Timestamp.Month == dateTime.Month)
                    {
                        resultList.Add(tempSupStat);
                    }
                }
                else
                {
                    dateTime = new DateTime(year, DateTime.Now.Month, DateTime.Now.Day);
                    if (tempSupStat.Timestamp.Year == dateTime.Year)
                    {
                        resultList.Add(tempSupStat);
                    }
                }
            }
            searchResponse = await elastic.ScrollAsync<SupplierPricelistStatistic>("10m", searchResponse.ScrollId);
        }

        return resultList;
    }
2
  • What version of NEST are you using, and what version of Elasticsearch are you targeting? Could you please show a small, succinct but complete example of what you're doing and what you're seeing? Commented Jun 19, 2019 at 23:43
  • I have added more information. I hope it's enough Commented Jun 20, 2019 at 8:49

1 Answer 1

1

So i just looked over my model again

public DateTime Timestamp { get; }

It did not have a setter. Adding one fixed the issue.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.