Skip to content

Commit 5a6718e

Browse files
authored
fix: add missing ignore_unavailable param to multi-search API (#757)
* add AllowNoIndices and IgnoreUnavailable params Signed-off-by: iamrajiv <rajivperfect007@gmail.com> * same fix Signed-off-by: iamrajiv <rajivperfect007@gmail.com> * add tests Signed-off-by: iamrajiv <rajivperfect007@gmail.com> * add changelog Signed-off-by: iamrajiv <rajivperfect007@gmail.com> --------- Signed-off-by: iamrajiv <rajivperfect007@gmail.com>
1 parent c801c69 commit 5a6718e

5 files changed

Lines changed: 249 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
2929

3030
### Fixed
3131
- Missing "caused by" information in StructError ([#752](https://github.com/opensearch-project/opensearch-go/pull/752))
32+
- Add missing `ignore_unavailable`, `allow_no_indices`, and `expand_wildcards` params to MSearch ([#757](https://github.com/opensearch-project/opensearch-go/pull/757))
3233

3334
### Security
3435

opensearchapi/api_msearch-params.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@ import (
3333

3434
// MSearchParams represents possible parameters for the MSearchReq
3535
type MSearchParams struct {
36+
AllowNoIndices *bool
3637
CcsMinimizeRoundtrips *bool
38+
ExpandWildcards string
39+
IgnoreUnavailable *bool
3740
MaxConcurrentSearches *int
3841
MaxConcurrentShardRequests *int
3942
PreFilterShardSize *int
@@ -50,10 +53,22 @@ type MSearchParams struct {
5053
func (r MSearchParams) get() map[string]string {
5154
params := make(map[string]string)
5255

56+
if r.AllowNoIndices != nil {
57+
params["allow_no_indices"] = strconv.FormatBool(*r.AllowNoIndices)
58+
}
59+
5360
if r.CcsMinimizeRoundtrips != nil {
5461
params["ccs_minimize_roundtrips"] = strconv.FormatBool(*r.CcsMinimizeRoundtrips)
5562
}
5663

64+
if r.ExpandWildcards != "" {
65+
params["expand_wildcards"] = r.ExpandWildcards
66+
}
67+
68+
if r.IgnoreUnavailable != nil {
69+
params["ignore_unavailable"] = strconv.FormatBool(*r.IgnoreUnavailable)
70+
}
71+
5772
if r.MaxConcurrentSearches != nil {
5873
params["max_concurrent_searches"] = strconv.FormatInt(int64(*r.MaxConcurrentSearches), 10)
5974
}
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
//
3+
// The OpenSearch Contributors require contributions made to
4+
// this file be licensed under the Apache-2.0 license or a
5+
// compatible open source license.
6+
7+
//go:build !integration
8+
9+
//nolint:testpackage // to test unexported get() method
10+
package opensearchapi
11+
12+
import (
13+
"testing"
14+
15+
"github.com/stretchr/testify/assert"
16+
)
17+
18+
func TestMSearchParams_get(t *testing.T) {
19+
type fields struct {
20+
AllowNoIndices *bool
21+
CcsMinimizeRoundtrips *bool
22+
ExpandWildcards string
23+
IgnoreUnavailable *bool
24+
MaxConcurrentSearches *int
25+
MaxConcurrentShardRequests *int
26+
PreFilterShardSize *int
27+
RestTotalHitsAsInt *bool
28+
SearchType string
29+
TypedKeys *bool
30+
Pretty bool
31+
Human bool
32+
ErrorTrace bool
33+
FilterPath []string
34+
}
35+
tests := []struct {
36+
name string
37+
fields fields
38+
want map[string]string
39+
}{
40+
{
41+
name: "empty params",
42+
fields: fields{},
43+
want: map[string]string{},
44+
},
45+
{
46+
name: "all params",
47+
fields: fields{
48+
AllowNoIndices: ToPointer(true),
49+
CcsMinimizeRoundtrips: ToPointer(true),
50+
ExpandWildcards: "open,hidden",
51+
IgnoreUnavailable: ToPointer(true),
52+
MaxConcurrentSearches: ToPointer(10),
53+
MaxConcurrentShardRequests: ToPointer(100),
54+
PreFilterShardSize: ToPointer(128),
55+
RestTotalHitsAsInt: ToPointer(true),
56+
SearchType: "query_then_fetch",
57+
TypedKeys: ToPointer(true),
58+
Pretty: true,
59+
Human: true,
60+
ErrorTrace: true,
61+
FilterPath: []string{"took", "responses"},
62+
},
63+
want: map[string]string{
64+
"allow_no_indices": "true",
65+
"ccs_minimize_roundtrips": "true",
66+
"expand_wildcards": "open,hidden",
67+
"ignore_unavailable": "true",
68+
"max_concurrent_searches": "10",
69+
"max_concurrent_shard_requests": "100",
70+
"pre_filter_shard_size": "128",
71+
"rest_total_hits_as_int": "true",
72+
"search_type": "query_then_fetch",
73+
"typed_keys": "true",
74+
"pretty": "true",
75+
"human": "true",
76+
"error_trace": "true",
77+
"filter_path": "took,responses",
78+
},
79+
},
80+
{
81+
name: "ignore_unavailable false",
82+
fields: fields{
83+
IgnoreUnavailable: ToPointer(false),
84+
AllowNoIndices: ToPointer(false),
85+
},
86+
want: map[string]string{
87+
"ignore_unavailable": "false",
88+
"allow_no_indices": "false",
89+
},
90+
},
91+
}
92+
for _, tt := range tests {
93+
t.Run(tt.name, func(t *testing.T) {
94+
r := MSearchParams{
95+
AllowNoIndices: tt.fields.AllowNoIndices,
96+
CcsMinimizeRoundtrips: tt.fields.CcsMinimizeRoundtrips,
97+
ExpandWildcards: tt.fields.ExpandWildcards,
98+
IgnoreUnavailable: tt.fields.IgnoreUnavailable,
99+
MaxConcurrentSearches: tt.fields.MaxConcurrentSearches,
100+
MaxConcurrentShardRequests: tt.fields.MaxConcurrentShardRequests,
101+
PreFilterShardSize: tt.fields.PreFilterShardSize,
102+
RestTotalHitsAsInt: tt.fields.RestTotalHitsAsInt,
103+
SearchType: tt.fields.SearchType,
104+
TypedKeys: tt.fields.TypedKeys,
105+
Pretty: tt.fields.Pretty,
106+
Human: tt.fields.Human,
107+
ErrorTrace: tt.fields.ErrorTrace,
108+
FilterPath: tt.fields.FilterPath,
109+
}
110+
assert.Equalf(t, tt.want, r.get(), "get()")
111+
})
112+
}
113+
}

opensearchapi/api_msearch-template-params.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@ import (
3333

3434
// MSearchTemplateParams represents possible parameters for the MSearchTemplateReq
3535
type MSearchTemplateParams struct {
36+
AllowNoIndices *bool
3637
CcsMinimizeRoundtrips *bool
38+
ExpandWildcards string
39+
IgnoreUnavailable *bool
3740
MaxConcurrentSearches *int
3841
RestTotalHitsAsInt *bool
3942
SearchType string
@@ -48,10 +51,22 @@ type MSearchTemplateParams struct {
4851
func (r MSearchTemplateParams) get() map[string]string {
4952
params := make(map[string]string)
5053

54+
if r.AllowNoIndices != nil {
55+
params["allow_no_indices"] = strconv.FormatBool(*r.AllowNoIndices)
56+
}
57+
5158
if r.CcsMinimizeRoundtrips != nil {
5259
params["ccs_minimize_roundtrips"] = strconv.FormatBool(*r.CcsMinimizeRoundtrips)
5360
}
5461

62+
if r.ExpandWildcards != "" {
63+
params["expand_wildcards"] = r.ExpandWildcards
64+
}
65+
66+
if r.IgnoreUnavailable != nil {
67+
params["ignore_unavailable"] = strconv.FormatBool(*r.IgnoreUnavailable)
68+
}
69+
5570
if r.MaxConcurrentSearches != nil {
5671
params["max_concurrent_searches"] = strconv.FormatInt(int64(*r.MaxConcurrentSearches), 10)
5772
}
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
//
3+
// The OpenSearch Contributors require contributions made to
4+
// this file be licensed under the Apache-2.0 license or a
5+
// compatible open source license.
6+
7+
//go:build !integration
8+
9+
//nolint:testpackage // to test unexported get() method
10+
package opensearchapi
11+
12+
import (
13+
"testing"
14+
15+
"github.com/stretchr/testify/assert"
16+
)
17+
18+
func TestMSearchTemplateParams_get(t *testing.T) {
19+
type fields struct {
20+
AllowNoIndices *bool
21+
CcsMinimizeRoundtrips *bool
22+
ExpandWildcards string
23+
IgnoreUnavailable *bool
24+
MaxConcurrentSearches *int
25+
RestTotalHitsAsInt *bool
26+
SearchType string
27+
TypedKeys *bool
28+
Pretty bool
29+
Human bool
30+
ErrorTrace bool
31+
FilterPath []string
32+
}
33+
tests := []struct {
34+
name string
35+
fields fields
36+
want map[string]string
37+
}{
38+
{
39+
name: "empty params",
40+
fields: fields{},
41+
want: map[string]string{},
42+
},
43+
{
44+
name: "all params",
45+
fields: fields{
46+
AllowNoIndices: ToPointer(true),
47+
CcsMinimizeRoundtrips: ToPointer(true),
48+
ExpandWildcards: "open,hidden",
49+
IgnoreUnavailable: ToPointer(true),
50+
MaxConcurrentSearches: ToPointer(10),
51+
RestTotalHitsAsInt: ToPointer(true),
52+
SearchType: "query_then_fetch",
53+
TypedKeys: ToPointer(true),
54+
Pretty: true,
55+
Human: true,
56+
ErrorTrace: true,
57+
FilterPath: []string{"took", "responses"},
58+
},
59+
want: map[string]string{
60+
"allow_no_indices": "true",
61+
"ccs_minimize_roundtrips": "true",
62+
"expand_wildcards": "open,hidden",
63+
"ignore_unavailable": "true",
64+
"max_concurrent_searches": "10",
65+
"rest_total_hits_as_int": "true",
66+
"search_type": "query_then_fetch",
67+
"typed_keys": "true",
68+
"pretty": "true",
69+
"human": "true",
70+
"error_trace": "true",
71+
"filter_path": "took,responses",
72+
},
73+
},
74+
{
75+
name: "ignore_unavailable false",
76+
fields: fields{
77+
IgnoreUnavailable: ToPointer(false),
78+
AllowNoIndices: ToPointer(false),
79+
},
80+
want: map[string]string{
81+
"ignore_unavailable": "false",
82+
"allow_no_indices": "false",
83+
},
84+
},
85+
}
86+
for _, tt := range tests {
87+
t.Run(tt.name, func(t *testing.T) {
88+
r := MSearchTemplateParams{
89+
AllowNoIndices: tt.fields.AllowNoIndices,
90+
CcsMinimizeRoundtrips: tt.fields.CcsMinimizeRoundtrips,
91+
ExpandWildcards: tt.fields.ExpandWildcards,
92+
IgnoreUnavailable: tt.fields.IgnoreUnavailable,
93+
MaxConcurrentSearches: tt.fields.MaxConcurrentSearches,
94+
RestTotalHitsAsInt: tt.fields.RestTotalHitsAsInt,
95+
SearchType: tt.fields.SearchType,
96+
TypedKeys: tt.fields.TypedKeys,
97+
Pretty: tt.fields.Pretty,
98+
Human: tt.fields.Human,
99+
ErrorTrace: tt.fields.ErrorTrace,
100+
FilterPath: tt.fields.FilterPath,
101+
}
102+
assert.Equalf(t, tt.want, r.get(), "get()")
103+
})
104+
}
105+
}

0 commit comments

Comments
 (0)