2

I'm able to enable timestamp on a mapping like this :

"someType" as (
   "someField" typed StringType
) timestamp true

But to be able to retrieve it when searching using "fields": ["_timestamp"] it also needs to have store attribute set to true. But if I do this :

"someType" as (
   "someField" typed StringType,
   "_timestamp" typed LongType/DateType store true
) timestamp true

Then it is not returned by _search:

GET /myIndex/someType/_search 
{
  "fields": ["_timestamp"],
  "query" : {
     "match_all" : {}
    }
}

The resulting mapping looks like this :

"someType": {
    "dynamic": "dynamic",
    "_timestamp": {
       "enabled": true
    },
    "properties": {
        "_timestamp": {
          "store": "yes",
          "type": "long"
       }
    }

}

But I've got a feeling that it should be like this :

"someType": {
    "dynamic": "dynamic",
    "_timestamp": {
       "enabled": true,
       "store": true
    },
    "properties": {
        "_timestamp": {
          "store": "yes",
          "type": "long"
       }
    }
    }

Which cannot be done using elastic4s Dsl because it doesn't have a special handling for fields named _timestamp so that the field goes to properties instead of fields in that mapping...

lisak
  • 21,611
  • 40
  • 152
  • 243

1 Answers1

1

Elastic4s version 1.5.7 allows you to set the timestamp like this:

create index("myindex") mappings(
  mapping name "foo" timestamp {
    timestamp enabled true format "qwerty" store true path "somepath"
  }
)

Path, format, and store are optional.

sksamuel
  • 16,154
  • 8
  • 60
  • 108
  • thank you, I think you forgot to update the `timestamp` method, only `TimestampDefinition` is updated with the `store` attribute. https://github.com/sksamuel/elastic4s/blob/c208850f1d650eb9de8ef64d837526f735d6f1a9/src/main/scala/com/sksamuel/elastic4s/mappings/MappingDefinition.scala#L77 – lisak Apr 29 '15 at 19:46
  • Or should we rather use the `mapping name` convention? It can be done 2 ways now. – lisak Apr 29 '15 at 19:50
  • the existing timestamp method is overloaded, so you can actually do `timestamp(name, store=Some(true))` which isn't as nice as the DSL. – sksamuel Apr 29 '15 at 20:04
  • I've added a method in 1.5.8 (not released yet) that will allow you to do timestamp(name).store(true).path("path") etc – sksamuel Apr 29 '15 at 20:09
  • Just one last thing, how come that after using this mapping for creating both index and template, there is `store: true` in index and `store: "yes"` in template mapping responses? Does ES have some sort of politics regarding boolean evaluation that it doesn't matter if it is `true` or `"yes"` and uses them randomly :-) ? – lisak Apr 29 '15 at 20:51
  • I don't know, the docs don't specify the store option at all on timestamp but all the examples I found had "yes". – sksamuel Apr 29 '15 at 22:25
  • Please one last thing, I needed it for range query `searchDsl range "_timestamp" from fromDate to toDate` but it seems that `SearchDsl` lost support for `range` queries because it doesn't let you to chain `from` and `to` range constraints, is that correct? – lisak Apr 30 '15 at 07:08
  • Got it, it must be `searchDsl query { rangeQuery "_timestamp" from fromDate to toDate }` – lisak Apr 30 '15 at 07:20