forked from olivere/elastic
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathclient.go
More file actions
171 lines (144 loc) · 4.33 KB
/
client.go
File metadata and controls
171 lines (144 loc) · 4.33 KB
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
// Copyright 2012 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 (
"errors"
"net/http"
"time"
)
const (
// Version represents the current version.
Version = "1.3.1"
// pingDuration is the time to periodically check the Elasticsearch URLs.
pingDuration = 60 * time.Second
)
// Client is an ElasticSearch client. Create one by calling NewClient.
type Client struct {
c *http.Client // c is the net/http Client to use for requests
host string // currently active connection url
}
// NewClient creates a new client to work with ElasticSearch.
func NewClient(client *http.Client, url string) (*Client, error) {
if client == nil {
return nil, errors.New("client is nil")
}
c := &Client{c: client}
c.host = url
return c, nil
}
// NewRequest creates a new request with the given method and prepends
// the base URL to the path. If no active connection to Elasticsearch
// is available, ErrNoClient is returned.
func (c *Client) NewRequest(method, path string) (*Request, error) {
return NewRequest(method, c.host+path)
}
// CreateIndex starts the service to create a new index.
func (c *Client) CreateIndex(name string) *CreateIndexService {
builder := NewCreateIndexService(c)
builder.Index(name)
return builder
}
// DeleteIndex starts the service to delete an index.
func (c *Client) DeleteIndex(name string) *DeleteIndexService {
builder := NewDeleteIndexService(c)
builder.Index(name)
return builder
}
// IndexExists allows to check if an index exists.
func (c *Client) IndexExists(name string) *IndexExistsService {
builder := NewIndexExistsService(c)
builder.Index(name)
return builder
}
// Index a document.
func (c *Client) Index() *IndexService {
builder := NewIndexService(c)
return builder
}
// Delete a document.
func (c *Client) Delete() *DeleteService {
builder := NewDeleteService(c)
return builder
}
// DeleteByQuery deletes documents as found by a query.
func (c *Client) DeleteByQuery() *DeleteByQueryService {
builder := NewDeleteByQueryService(c)
return builder
}
// Get a document.
func (c *Client) Get() *GetService {
builder := NewGetService(c)
return builder
}
// MultiGet retrieves multiple documents in one roundtrip.
func (c *Client) MultiGet() *MultiGetService {
builder := NewMultiGetService(c)
return builder
}
// Exists checks if a document exists.
func (c *Client) Exists() *ExistsService {
builder := NewExistsService(c)
return builder
}
// Count documents.
func (c *Client) Count(indices ...string) *CountService {
builder := NewCountService(c)
builder.Indices(indices...)
return builder
}
// Search is the entry point for searches.
func (c *Client) Search(indices ...string) *SearchService {
builder := NewSearchService(c)
builder.Indices(indices...)
return builder
}
// MultiSearch is the entry point for multi searches.
func (c *Client) MultiSearch() *MultiSearchService {
return NewMultiSearchService(c)
}
// Suggest returns an interface to return suggestions.
func (c *Client) Suggest(indices ...string) *SuggestService {
builder := NewSuggestService(c)
builder.Indices(indices...)
return builder
}
// Scan through documents.
func (c *Client) Scan(indices ...string) *ScanService {
builder := NewScanService(c)
builder.Indices(indices...)
return builder
}
// Optimize asks Elasticsearch to optimize one or more indices.
func (c *Client) Optimize(indices ...string) *OptimizeService {
builder := NewOptimizeService(c)
builder.Indices(indices...)
return builder
}
// Refresh asks Elasticsearch to refresh one or more indices.
func (c *Client) Refresh(indices ...string) *RefreshService {
builder := NewRefreshService(c)
builder.Indices(indices...)
return builder
}
// Flush asks Elasticsearch to free memory from the index and
// flush data to disk.
func (c *Client) Flush() *FlushService {
builder := NewFlushService(c)
return builder
}
// Bulk is the entry point to mass insert/update/delete documents.
func (c *Client) Bulk() *BulkService {
builder := NewBulkService(c)
return builder
}
// Alias enables the caller to add and/or remove aliases.
func (c *Client) Alias() *AliasService {
builder := NewAliasService(c)
return builder
}
// Aliases returns aliases by index name(s).
func (c *Client) Aliases() *AliasesService {
builder := NewAliasesService(c)
return builder
}