Skip to content

FieldValues inference converts timestamp strings to date/times then to string in different format #2155

@wewebber

Description

@wewebber

NEST/Elasticsearch.Net version: 2.4.1

Elasticsearch version: 2.33

Description of the problem including expected versus actual behavior:

If we have a string field holding a value that happens to look like a timestamp, and retrieve that field through a Fields() query, the field will get reformatted into a different form of date / time.

E.g. we have the mapping:

"mything" : {
    "myname" : {
       "type" : "string"
    }
}

fronted by the class:

public class MyThing
{
    [String]
    public string MyName { get; set; }
}

We insert the following mything:

new MyThing() { MyName = "2016-07-12T06:06:35.203Z" }

and do a search like:

var name = client.Search<MyThing>(sd => sd.Fields(fd => fd.Field(mt => mt.MyName)))
              .Fields.Select(fv => fv.Values<MyThing, string>(mt => mt.MyName)[0]).ToArray().[0]

We'll then find that name has a value like "12/07/2016 06:06:35" (depending I think on language settings).

The culprit I think is in

, where NEST uses Newtonsoft.Json.Linq.JArray to infer the type of the field. It infers it to be some sort of DateTime, then does a ToString() on that DateTime.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions