Skip to content

Commit

Permalink
document id must be a string
Browse files Browse the repository at this point in the history
  • Loading branch information
urso committed Sep 18, 2019
1 parent 0b9b43c commit 232f6db
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion filebeat/input/log/harvester.go
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ func (h *Harvester) onMessage(
timestamp = ts
}

if id != nil {
if id != "" {
meta = common.MapStr{
"id": id,
}
Expand Down
10 changes: 6 additions & 4 deletions libbeat/reader/readjson/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down

0 comments on commit 232f6db

Please sign in to comment.