2017-08-25 142 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」仍然給出了同樣的錯誤 –