2017-01-26 4 views
0

私は弾性検索のフィールド "published_date"を持っています。yyyy-MM-dd'T'HH:mm:ssのような完全な日付があります。既存の列の値を使用して弾性検索のすべてのドキュメントを更新します

私は新しい3列を更新するために、既存のpublished_dateを使用する必要が日付のために3つの以上の列を作成します。

e.s.でこの種の作業を行うためのinbuilt APIはありますか?私はelasticsearchを使用しています。5

答えて

0

これを行うにはupdate-by-query APIを使用できます。これは、単にこのような何かを実行するに煮詰めるます:

POST your_index/_update_by_query 
{ 
    "script": { 
    "inline": "ctx._source.year = ctx._source.published_date.date.getYear(); ctx._source.month = ctx._source.published_date.date.getMonthOfYear(); ctx._source.day = ctx._source.published_date.date.getDayOfYear(); ", 
    "lang": "groovy" 
    }, 
    "query": { 
    "match_all": {} 
    } 
} 

はまた、あなたが動作するには、このためには enable dynamic scriptingに必要なことに注意してください。

+0

このエラーが発生しました ctx._source.year = ctx._source.created_date.date.getYear();を評価する際にエラーが発生しました。 ctx._source.month = ctx._source.created_date.date.getMonthOfYear(); ctx._source.day = ctx._source.created_date.date.getDayOfYear(); --- このようなプロパティはありません:クラスの日付:java.lang.String \ n可解:バイト –

+0

これは、 'published_date'フィールドが' date'型ではなく単に文字列であることを意味します。あなたのマッピングは 'curl -XGET localhost:9200/your_index'のように見えますか? – Val

+0

値:::: "created_date": "2016-12-04T02:13:53.707Z"、 ---------- マッピング::: "created_date":{ "type": " "format": "dateOptionalTime" ------- 実際の列名は "created_date" –

関連する問題