c# - How does attribute mapping for the NEST Elasticsearch client work for date times -


i have c# object using index documents existing type in elasticsearch.

the object has datetime field want configure mapping using nest clients attribute based mapping. looking configure format dateformat.basic_date_time_no_millis. hopping strip out milliseconds date time object. class being used document index below.

public class dbqueuedepth {     public string queuename { get; set; }     public int processedcount { get; set; }     public int notprocessedcount { get; set; }     public string environment { get; set; }      [date(format = dateformat.basic_date_time_no_millis)]     public datetime sampletimestamp { get; set; } } 

the type being mapped in elasticsearch is;

    "dbqueuedepth": {     "properties": {       "environment": {         "type": "text"       },       "notprocessedcount": {         "type": "integer"       },       "processedcount": {         "type": "integer"       },       "queuename": {         "type": "text"       },       "sampletimestamp": {         "type": "date",         "format": "date_time_no_millis"       }     } 

my client code

        var node = new uri("http://localhost:9200");          var settings =             new connectionsettings(node).maximumretries(10)                 .maxretrytimeout(new timespan(0, 0, 0, 10))                 .defaultindex("austin_operational_data")                 .infermappingfor<dbqueuedepth>(i => i.typename("dbqueuedepth"));           elasticclient client = new elasticclient(settings);         var response = client.indexmany(rows); 

when try , index document receive following error.

{index returned 400 _index: operational_data _type: dbqueuedepth _id: av5rqc3g6arlsamjzplk _version: 0 error: type: mapper_parsing_exception reason: "failed parse [sampletimestamp]" causedby: type: illegal_argument_exception reason: "invalid format: "2017-09-10t12:00:41.9926558z" malformed @ ".9926558z""}

am correct in expecting nest client strip out milliseconds based on formatting in date attribute ?

is infermappingfor method instructing client use formatting designated attributes on c# object?

your assumption not quite right. format on date field controls how date string in request parsed on server side in elasticsearch i.e. tells elasticsearch in format expect string.

now, use format in conjunction jsonconverter serialize datetime format not emit milliseconds. however, approach instead removing milliseconds datetime instance within application code (perhaps in property setter) , leaving format , serialization is.


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -