From 232f6db2f7db5d854e78af452970eed14d3296ae Mon Sep 17 00:00:00 2001 From: urso Date: Mon, 12 Feb 2018 19:21:52 +0100 Subject: [PATCH] document id must be a string --- filebeat/input/log/harvester.go | 2 +- libbeat/reader/readjson/json.go | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/filebeat/input/log/harvester.go b/filebeat/input/log/harvester.go index f2bed44c6deb..fd5c8c8dd6d0 100644 --- a/filebeat/input/log/harvester.go +++ b/filebeat/input/log/harvester.go @@ -370,7 +370,7 @@ func (h *Harvester) onMessage( timestamp = ts } - if id != nil { + if id != "" { meta = common.MapStr{ "id": id, } diff --git a/libbeat/reader/readjson/json.go b/libbeat/reader/readjson/json.go index e6e055417e8b..a669b3f49ae0 100644 --- a/libbeat/reader/readjson/json.go +++ b/libbeat/reader/readjson/json.go @@ -114,7 +114,7 @@ func createJSONError(message string) common.MapStr { // respecting the KeysUnderRoot and OverwriteKeys configuration options. // If MessageKey is defined, the Text value from the event always // takes precedence. -func MergeJSONFields(data common.MapStr, jsonFields common.MapStr, text *string, config Config) (interface{}, time.Time) { +func MergeJSONFields(data common.MapStr, jsonFields common.MapStr, text *string, config Config) (string, time.Time) { // The message key might have been modified by multiline if len(config.MessageKey) > 0 && text != nil { jsonFields[config.MessageKey] = *text @@ -127,12 +127,14 @@ func MergeJSONFields(data common.MapStr, jsonFields common.MapStr, text *string, data["message"] = *text } - var id interface{} + var id string if key := config.DocumentID; key != "" { if tmp, err := jsonFields.GetValue(key); err == nil { - id = tmp + if v, ok := tmp.(string); ok { + id = v + jsonFields.Delete(key) + } } - jsonFields.Delete(key) } if config.KeysUnderRoot {