3

I followed

and https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-date-format.html but I could not find the answer that required .

I created index using

 GET film/_mapping

Also as per the accepted answer in Elasticsearch: Datatype for time(HH:mm:ss.SSS) field

I created my mapping as per below .

PUT film/_mapping 
{
  
  "properties": {
    "filmname": {
      "type": "keyword"
    },
    "runtime": {
      "type": "date",
      "format": "hour_minute_second_fraction"
    },
      "genre": {
      "type": "text"
    },
    "releasedate":{
      "type": "date",
      "format": "yyyy-MM-dd"
    },
    "budget":{
      "type": "double"
    }
  }
}

I tried to add a document using below request .

PUT film/_doc/1/
{
  "film": "The Terminator",
  "runtime": "12_50_30_40",
  "genre": "SCIFI war Action",
  "releasedate": "1984-11-30",
  "budget" : "45.12"
}

But it throws the attached error , actually I want to add this field only in hour_minute_second format. enter image description here

Sameera De Silva
  • 1,722
  • 1
  • 22
  • 41

1 Answers1

4

The format expected by hour_minute_second_fraction is HH:mm:ss.SSS, so in your case, it would mean 12:50:30.400

If you want to keep using 12_50_30_40, then you need to set your own format, like this:

"runtime": {
  "type": "date",
  "format": "HH_mm_ss_SS"
},
Val
  • 207,596
  • 13
  • 358
  • 360
  • Thanks a lot Val ,both worked . In mapping I gave like "format":"HH:mm:ss" and value as "12:50:30" . Have a nice day. – Sameera De Silva Oct 16 '20 at 07:52
  • By the way since you are expert on ElK Slack , could you please look at this as well , I'm new to this tool though and this is bit of an out of the box question. https://stackoverflow.com/questions/64256088/elasticsearch-what-are-the-formulas-to-calculate-total-shards – Sameera De Silva Oct 16 '20 at 08:39