Skip to content

Commit

Permalink
[esutil.Client] Expose generic multiget (#91)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexashley authored Jun 18, 2021
1 parent 45d0d14 commit 19949cc
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
11 changes: 9 additions & 2 deletions go/v1beta1/storage/esutil/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -464,10 +464,17 @@ func (c *client) MultiGet(ctx context.Context, request *MultiGetRequest) (*EsMul
})
log = log.With(zap.String("request", requestJson))

mgetOpts := []func(mgetRequest *esapi.MgetRequest){
c.esClient.Mget.WithContext(ctx),
}

if request.Index != "" {
mgetOpts = append(mgetOpts, c.esClient.Mget.WithIndex(request.Index))
}

res, err := c.esClient.Mget(
encodedBody,
c.esClient.Mget.WithContext(ctx),
c.esClient.Mget.WithIndex(request.Index),
mgetOpts...,
)
if err != nil {
return nil, err
Expand Down
11 changes: 11 additions & 0 deletions go/v1beta1/storage/esutil/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1000,6 +1000,17 @@ var _ = Describe("elasticsearch client", func() {
})
})

When("no index is specified", func() {
BeforeEach(func() {
expectedMultiGetRequest.Index = ""
})

It("should use the generic mget path", func() {
Expect(transport.ReceivedHttpRequests[0].Method).To(Equal(http.MethodGet))
Expect(transport.ReceivedHttpRequests[0].URL.Path).To(Equal("/_mget"))
})
})

When("the multiget operation fails", func() {
BeforeEach(func() {
transport.PreparedHttpResponses = []*http.Response{
Expand Down
1 change: 1 addition & 0 deletions go/v1beta1/storage/esutil/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ type ESPitResponse struct {

type EsMultiGetItem struct {
Id string `json:"_id"`
Index string `json:"_index,omitempty"`
Routing string `json:"routing,omitempty"`
}

Expand Down

0 comments on commit 19949cc

Please sign in to comment.