Skip to content

Commit dda3b3a

Browse files
committed
wip: Elasticsearch 2.0
* Align file names and service names with REST API spec. * Refresh many services to be up-to-date with latest version of REST API spec. * Move test setup functions into separate file.
1 parent 46ac184 commit dda3b3a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+2035
-1194
lines changed

CHANGELOG-3.0.md

+23
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@ The error response of a bulk operation used to be a simple string in Elasticsear
104104
In Elasticsearch 2.0, it returns a structured JSON object with a lot more details about the error.
105105
These errors are now captured in an object of type [`ErrorDetails`](https://github.com/olivere/elastic/blob/master/errors.go#L57) which is used in [BulkResponseItem](https://github.com/olivere/elastic/blob/master/bulk.go#L207).
106106

107+
### Removed ErrMissingIndex, ErrMissingType, and ErrMissingId
108+
109+
The specific error types `ErrMissingIndex`, `ErrMissingType`, and `ErrMissingId` have been removed. They were only used by `DeleteService` and are replaced by a generic error message.
110+
107111
## Numeric types
108112

109113
Elastic 3.0 has settled to use `float64` everywhere. It used to be a mix of `float32` and `float64` in Elastic 2.0. E.g. all boostable queries in Elastic 3.0 now have a boost type of `float64` where it used to be `float32`.
@@ -273,3 +277,22 @@ update, err := client.Update().Index("twitter").Type("tweet").Id("1").
273277
Do()
274278
```
275279

280+
## Services
281+
282+
### REST API specification
283+
284+
As you might know, Elasticsearch comes with a REST API specification. The specification describes the endpoints in a JSON structure.
285+
286+
Most services in Elastic predated the REST API specification. Well, now they are in line with the specification. All services can be generated by go generate (not 100% automatic though). All services have been reviewed for being up-to-date with the 2.0 specification.
287+
288+
For you, this probably doesn't mean a lot. However, you can now be more confident that Elastic supports all features the REST API specification specifies.
289+
290+
At the same time, the file names of the services are renamed to match the REST API specification naming.
291+
292+
### REST API Test Suite
293+
294+
The REST API specification of Elasticsearch comes along with a test suite that official clients typically use to test for conformance. Up until now, Elastic didn't run this test suite. However, we are in the process of setting up infrastructure and tests to match this suite as well.
295+
296+
This process in not completed though.
297+
298+

client.go

+167-108
Original file line numberDiff line numberDiff line change
@@ -903,93 +903,26 @@ func (c *Client) PerformRequest(method, path string, params url.Values, body int
903903
return resp, nil
904904
}
905905

906-
// ElasticsearchVersion returns the version number of Elasticsearch
907-
// running on the given URL.
908-
func (c *Client) ElasticsearchVersion(url string) (string, error) {
909-
res, _, err := c.Ping(url).Do()
910-
if err != nil {
911-
return "", err
912-
}
913-
return res.Version.Number, nil
914-
}
915-
916-
// IndexNames returns the names of all indices in the cluster.
917-
func (c *Client) IndexNames() ([]string, error) {
918-
res, err := c.IndexGetSettings().Index("_all").Do()
919-
if err != nil {
920-
return nil, err
921-
}
922-
var names []string
923-
for name, _ := range res {
924-
names = append(names, name)
925-
}
926-
return names, nil
927-
}
928-
929-
// Ping checks if a given node in a cluster exists and (optionally)
930-
// returns some basic information about the Elasticsearch server,
931-
// e.g. the Elasticsearch version number.
932-
//
933-
// Notice that you need to specify a URL here explicitly.
934-
func (c *Client) Ping(url string) *PingService {
935-
return NewPingService(c).URL(url)
936-
}
937-
938-
// CreateIndex returns a service to create a new index.
939-
func (c *Client) CreateIndex(name string) *CreateIndexService {
940-
return NewCreateIndexService(c).Index(name)
941-
}
942-
943-
// DeleteIndex returns a service to delete an index.
944-
func (c *Client) DeleteIndex(name string) *DeleteIndexService {
945-
return NewDeleteIndexService(c).Index(name)
946-
}
947-
948-
// IndexExists allows to check if an index exists.
949-
func (c *Client) IndexExists(name string) *IndexExistsService {
950-
return NewIndexExistsService(c).Index(name)
951-
}
952-
953-
// TypeExists allows to check if one or more types exist in one or more indices.
954-
func (c *Client) TypeExists() *IndicesExistsTypeService {
955-
return NewIndicesExistsTypeService(c)
956-
}
957-
958-
// IndexStats provides statistics on different operations happining
959-
// in one or more indices.
960-
func (c *Client) IndexStats(indices ...string) *IndicesStatsService {
961-
return NewIndicesStatsService(c).Index(indices...)
962-
}
963-
964-
// OpenIndex opens an index.
965-
func (c *Client) OpenIndex(name string) *OpenIndexService {
966-
return NewOpenIndexService(c).Index(name)
967-
}
968-
969-
// CloseIndex closes an index.
970-
func (c *Client) CloseIndex(name string) *CloseIndexService {
971-
return NewCloseIndexService(c).Index(name)
972-
}
906+
// -- Document APIs --
973907

974908
// Index a document.
975909
func (c *Client) Index() *IndexService {
976910
return NewIndexService(c)
977911
}
978912

979-
// IndexGet retrieves information about one or more indices.
980-
// IndexGet is only available for Elasticsearch 1.4 or later.
981-
func (c *Client) IndexGet(indices ...string) *IndicesGetService {
982-
return NewIndicesGetService(c).Index(indices...)
913+
// Get a document.
914+
func (c *Client) Get() *GetService {
915+
return NewGetService(c)
983916
}
984917

985-
// IndexGetSettings retrieves settings about one or more indices.
986-
func (c *Client) IndexGetSettings(indices ...string) *IndicesGetSettingsService {
987-
return NewIndicesGetSettingsService(c).Index(indices...)
918+
// MultiGet retrieves multiple documents in one roundtrip.
919+
func (c *Client) MultiGet() *MgetService {
920+
return NewMgetService(c)
988921
}
989922

990-
// Update a document.
991-
func (c *Client) Update() *UpdateService {
992-
return NewUpdateService(c)
923+
// Mget retrieves multiple documents in one roundtrip.
924+
func (c *Client) Mget() *MgetService {
925+
return NewMgetService(c)
993926
}
994927

995928
// Delete a document.
@@ -1002,29 +935,44 @@ func (c *Client) DeleteByQuery(indices ...string) *DeleteByQueryService {
1002935
return NewDeleteByQueryService(c).Index(indices...)
1003936
}
1004937

1005-
// Get a document.
1006-
func (c *Client) Get() *GetService {
1007-
return NewGetService(c)
938+
// Update a document.
939+
func (c *Client) Update() *UpdateService {
940+
return NewUpdateService(c)
1008941
}
1009942

1010-
// MultiGet retrieves multiple documents in one roundtrip.
1011-
func (c *Client) MultiGet() *MultiGetService {
1012-
return NewMultiGetService(c)
943+
// Bulk is the entry point to mass insert/update/delete documents.
944+
func (c *Client) Bulk() *BulkService {
945+
return NewBulkService(c)
1013946
}
1014947

1015-
// Exists checks if a document exists.
1016-
func (c *Client) Exists() *ExistsService {
1017-
return NewExistsService(c)
948+
// TODO Term Vectors
949+
// TODO Multi termvectors API
950+
951+
// -- Search APIs --
952+
953+
// Search is the entry point for searches.
954+
func (c *Client) Search(indices ...string) *SearchService {
955+
return NewSearchService(c).Index(indices...)
956+
}
957+
958+
// Suggest returns a service to return suggestions.
959+
func (c *Client) Suggest(indices ...string) *SuggestService {
960+
return NewSuggestService(c).Index(indices...)
961+
}
962+
963+
// MultiSearch is the entry point for multi searches.
964+
func (c *Client) MultiSearch() *MultiSearchService {
965+
return NewMultiSearchService(c)
1018966
}
1019967

1020968
// Count documents.
1021969
func (c *Client) Count(indices ...string) *CountService {
1022970
return NewCountService(c).Index(indices...)
1023971
}
1024972

1025-
// Search is the entry point for searches.
1026-
func (c *Client) Search(indices ...string) *SearchService {
1027-
return NewSearchService(c).Index(indices...)
973+
// Explain computes a score explanation for a query and a specific document.
974+
func (c *Client) Explain(index, typ, id string) *ExplainService {
975+
return NewExplainService(c).Index(index).Type(typ).Id(id)
1028976
}
1029977

1030978
// Percolate allows to send a document and return matching queries.
@@ -1033,14 +981,15 @@ func (c *Client) Percolate() *PercolateService {
1033981
return NewPercolateService(c)
1034982
}
1035983

1036-
// MultiSearch is the entry point for multi searches.
1037-
func (c *Client) MultiSearch() *MultiSearchService {
1038-
return NewMultiSearchService(c)
1039-
}
984+
// TODO Search Template
985+
// TODO Search Shards API
986+
// TODO Search Exists API
987+
// TODO Validate API
988+
// TODO Field Stats API
1040989

1041-
// Suggest returns a service to return suggestions.
1042-
func (c *Client) Suggest(indices ...string) *SuggestService {
1043-
return NewSuggestService(c).Index(indices...)
990+
// Exists checks if a document exists.
991+
func (c *Client) Exists() *ExistsService {
992+
return NewExistsService(c)
1044993
}
1045994

1046995
// Scan through documents. Use this to iterate inside a server process
@@ -1061,6 +1010,55 @@ func (c *Client) ClearScroll(scrollIds ...string) *ClearScrollService {
10611010
return NewClearScrollService(c).ScrollId(scrollIds...)
10621011
}
10631012

1013+
// -- Indices APIs --
1014+
1015+
// CreateIndex returns a service to create a new index.
1016+
func (c *Client) CreateIndex(name string) *IndicesCreateService {
1017+
return NewIndicesCreateService(c).Index(name)
1018+
}
1019+
1020+
// DeleteIndex returns a service to delete an index.
1021+
func (c *Client) DeleteIndex(indices ...string) *IndicesDeleteService {
1022+
return NewIndicesDeleteService(c).Index(indices)
1023+
}
1024+
1025+
// IndexExists allows to check if an index exists.
1026+
func (c *Client) IndexExists(indices ...string) *IndicesExistsService {
1027+
return NewIndicesExistsService(c).Index(indices)
1028+
}
1029+
1030+
// TypeExists allows to check if one or more types exist in one or more indices.
1031+
func (c *Client) TypeExists() *IndicesExistsTypeService {
1032+
return NewIndicesExistsTypeService(c)
1033+
}
1034+
1035+
// IndexStats provides statistics on different operations happining
1036+
// in one or more indices.
1037+
func (c *Client) IndexStats(indices ...string) *IndicesStatsService {
1038+
return NewIndicesStatsService(c).Index(indices...)
1039+
}
1040+
1041+
// OpenIndex opens an index.
1042+
func (c *Client) OpenIndex(name string) *IndicesOpenService {
1043+
return NewIndicesOpenService(c).Index(name)
1044+
}
1045+
1046+
// CloseIndex closes an index.
1047+
func (c *Client) CloseIndex(name string) *IndicesCloseService {
1048+
return NewIndicesCloseService(c).Index(name)
1049+
}
1050+
1051+
// IndexGet retrieves information about one or more indices.
1052+
// IndexGet is only available for Elasticsearch 1.4 or later.
1053+
func (c *Client) IndexGet(indices ...string) *IndicesGetService {
1054+
return NewIndicesGetService(c).Index(indices...)
1055+
}
1056+
1057+
// IndexGetSettings retrieves settings about one or more indices.
1058+
func (c *Client) IndexGetSettings(indices ...string) *IndicesGetSettingsService {
1059+
return NewIndicesGetSettingsService(c).Index(indices...)
1060+
}
1061+
10641062
// Optimize asks Elasticsearch to optimize one or more indices.
10651063
func (c *Client) Optimize(indices ...string) *OptimizeService {
10661064
return NewOptimizeService(c).Index(indices...)
@@ -1073,18 +1071,8 @@ func (c *Client) Refresh(indices ...string) *RefreshService {
10731071

10741072
// Flush asks Elasticsearch to free memory from the index and
10751073
// flush data to disk.
1076-
func (c *Client) Flush(indices ...string) *FlushService {
1077-
return NewFlushService(c).Index(indices...)
1078-
}
1079-
1080-
// Explain computes a score explanation for a query and a specific document.
1081-
func (c *Client) Explain(index, typ, id string) *ExplainService {
1082-
return NewExplainService(c).Index(index).Type(typ).Id(id)
1083-
}
1084-
1085-
// Bulk is the entry point to mass insert/update/delete documents.
1086-
func (c *Client) Bulk() *BulkService {
1087-
return NewBulkService(c)
1074+
func (c *Client) Flush(indices ...string) *IndicesFlushService {
1075+
return NewIndicesFlushService(c).Index(indices...)
10881076
}
10891077

10901078
// Alias enables the caller to add and/or remove aliases.
@@ -1149,6 +1137,25 @@ func (c *Client) PutMapping() *PutMappingService {
11491137
return NewPutMappingService(c)
11501138
}
11511139

1140+
// -- cat APIs --
1141+
1142+
// TODO cat aliases
1143+
// TODO cat allocation
1144+
// TODO cat count
1145+
// TODO cat fielddata
1146+
// TODO cat health
1147+
// TODO cat indices
1148+
// TODO cat master
1149+
// TODO cat nodes
1150+
// TODO cat pending tasks
1151+
// TODO cat plugins
1152+
// TODO cat recovery
1153+
// TODO cat thread pool
1154+
// TODO cat shards
1155+
// TODO cat segments
1156+
1157+
// -- Cluster APIs --
1158+
11521159
// ClusterHealth retrieves the health of the cluster.
11531160
func (c *Client) ClusterHealth() *ClusterHealthService {
11541161
return NewClusterHealthService(c)
@@ -1169,6 +1176,58 @@ func (c *Client) NodesInfo() *NodesInfoService {
11691176
return NewNodesInfoService(c)
11701177
}
11711178

1179+
// TODO Pending cluster tasks
1180+
// TODO Cluster Reroute
1181+
// TODO Cluster Update Settings
1182+
// TODO Nodes Stats
1183+
// TODO Nodes hot_threads
1184+
1185+
// -- Snapshot and Restore --
1186+
1187+
// TODO Snapshot Create
1188+
// TODO Snapshot Create Repository
1189+
// TODO Snapshot Delete
1190+
// TODO Snapshot Delete Repository
1191+
// TODO Snapshot Get
1192+
// TODO Snapshot Get Repository
1193+
// TODO Snapshot Restore
1194+
// TODO Snapshot Status
1195+
// TODO Snapshot Verify Repository
1196+
1197+
// -- Helpers and shortcuts --
1198+
1199+
// ElasticsearchVersion returns the version number of Elasticsearch
1200+
// running on the given URL.
1201+
func (c *Client) ElasticsearchVersion(url string) (string, error) {
1202+
res, _, err := c.Ping(url).Do()
1203+
if err != nil {
1204+
return "", err
1205+
}
1206+
return res.Version.Number, nil
1207+
}
1208+
1209+
// IndexNames returns the names of all indices in the cluster.
1210+
func (c *Client) IndexNames() ([]string, error) {
1211+
res, err := c.IndexGetSettings().Index("_all").Do()
1212+
if err != nil {
1213+
return nil, err
1214+
}
1215+
var names []string
1216+
for name, _ := range res {
1217+
names = append(names, name)
1218+
}
1219+
return names, nil
1220+
}
1221+
1222+
// Ping checks if a given node in a cluster exists and (optionally)
1223+
// returns some basic information about the Elasticsearch server,
1224+
// e.g. the Elasticsearch version number.
1225+
//
1226+
// Notice that you need to specify a URL here explicitly.
1227+
func (c *Client) Ping(url string) *PingService {
1228+
return NewPingService(c).URL(url)
1229+
}
1230+
11721231
// Reindex returns a service that will reindex documents from a source
11731232
// index into a target index. See
11741233
// http://www.elastic.co/guide/en/elasticsearch/guide/current/reindex.html

0 commit comments

Comments
 (0)