2017-03-06 4 views
1

「文字列」フィールドの変換中に再インデックスする方法を教えてください。 "field2": "123.2"(旧インデックス文書内)を浮動小数点数に変換する。 "field2":123.2(新しいインデックスに入ることを意図している)?この投稿は私が得ることができる最も近いですが、文字列を数値にキャスト/変換するために使用する関数がわかりません。私はElasticSearchバージョン2.3.3を使用しています。アドバイスをありがとうございました!!!特定のフィールド(古いインデックスにある)の文字列値を(新しいインデックスの)数値フィールド値に変換する際にインデックスを再作成する

答えて

0

Elasticsearch templatesを使用して、新しいインデックスのマッピングを指定し、そのフィールドをダブルタイプとして指定します。

テンプレートを作成する最も簡単な方法は、既存のマッピングを使用することです。

GET oldindex/_mapping 
POST _template/templatename 
{ 
    "template" : "newindex", // this can be a wildcard pattern to match indexes 
    "mappings": { // this is copied from the response of the previous call 
    "mytype": { 
     "properties": { 
     "field2": { 
      "type": "double" // change the type 
     } 
     } 
    } 
    } 
} 
POST newindex 
GET newindex/_mapping 

その後

POST _reindex 
{ 
    "source": { 
    "index": "oldindex" 
    }, 
    "dest": { 
    "index": "newindex" 
    }, 
    "script": { 
    "inline": "ctx._source.field2 = ctx._source.field2.toDouble()" 
    } 
} 

(あなたがenable inline scriptingする必要があるかもしれません)新しいインデックスに古いインデックスからデータを移動し、インラインスクリプトを使用してdoubleとしてフィールドを解析するelasticsearch _reindex APIを使用:_reindexエンドポイントを使用するように更新

+0

ありがとうございました。私の問題は、あなたが「スキャンとスクロール中にjsonを変換する」というように、あなたが記述したところにあります。私は_reindexリクエストのクエリで新しいスクリプトフィールドを作成するelasticsearchの_reindex機能で可能でなければならないと主張していますが、正確な構文や機能は基本的にどこにも見つかりませんでした。ちょうどメモ:私は* logstashを使用していない*です。 – leeway

+0

私は文字列 - > floatからフィールドのthevalueを変換するインラインスクリプトの変換関数を見つけた場合、この[1]のような仕事でしょうか? [1] http://stackoverflow.com/questions/42423899/renaming-fields-to-new-index-in-elasticsearch/42425103#42425103 – leeway

+0

元の質問で述べた文字列 - >浮動小数点数変換に最も近いポストここでは(前に非特異的であることを申し訳ありません):http://stackoverflow.com/questions/30706361/convert-strings-to-floats-at-aggregation-time – leeway

0

データを再インデックス化してフィールドを変換することができます。次のようなもの:

input { 
    elasticsearch { 
    hosts => "es.server.url" 
    index => "old_index" 
    query => "*" 
    size => 500 
    scroll => "5m" 
    docinfo => true 
    } 
} 

filter { 
    mutate { 
    convert => { "fieldname" => "long" } 
    } 
} 

output { 
    elasticsearch { 
    host => "es.server.url" 
    index => "new_index" 
    index_type => "%{[@metadata][_type]}" 
    document_id => "%{[@metadata][_id]}" 
    } 
} 
+0

ありがとうございました!残念ながら私はLogstashを使用していません。 – leeway

関連する問題