Skip to content

Commit

Permalink
Elasticsearch: Fix using multiple indexes with comma separated string (
Browse files Browse the repository at this point in the history
…#71284)

* Revert "Elasticsearch: Use array of strings as index in backend queries (#67276)"

This reverts commit d0ced39.

* updated tests

(cherry picked from commit e17540b)
  • Loading branch information
gabor authored and grafana-delivery-bot[bot] committed Jul 11, 2023
1 parent eeba36e commit 74d3036
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion pkg/tsdb/elasticsearch/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ func (c *baseClientImpl) createMultiSearchRequests(searchRequests []*SearchReque
header: map[string]interface{}{
"search_type": "query_then_fetch",
"ignore_unavailable": true,
"index": c.indices,
"index": strings.Join(c.indices, ","),
},
body: searchReq,
interval: searchReq.Interval,
Expand Down
12 changes: 6 additions & 6 deletions pkg/tsdb/elasticsearch/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func TestClient_ExecuteMultisearch(t *testing.T) {
jBody, err := simplejson.NewJson(bodyBytes)
require.NoError(t, err)

assert.Equal(t, []string{"metrics-2018.05.15"}, jHeader.Get("index").MustStringArray())
assert.Equal(t, "metrics-2018.05.15", jHeader.Get("index").MustString())
assert.True(t, jHeader.Get("ignore_unavailable").MustBool(false))
assert.Equal(t, "query_then_fetch", jHeader.Get("search_type").MustString())
assert.Empty(t, jHeader.Get("max_concurrent_shard_requests"))
Expand All @@ -116,25 +116,25 @@ func TestClient_Index(t *testing.T) {
name string
indexInDatasource string
patternInDatasource string
indexInRequest []string
indexInRequest string
}{
{
name: "empty string",
indexInDatasource: "",
patternInDatasource: "",
indexInRequest: []string{},
indexInRequest: "",
},
{
name: "single string",
indexInDatasource: "logs-*",
patternInDatasource: "",
indexInRequest: []string{"logs-*"},
indexInRequest: "logs-*",
},
{
name: "daily pattern",
indexInDatasource: "[logs-]YYYY.MM.DD",
patternInDatasource: "Daily",
indexInRequest: []string{"logs-2018.05.10", "logs-2018.05.11", "logs-2018.05.12"},
indexInRequest: "logs-2018.05.10,logs-2018.05.11,logs-2018.05.12",
},
}

Expand Down Expand Up @@ -210,7 +210,7 @@ func TestClient_Index(t *testing.T) {
jHeader, err := simplejson.NewJson(headerBytes)
require.NoError(t, err)

assert.Equal(t, test.indexInRequest, jHeader.Get("index").MustStringArray())
assert.Equal(t, test.indexInRequest, jHeader.Get("index").MustString())
})
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/tsdb/elasticsearch/snapshot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func TestRequestSnapshots(t *testing.T) {
queryHeader := []byte(`
{
"ignore_unavailable": true,
"index": ["testdb-2022.11.14"],
"index": "testdb-2022.11.14",
"search_type": "query_then_fetch"
}
`)
Expand Down

0 comments on commit 74d3036

Please sign in to comment.