Skip to content

Commit 01e3d87

Browse files
committed
Ignore doc type in ES search API for ES 8
1 parent 056d921 commit 01e3d87

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

libbeat/outputs/elasticsearch/api.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ import (
2323
"strconv"
2424

2525
"github.com/pkg/errors"
26+
27+
"github.com/elastic/beats/libbeat/common"
2628
)
2729

2830
// QueryResult contains the result of a query.
@@ -235,6 +237,9 @@ func (es *Connection) SearchURIWithBody(
235237
params map[string]string,
236238
body interface{},
237239
) (int, *SearchResults, error) {
240+
if !es.version.LessThan(&common.Version{Major: 8}) {
241+
docType = ""
242+
}
238243
status, resp, err := es.apiCall("GET", index, docType, "_search", "", params, body)
239244
if err != nil {
240245
return status, nil, err

libbeat/outputs/elasticsearch/api_integration_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func TestIndex(t *testing.T) {
6161
}
6262
_, result, err := client.SearchURIWithBody(index, "", nil, map[string]interface{}{})
6363
if err != nil {
64-
t.Errorf("SearchUriWithBody() returns an error: %s", err)
64+
t.Fatalf("SearchUriWithBody() returns an error: %s", err)
6565
}
6666
if result.Hits.Total.Value != 1 {
6767
t.Errorf("Wrong number of search results: %d", result.Hits.Total.Value)
@@ -72,7 +72,7 @@ func TestIndex(t *testing.T) {
7272
}
7373
_, result, err = client.SearchURI(index, "test", params)
7474
if err != nil {
75-
t.Errorf("SearchUri() returns an error: %s", err)
75+
t.Fatalf("SearchUri() returns an error: %s", err)
7676
}
7777
if result.Hits.Total.Value != 1 {
7878
t.Errorf("Wrong number of search results: %d", result.Hits.Total.Value)

0 commit comments

Comments
 (0)