Skip to content

Commit b8e6745

Browse files
committed
Fix deprecations
The tests report some deprecations. This commit fixes two of them.
1 parent fb1fc54 commit b8e6745

3 files changed

+16
-2
lines changed

search_queries_common_terms.go

+2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ type CommonTermsQuery struct {
3030
}
3131

3232
// NewCommonTermsQuery creates and initializes a new common terms query.
33+
//
34+
// Deprecated: Common Terms Query was deprecated in >= 7.3.0. See https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-common-terms-query.html.
3335
func NewCommonTermsQuery(name string, text interface{}) *CommonTermsQuery {
3436
return &CommonTermsQuery{name: name, text: text}
3537
}

search_queries_common_terms_test.go

+13-1
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,24 @@ func TestCommonTermsQuery(t *testing.T) {
3131
func TestSearchQueriesCommonTermsQuery(t *testing.T) {
3232
client := setupTestClientAndCreateIndex(t)
3333

34+
// Deprecated in >= 7.3.0
35+
// https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-common-terms-query.html
36+
esversion, err := client.ElasticsearchVersion(DefaultURL)
37+
if err != nil {
38+
t.Fatal(err)
39+
}
40+
if esversion < "7.3.0" {
41+
t.Skipf("Elasticsearch versions >= 7.3.0 deprecated Common Terms Query. "+
42+
"See https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-common-terms-query.html. "+
43+
"You are running Elasticsearch %v.", esversion)
44+
}
45+
3446
tweet1 := tweet{User: "olivere", Message: "Welcome to Golang and Elasticsearch."}
3547
tweet2 := tweet{User: "olivere", Message: "Another unrelated topic."}
3648
tweet3 := tweet{User: "sandrae", Message: "Cycling is fun."}
3749

3850
// Add all documents
39-
_, err := client.Index().Index(testIndexName).Id("1").BodyJson(&tweet1).Do(context.TODO())
51+
_, err = client.Index().Index(testIndexName).Id("1").BodyJson(&tweet1).Do(context.TODO())
4052
if err != nil {
4153
t.Fatal(err)
4254
}

search_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ func TestSearchSpecificFields(t *testing.T) {
514514
Query(all).
515515
StoredFields("message").
516516
DocvalueFields("retweets").
517-
Sort("_id", true).
517+
Sort("created", true).
518518
Do(context.TODO())
519519
if err != nil {
520520
t.Fatal(err)

0 commit comments

Comments
 (0)