Skip to content

Commit 14202c5

Browse files
committed
Only add params when there are; complete parameters on Get request
1 parent a1598d8 commit 14202c5

File tree

9 files changed

+54
-24
lines changed

9 files changed

+54
-24
lines changed

alias.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,9 @@ func (s *AliasService) Do() (*AliasResult, error) {
8181
if s.pretty {
8282
params.Set("pretty", fmt.Sprintf("%v", s.pretty))
8383
}
84-
urls += "?" + params.Encode()
84+
if len(params) > 0 {
85+
urls += "?" + params.Encode()
86+
}
8587

8688
// Actions
8789
body := make(map[string]interface{})

aliases.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,9 @@ func (s *AliasesService) Do() (*AliasesResult, error) {
7676
if s.pretty {
7777
params.Set("pretty", fmt.Sprintf("%v", s.pretty))
7878
}
79-
urls += "?" + params.Encode()
79+
if len(params) > 0 {
80+
urls += "?" + params.Encode()
81+
}
8082

8183
if s.debug {
8284
out, _ := httputil.DumpRequestOut((*http.Request)(req), true)

bulk.go

+11-9
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,18 @@ type BulkService struct {
2323
requests []BulkableRequest
2424
//replicationType string
2525
//consistencyLevel string
26-
refresh *bool
27-
pretty bool
28-
debug bool
26+
refresh *bool
27+
pretty bool
28+
debug bool
2929
debugOnError bool
3030
}
3131

3232
func NewBulkService(client *Client) *BulkService {
3333
builder := &BulkService{
34-
client: client,
35-
requests: make([]BulkableRequest, 0),
36-
pretty: false,
37-
debug: false,
34+
client: client,
35+
requests: make([]BulkableRequest, 0),
36+
pretty: false,
37+
debug: false,
3838
debugOnError: false,
3939
}
4040
return builder
@@ -132,7 +132,9 @@ func (s *BulkService) Do() (*BulkResponse, error) {
132132
if s.refresh != nil {
133133
params.Set("refresh", fmt.Sprintf("%v", *s.refresh))
134134
}
135-
urls += "?" + params.Encode()
135+
if len(params) > 0 {
136+
urls += "?" + params.Encode()
137+
}
136138

137139
// Set up a new request
138140
req, err := s.client.NewRequest("POST", urls)
@@ -171,7 +173,7 @@ func (s *BulkService) Do() (*BulkResponse, error) {
171173
}
172174
defer res.Body.Close()
173175

174-
// Debug
176+
// Debug
175177
if s.debug {
176178
out, _ := httputil.DumpResponse(res, true)
177179
fmt.Printf("%s\n", string(out))

count.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,9 @@ func (s *CountService) Do() (int64, error) {
8484
if s.pretty {
8585
params.Set("pretty", fmt.Sprintf("%v", s.pretty))
8686
}
87-
urls += "?" + params.Encode()
87+
if len(params) > 0 {
88+
urls += "?" + params.Encode()
89+
}
8890

8991
// Set up a new request
9092
req, err := s.client.NewRequest("GET", urls)

flush.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,9 @@ func (s *FlushService) Do() (*FlushResult, error) {
7575
if s.full != nil {
7676
params.Set("full", fmt.Sprintf("%v", *s.full))
7777
}
78-
urls += "?" + params.Encode()
78+
if len(params) > 0 {
79+
urls += "?" + params.Encode()
80+
}
7981

8082
// Set up a new request
8183
req, err := s.client.NewRequest("POST", urls)

get.go

+22-8
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,14 @@ type GetService struct {
2020
routing string
2121
preference string
2222
fields []string
23-
refresh bool
24-
realtime bool
23+
refresh *bool
24+
realtime *bool
2525
}
2626

2727
func NewGetService(client *Client) *GetService {
2828
builder := &GetService{
29-
client: client,
30-
_type: "_all",
31-
realtime: true,
29+
client: client,
30+
_type: "_all",
3231
}
3332
return builder
3433
}
@@ -82,12 +81,12 @@ func (b *GetService) Fields(fields ...string) *GetService {
8281
}
8382

8483
func (b *GetService) Refresh(refresh bool) *GetService {
85-
b.refresh = refresh
84+
b.refresh = &refresh
8685
return b
8786
}
8887

8988
func (b *GetService) Realtime(realtime bool) *GetService {
90-
b.realtime = realtime
89+
b.realtime = &realtime
9190
return b
9291
}
9392

@@ -99,8 +98,23 @@ func (b *GetService) Do() (*GetResult, error) {
9998
urls = strings.Replace(urls, "{id}", cleanPathString(b.id), 1)
10099

101100
params := make(url.Values)
101+
if b.realtime != nil {
102+
params.Add("realtime", fmt.Sprintf("%v", *b.realtime))
103+
}
104+
if len(b.fields) > 0 {
105+
params.Add("fields", strings.Join(b.fields, ","))
106+
}
107+
if b.routing != "" {
108+
params.Add("routing", b.routing)
109+
}
110+
if b.preference != "" {
111+
params.Add("preference", b.preference)
112+
}
113+
if b.refresh != nil {
114+
params.Add("refresh", fmt.Sprintf("%v", *b.refresh))
115+
}
102116
if len(params) > 0 {
103-
urls += params.Encode()
117+
urls += "?" + params.Encode()
104118
}
105119

106120
// Set up a new request

index.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,9 @@ func (b *IndexService) Do() (*IndexResult, error) {
8989
if b.pretty {
9090
params.Set("pretty", fmt.Sprintf("%v", b.pretty))
9191
}
92-
urls += "?" + params.Encode()
92+
if len(params) > 0 {
93+
urls += "?" + params.Encode()
94+
}
9395

9496
// Set up a new request
9597
req, err := b.client.NewRequest("PUT", urls)

scan.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,9 @@ func (s *ScanService) Do() (*ScanCursor, error) {
153153
if s.size != nil && *s.size > 0 {
154154
params.Set("size", fmt.Sprintf("%d", *s.size))
155155
}
156-
urls += "?" + params.Encode()
156+
if len(params) > 0 {
157+
urls += "?" + params.Encode()
158+
}
157159

158160
// Set up a new request
159161
req, err := s.client.NewRequest("POST", urls)

search.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,9 @@ func (s *SearchService) Do() (*SearchResult, error) {
212212
if s.searchType != "" {
213213
params.Set("search_type", s.searchType)
214214
}
215-
urls += "?" + params.Encode()
215+
if len(params) > 0 {
216+
urls += "?" + params.Encode()
217+
}
216218

217219
// Set up a new request
218220
req, err := s.client.NewRequest("POST", urls)

0 commit comments

Comments
 (0)