Skip to content

Commit

Permalink
[Monitoring] Use op_type = create with ES version >= 7.5.0 (elastic#1…
Browse files Browse the repository at this point in the history
…4313) (elastic#14372)

* Use op_type = create with ES version >= 7.5.0

* Initialize map

* Printing out logs for debugging

* Removing debugging logs
  • Loading branch information
ycombinator authored Nov 7, 2019
1 parent 4bdf333 commit 87ad0f4
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions libbeat/monitoring/report/elasticsearch/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ import (
"github.com/elastic/beats/libbeat/testing"
)

var createDocPrivAvailableESVersion = common.MustNewVersion("7.5.0")

type publishClient struct {
es *esout.Client
params map[string]string
Expand Down Expand Up @@ -185,13 +187,19 @@ func (c *publishClient) publishBulk(event publisher.Event, typ string) error {
"_routing": nil,
}

if c.es.GetVersion().Major < 7 {
esVersion := c.es.GetVersion()
if esVersion.Major < 7 {
meta["_type"] = "doc"
}

action := common.MapStr{
"index": meta,
action := common.MapStr{}
var opType string
if esVersion.LessThan(createDocPrivAvailableESVersion) {
opType = "index"
} else {
opType = "create"
}
action[opType] = meta

event.Content.Fields.Put("timestamp", event.Content.Timestamp)

Expand Down

0 comments on commit 87ad0f4

Please sign in to comment.