1

I am trying to use persistence API, using elasticsearch-dsl version 6.2.1 as follow:

class MyClass(Document):
    start = Date(format='dd-MM-yyyy HH:mm:ss:SSS')
    stop = Date(format='dd-MM-yyyy HH:mm:ss:SSS')

When I call MyClass.init() I see (through Kibana) that indeed the mapping is as I expected:

    "start": {
      "type": "date",
      "format": "dd-MM-yyyy HH:mm:ss:SSS"
    },
    "stop": {
      "type": "date",
      "format": "dd-MM-yyyy HH:mm:ss:SSS"
    }

I have variable my_instance which is an instance of MyClass. my_instance.start and my_instance.stop hold strings like '15-06-2018 02:54:05:382'

When I call my_instance.save() I get the following exception:

elasticsearch_dsl.exceptions.ValidationException: {'start': 
[ValidationException("Could not parse date from the value ('15-06-2018 
02:54:05:281')", ValueError('Unknown string format:', '15-06-2018 
02:54:05:281'))], 'stop': [ValidationException("Could not parse date from the 
value ('15-06-2018 02:54:05:382')", ValueError('Unknown string format:', '15- 
06-2018 02:54:05:382'))]}

What am I doing wrong?

miki
  • 13
  • 3

1 Answers1

1

Unfortunately elasticsearch-dsl currently only supports dates in ISO format. If you want to use any other format you need to specify the (de) serialization yourself.

Honza Král
  • 2,982
  • 14
  • 11
  • Thanks, I replaced last colon with period i.e. `dd-MM-yyyy HH:mm:ss.SSS` to make it work. By specifying the (de) serialization you mean I should derive from `Date()` i.e. `class MyDate(Date)` and override `deserialize`? – miki Jul 18 '18 at 07:45
  • exactly. You can also create completely custom field by extending `CustomField` (see examples in tests). – Honza Král Jul 19 '18 at 17:36