Skip to content

Commit

Permalink
wip: Elasticsearch 2.0
Browse files Browse the repository at this point in the history
* Bump version to 3.0.0
* Change all `Source()` methods to also return an error.
* Remove facets
* Remove Delete Mapping API
* Add `meta` to all aggregations
* Field `status` is removed from HTTP GET response. It already exists
  in the HTTP header.
* Remove `_fields` from Get API. It is `fields`.
* Fix test mappings, e.g. remove `store` from `_ttl` and `_timestamp`.
* Make `MoreLikeThisQuery` compatible with 2.0.
* Remove `MoreLikeThisFieldQuery`.
  • Loading branch information
olivere committed Jul 2, 2015
1 parent fa9cb36 commit 55705c5
Show file tree
Hide file tree
Showing 223 changed files with 2,960 additions and 3,723 deletions.
6 changes: 5 additions & 1 deletion alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,11 @@ func (s *AliasService) Do() (*AliasResult, error) {
detailsJson["index"] = action.Index
detailsJson["alias"] = action.Alias
if action.Filter != nil {
detailsJson["filter"] = (*action.Filter).Source()
src, err := (*action.Filter).Source()
if err != nil {
return nil, err
}
detailsJson["filter"] = src
}
actionJson[action.Type] = detailsJson
actionsJson = append(actionsJson, actionJson)
Expand Down
7 changes: 1 addition & 6 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (

const (
// Version is the current version of Elastic.
Version = "2.0.0"
Version = "3.0.0"

// DefaultUrl is the default endpoint of Elasticsearch on the local machine.
// It is used e.g. when initializing a new Client without a specific URL.
Expand Down Expand Up @@ -1198,11 +1198,6 @@ func (c *Client) PutMapping() *PutMappingService {
return NewPutMappingService(c)
}

// DeleteMapping deletes a mapping.
func (c *Client) DeleteMapping() *DeleteMappingService {
return NewDeleteMappingService(c)
}

// ClusterHealth retrieves the health of the cluster.
func (c *Client) ClusterHealth() *ClusterHealthService {
return NewClusterHealthService(c)
Expand Down
12 changes: 6 additions & 6 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -482,8 +482,8 @@ func TestPerformRequest(t *testing.T) {
if err := json.Unmarshal(res.Body, ret); err != nil {
t.Fatalf("expected no error on decode; got: %v", err)
}
if ret.Status != 200 {
t.Errorf("expected HTTP status 200; got: %d", ret.Status)
if ret.ClusterName == "" {
t.Errorf("expected cluster name; got: %q", ret.ClusterName)
}
}

Expand All @@ -508,8 +508,8 @@ func TestPerformRequestWithLogger(t *testing.T) {
if err := json.Unmarshal(res.Body, ret); err != nil {
t.Fatalf("expected no error on decode; got: %v", err)
}
if ret.Status != 200 {
t.Errorf("expected HTTP status 200; got: %d", ret.Status)
if ret.ClusterName == "" {
t.Errorf("expected cluster name; got: %q", ret.ClusterName)
}

got := w.String()
Expand Down Expand Up @@ -547,8 +547,8 @@ func TestPerformRequestWithLoggerAndTracer(t *testing.T) {
if err := json.Unmarshal(res.Body, ret); err != nil {
t.Fatalf("expected no error on decode; got: %v", err)
}
if ret.Status != 200 {
t.Errorf("expected HTTP status 200; got: %d", ret.Status)
if ret.ClusterName == "" {
t.Errorf("expected cluster name; got: %q", ret.ClusterName)
}

lgot := lw.String()
Expand Down
6 changes: 5 additions & 1 deletion count.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,12 @@ func (s *CountService) Do() (int64, error) {
// Set body if there is a query specified
var body interface{}
if s.query != nil {
src, err := s.query.Source()
if err != nil {
return 0, err
}
query := make(map[string]interface{})
query["query"] = s.query.Source()
query["query"] = src
body = query
}

Expand Down
6 changes: 5 additions & 1 deletion delete_by_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,12 @@ func (s *DeleteByQueryService) Do() (*DeleteByQueryResult, error) {
// Set body if there is a query set
var body interface{}
if s.query != nil {
src, err := s.query.Source()
if err != nil {
return nil, err
}
query := make(map[string]interface{})
query["query"] = s.query.Source()
query["query"] = src
body = query
}

Expand Down
136 changes: 0 additions & 136 deletions delete_mapping.go

This file was deleted.

40 changes: 0 additions & 40 deletions delete_mapping_test.go

This file was deleted.

2 changes: 1 addition & 1 deletion errors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ func TestResponseError(t *testing.T) {
message := "Something went seriously wrong."
raw := "HTTP/1.1 500 Internal Server Error\r\n" +
"\r\n" +
`{"status":500,"error":"` + message + `"}` + "\r\n"
`{"error":"` + message + `"}` + "\r\n"
r := bufio.NewReader(strings.NewReader(raw))

resp, err := http.ReadResponse(r, nil)
Expand Down
7 changes: 6 additions & 1 deletion explain.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,13 @@ func (s *ExplainService) Pretty(pretty bool) *ExplainService {

// Query sets a query definition using the Query DSL.
func (s *ExplainService) Query(query Query) *ExplainService {
src, err := query.Source()
if err != nil {
// Do nothing in case of an error
return s
}
body := make(map[string]interface{})
body["query"] = query.Source()
body["query"] = src
s.bodyJson = body
return s
}
Expand Down
6 changes: 3 additions & 3 deletions fetch_source_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ func (fsc *FetchSourceContext) TransformSource(transformSource bool) *FetchSourc
return fsc
}

func (fsc *FetchSourceContext) Source() interface{} {
func (fsc *FetchSourceContext) Source() (interface{}, error) {
if !fsc.fetchSource {
return false
return false, nil
}
return map[string]interface{}{
"includes": fsc.includes,
"excludes": fsc.excludes,
}
}, nil
}

// Query returns the parameters in a form suitable for a URL query string.
Expand Down
24 changes: 20 additions & 4 deletions fetch_source_context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ import (

func TestFetchSourceContextNoFetchSource(t *testing.T) {
builder := NewFetchSourceContext(false)
data, err := json.Marshal(builder.Source())
src, err := builder.Source()
if err != nil {
t.Fatal(err)
}
data, err := json.Marshal(src)
if err != nil {
t.Fatalf("marshaling to JSON failed: %v", err)
}
Expand All @@ -24,7 +28,11 @@ func TestFetchSourceContextNoFetchSource(t *testing.T) {

func TestFetchSourceContextNoFetchSourceIgnoreIncludesAndExcludes(t *testing.T) {
builder := NewFetchSourceContext(false).Include("a", "b").Exclude("c")
data, err := json.Marshal(builder.Source())
src, err := builder.Source()
if err != nil {
t.Fatal(err)
}
data, err := json.Marshal(src)
if err != nil {
t.Fatalf("marshaling to JSON failed: %v", err)
}
Expand All @@ -37,7 +45,11 @@ func TestFetchSourceContextNoFetchSourceIgnoreIncludesAndExcludes(t *testing.T)

func TestFetchSourceContextFetchSource(t *testing.T) {
builder := NewFetchSourceContext(true)
data, err := json.Marshal(builder.Source())
src, err := builder.Source()
if err != nil {
t.Fatal(err)
}
data, err := json.Marshal(src)
if err != nil {
t.Fatalf("marshaling to JSON failed: %v", err)
}
Expand All @@ -50,7 +62,11 @@ func TestFetchSourceContextFetchSource(t *testing.T) {

func TestFetchSourceContextFetchSourceWithIncludesAndExcludes(t *testing.T) {
builder := NewFetchSourceContext(true).Include("a", "b").Exclude("c")
data, err := json.Marshal(builder.Source())
src, err := builder.Source()
if err != nil {
t.Fatal(err)
}
data, err := json.Marshal(src)
if err != nil {
t.Fatalf("marshaling to JSON failed: %v", err)
}
Expand Down
4 changes: 3 additions & 1 deletion filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

package elastic

// Filter defines the contract each filter has to fulfill.
type Filter interface {
Source() interface{}
// Source returns a JSON-serializable fragment of the request.
Source() (interface{}, error)
}
3 changes: 0 additions & 3 deletions get.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,6 @@ func (b *GetService) Do() (*GetResult, error) {
if b.ignoreErrorsOnGeneratedFields != nil {
params.Add("ignore_errors_on_generated_fields", fmt.Sprintf("%v", *b.ignoreErrorsOnGeneratedFields))
}
if len(b.fields) > 0 {
params.Add("_fields", strings.Join(b.fields, ","))
}
if b.version != nil {
params.Add("version", fmt.Sprintf("%d", *b.version))
}
Expand Down
Loading

0 comments on commit 55705c5

Please sign in to comment.