Skip to content

Commit

Permalink
Ignore doc type in ES search API for ES 8
Browse files Browse the repository at this point in the history
  • Loading branch information
jsoriano committed May 10, 2019
1 parent 056d921 commit 01e3d87
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 5 additions & 0 deletions libbeat/outputs/elasticsearch/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import (
"strconv"

"github.com/pkg/errors"

"github.com/elastic/beats/libbeat/common"
)

// QueryResult contains the result of a query.
Expand Down Expand Up @@ -235,6 +237,9 @@ func (es *Connection) SearchURIWithBody(
params map[string]string,
body interface{},
) (int, *SearchResults, error) {
if !es.version.LessThan(&common.Version{Major: 8}) {
docType = ""
}
status, resp, err := es.apiCall("GET", index, docType, "_search", "", params, body)
if err != nil {
return status, nil, err
Expand Down
4 changes: 2 additions & 2 deletions libbeat/outputs/elasticsearch/api_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func TestIndex(t *testing.T) {
}
_, result, err := client.SearchURIWithBody(index, "", nil, map[string]interface{}{})
if err != nil {
t.Errorf("SearchUriWithBody() returns an error: %s", err)
t.Fatalf("SearchUriWithBody() returns an error: %s", err)
}
if result.Hits.Total.Value != 1 {
t.Errorf("Wrong number of search results: %d", result.Hits.Total.Value)
Expand All @@ -72,7 +72,7 @@ func TestIndex(t *testing.T) {
}
_, result, err = client.SearchURI(index, "test", params)
if err != nil {
t.Errorf("SearchUri() returns an error: %s", err)
t.Fatalf("SearchUri() returns an error: %s", err)
}
if result.Hits.Total.Value != 1 {
t.Errorf("Wrong number of search results: %d", result.Hits.Total.Value)
Expand Down

0 comments on commit 01e3d87

Please sign in to comment.