2017-10-21 13 views
1

円グラフを作成するときに、フィールドmyfield(すなわち、""に等しい)の空の値をすべて"Others"で置き換えたいとします。木場でどうすればいいですか?Elasticsearchで空白/空白の値を「その他」に置き換えるにはどうすればよいですか?

木場で行うことが不可能な場合は、どのようにしてElasticsearchを使用して行うことができますか?

enter image description here

UPDATE:

私はこのクエリを実行し、それは私にエラーを与えていない:

GET myindex/entry/_update_by_query 
{ 
    "query":{ 
    "term": { 
     "myfield.keyword": { 
     "value": "" 
     } 
    } 
    }, 
    "script":{ 
    "inline": "ctx._source.myfield = 'Other'", 
    "lang": "painless" 
    } 
} 

私はこの出力を得る:

{ 
    "took": 5, 
    "timed_out": false, 
    "total": 0, 
    "updated": 0, 
    "deleted": 0, 
    "batches": 0, 
    "version_conflicts": 0, 
    "noops": 0, 
    "retries": { 
    "bulk": 0, 
    "search": 0 
    }, 
    "throttled_millis": 0, 
    "requests_per_second": -1, 
    "throttled_until_millis": 0, 
    "failures": [] 
} 

しかし、の値をチェックするとの場合、Otherではなく、""の値が再取得されます。

GET myindex/_search? 
{ 
"size":0, 
    "aggs": { 
    "months": { 
    "terms" : { 
     "field": "myfield" 
    } 
    } 
    } 
} 

これは私のインデックスマッピングです:

PUT /myindex 
{ 
    "mappings": { 
     "entry": { 
     "_all": { 
     "enabled": false 
     }, 
     "properties": { 
      "Id": { 
      "type":"keyword" 
      }, 
      "Country": { 
      "type":"keyword" 
      }, 
      "myfield": { 
      "type":"keyword" 
      }, 
      "Year": { 
      "type":"integer" 
      }, 
      "Counter": { 
      "type":"integer" 
      } 
     } 
     } 
    } 
} 

答えて

1

私の知る限りでは、これはKibanaの最後に行うことはできません。空のフィールド文書をすべてElasticsearchインデックスの "Others"で更新できます。

エラスティックサーチの更新を行うには、Update By Query APIを使用できます。以下は、更新コード/クエリです。

GET myindex/entry/_update_by_query 
{ 
    "query":{ 
    "term": { 
     "myfield": { 
     "value": "" 
     } 
    } 
    }, 
    "script":{ 
    "inline": "ctx._source.myfield = 'Other'", 
    "lang": "painless" 
    } 
} 
+0

ありがとうございます。 'ctx'と' _source'とは何ですか? – Dinosaurius

+0

'' parse_exception': 'reason": "[inline]、[file]、または[stored]フィールドのうち期待されているものは見つかりましたが、どれも見つかりません" – Dinosaurius

+0

あなたが取り組んでいるESバージョンはどれですか? –

0

あなたは、実行時に、あなたのインデックスに新しい文字列型スクリプトフィールドを作成しますKibanaで無痛スクリプト、この種のを試みることができます。

[管理 - > name_of_your_index - >スクリプトフィールド] - > [スクリプトフィールドの追加]を選択します。

次へ:スクリプトに名前を付け、そのタイプを "string"に設定します。その後

def source = doc['name_of_the_field'].value; 
if (source != null) { return source; } 
else { return "Other";} 

次に、あなたの可視化では、この新しいフィールドを使用します。

関連する問題