0

Is it possible to convert date to milliseconds? From below type(Table) when i want retrieve data of JoinDate column should show time in total Milliseconds.

Example 2010-10-12 13:10:10 (Time)==>1291966810000(Millisecond)

 ----------------------------------
|S.No | ID   |  JoinDate          |
 ----------------------------------
| 1   | N107 | 2010-10-12 13:10:10 |
|     |      |                     |
| 2   | N108 | 2011-2-12 10:40:10  |
|     |      |                     |
| 3   | N109 | 2013-10-12 11:10:50 |
|     |      |                     |
------------------------------------
3
  • So what you are asking is whether it is possible to convert an SQL date into a date field expressed in milliseconds when exporting your data from an SQL DB into Elasticsearch?
    – Val
    Commented Nov 16, 2015 at 6:13
  • no i need to get milliseconds when we are fetching data from elastic search table @Val
    – PRK449
    Commented Nov 16, 2015 at 10:38
  • Can you update your question with the current query you have? Eventually also your mapping type configuration?
    – Val
    Commented Nov 16, 2015 at 10:41

2 Answers 2

7

try something like

{
  "query": {
    "match_all": {}
  },
  "script_fields": {
    "JoinDate": {
      "script": "doc['JoinDate'].date.getMillis()"
    }
  }
}
1
  • 1
    This answer covers lang. painless. Thank you!
    – Dex
    Commented Dec 18, 2017 at 14:12
0

Also, you can use this

{
  "query": {
    "match_all": {}
  },
  "script_fields": {
    "createddate": {
      "lang": "painless",
      "script": "doc['createddate'].value.millis"
    }
  }
}

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.