如何使elastic4s存储_timestamp字段?

时间:2015-04-29 15:02:23

标签: scala elasticsearch elastic4s

我可以在这样的映射上启用时间戳:

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

但是,为了能够在使用"fields": ["_timestamp"]进行搜索时检索它,还需要将store属性设置为true。但如果我这样做:

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

然后_search不会返回它:

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

结果映射如下所示:

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

}

但我觉得它应该是这样的:

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

使用elastic4s Dsl无法完成,因为它没有对名为_timestamp的字段进行特殊处理,因此该字段转到属性而不是该映射中的字段...

1 个答案:

答案 0 :(得分:1)

Elastic4s 1.5.7版允许您设置如下的时间戳:

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

路径,格式和商店是可选的。