forked from olivere/elastic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_index.go
75 lines (61 loc) · 1.46 KB
/
create_index.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// Copyright 2012-2015 Oliver Eilhard. All rights reserved.
// Use of this source code is governed by a MIT-license.
// See http://olivere.mit-license.org/license.txt for details.
package elastic
import (
"encoding/json"
"fmt"
"net/url"
"github.com/olivere/elastic/uritemplates"
)
type CreateIndexService struct {
client *Client
index string
body string
pretty bool
}
func NewCreateIndexService(client *Client) *CreateIndexService {
builder := &CreateIndexService{
client: client,
}
return builder
}
func (b *CreateIndexService) Index(index string) *CreateIndexService {
b.index = index
return b
}
func (b *CreateIndexService) Body(body string) *CreateIndexService {
b.body = body
return b
}
func (b *CreateIndexService) Pretty(pretty bool) *CreateIndexService {
b.pretty = pretty
return b
}
func (b *CreateIndexService) Do() (*CreateIndexResult, error) {
// Build url
path, err := uritemplates.Expand("/{index}/", map[string]string{
"index": b.index,
})
if err != nil {
return nil, err
}
params := make(url.Values)
if b.pretty {
params.Set("pretty", fmt.Sprintf("%v", b.pretty))
}
// Get response
res, err := b.client.PerformRequest("PUT", path, params, b.body)
if err != nil {
return nil, err
}
ret := new(CreateIndexResult)
if err := json.Unmarshal(res.Body, ret); err != nil {
return nil, err
}
return ret, nil
}
// -- Result of a create index request.
type CreateIndexResult struct {
Acknowledged bool `json:"acknowledged"`
}