2017-08-25 43 views
0

我有一个类型为'document'的索引。它有一个名为'date'的字符串类型的字段,条目格式为“MMM dd,yyyy hh:mm:ss a”。Elasticsearch将字符串字段转换为日期

我希望将字段的数据类型从字符串转换为日期,这是不可能的。 因此,我已经修改了映射以添加一个新的字段“张贴”类型'日期'和格式。我现在需要将日期字段中的值更改为日期对象后将其复制到发布字段中。我试着下面的更新查询

POST /my-index/document/_update_by_query 
{ 
    "query" : { 
     "match_all" : {} 
    }, 
    "script": "ctx._source['posted'] = new Date().parse(\"MMM dd, yyyy hh:mm:ss a\",ctx._source['date'])" 
} 

但它给我这个错误,

java.lang.String cannot be cast to java.util.Map 

我要去哪里错了?

回答

0

您不需要在脚本中创建Date类型,只需将值分配给posted字段,Elasticsearch将在索引操作发生时执行其余操作。

你还需要改变你的脚本

"script": { 
    "inline": "ctx._source['posted'] = ctx._source.foo" 
} 
+0

“脚本”的结构:“ctx._source [‘贴’] = ctx._source [‘日期’]”仍然给我相同的错误 –

+0

点击发送提前,还修复了脚本 – alr

+0

“script”:“ctx._source ['posted'] = ctx._source.date”仍然给出了同样的错误 –