Add `access` format support for Elasticsearch notification target (#4006)
This change adds `access` format support for notifications to a
Elasticsearch server, and it refactors `namespace` format support.
In the case of `access` format, for each event in Minio, a JSON
document is inserted into Elasticsearch with its timestamp set to the
event's timestamp, and with the ID generated automatically by
elasticsearch. No events are modified or deleted in this mode.
In the case of `namespace` format, for each event in Minio, a JSON
document is keyed together by the bucket and object name is updated in
Elasticsearch. In the case of an object being created or over-written
in Minio, a new document or an existing document is inserted into the
Elasticsearch index. If an object is deleted in Minio, the
corresponding document is deleted from the Elasticsearch index.
Additionally, this change upgrades Elasticsearch support to the 5.x
series. This is a breaking change, and users of previous elasticsearch
versions should upgrade.
Also updates documentation on Elasticsearch notification target usage
and has a link to an elasticsearch upgrade guide.
This is the last patch that finally resolves #3928.
2017-03-31 17:11:27 -04:00
|
|
|
// Copyright 2012-present Oliver Eilhard. All rights reserved.
|
2016-07-24 01:51:12 -04:00
|
|
|
// 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/url"
|
|
|
|
|
Add `access` format support for Elasticsearch notification target (#4006)
This change adds `access` format support for notifications to a
Elasticsearch server, and it refactors `namespace` format support.
In the case of `access` format, for each event in Minio, a JSON
document is inserted into Elasticsearch with its timestamp set to the
event's timestamp, and with the ID generated automatically by
elasticsearch. No events are modified or deleted in this mode.
In the case of `namespace` format, for each event in Minio, a JSON
document is keyed together by the bucket and object name is updated in
Elasticsearch. In the case of an object being created or over-written
in Minio, a new document or an existing document is inserted into the
Elasticsearch index. If an object is deleted in Minio, the
corresponding document is deleted from the Elasticsearch index.
Additionally, this change upgrades Elasticsearch support to the 5.x
series. This is a breaking change, and users of previous elasticsearch
versions should upgrade.
Also updates documentation on Elasticsearch notification target usage
and has a link to an elasticsearch upgrade guide.
This is the last patch that finally resolves #3928.
2017-03-31 17:11:27 -04:00
|
|
|
"golang.org/x/net/context"
|
|
|
|
|
|
|
|
"gopkg.in/olivere/elastic.v5/uritemplates"
|
2016-07-24 01:51:12 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
// IndicesCreateService creates a new index.
|
|
|
|
//
|
Add `access` format support for Elasticsearch notification target (#4006)
This change adds `access` format support for notifications to a
Elasticsearch server, and it refactors `namespace` format support.
In the case of `access` format, for each event in Minio, a JSON
document is inserted into Elasticsearch with its timestamp set to the
event's timestamp, and with the ID generated automatically by
elasticsearch. No events are modified or deleted in this mode.
In the case of `namespace` format, for each event in Minio, a JSON
document is keyed together by the bucket and object name is updated in
Elasticsearch. In the case of an object being created or over-written
in Minio, a new document or an existing document is inserted into the
Elasticsearch index. If an object is deleted in Minio, the
corresponding document is deleted from the Elasticsearch index.
Additionally, this change upgrades Elasticsearch support to the 5.x
series. This is a breaking change, and users of previous elasticsearch
versions should upgrade.
Also updates documentation on Elasticsearch notification target usage
and has a link to an elasticsearch upgrade guide.
This is the last patch that finally resolves #3928.
2017-03-31 17:11:27 -04:00
|
|
|
// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/indices-create-index.html
|
2016-07-24 01:51:12 -04:00
|
|
|
// for details.
|
|
|
|
type IndicesCreateService struct {
|
|
|
|
client *Client
|
|
|
|
pretty bool
|
|
|
|
index string
|
|
|
|
timeout string
|
|
|
|
masterTimeout string
|
|
|
|
bodyJson interface{}
|
|
|
|
bodyString string
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewIndicesCreateService returns a new IndicesCreateService.
|
|
|
|
func NewIndicesCreateService(client *Client) *IndicesCreateService {
|
|
|
|
return &IndicesCreateService{client: client}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Index is the name of the index to create.
|
|
|
|
func (b *IndicesCreateService) Index(index string) *IndicesCreateService {
|
|
|
|
b.index = index
|
|
|
|
return b
|
|
|
|
}
|
|
|
|
|
|
|
|
// Timeout the explicit operation timeout, e.g. "5s".
|
|
|
|
func (s *IndicesCreateService) Timeout(timeout string) *IndicesCreateService {
|
|
|
|
s.timeout = timeout
|
|
|
|
return s
|
|
|
|
}
|
|
|
|
|
|
|
|
// MasterTimeout specifies the timeout for connection to master.
|
|
|
|
func (s *IndicesCreateService) MasterTimeout(masterTimeout string) *IndicesCreateService {
|
|
|
|
s.masterTimeout = masterTimeout
|
|
|
|
return s
|
|
|
|
}
|
|
|
|
|
|
|
|
// Body specifies the configuration of the index as a string.
|
|
|
|
// It is an alias for BodyString.
|
|
|
|
func (b *IndicesCreateService) Body(body string) *IndicesCreateService {
|
|
|
|
b.bodyString = body
|
|
|
|
return b
|
|
|
|
}
|
|
|
|
|
|
|
|
// BodyString specifies the configuration of the index as a string.
|
|
|
|
func (b *IndicesCreateService) BodyString(body string) *IndicesCreateService {
|
|
|
|
b.bodyString = body
|
|
|
|
return b
|
|
|
|
}
|
|
|
|
|
|
|
|
// BodyJson specifies the configuration of the index. The interface{} will
|
|
|
|
// be serializes as a JSON document, so use a map[string]interface{}.
|
|
|
|
func (b *IndicesCreateService) BodyJson(body interface{}) *IndicesCreateService {
|
|
|
|
b.bodyJson = body
|
|
|
|
return b
|
|
|
|
}
|
|
|
|
|
|
|
|
// Pretty indicates that the JSON response be indented and human readable.
|
|
|
|
func (b *IndicesCreateService) Pretty(pretty bool) *IndicesCreateService {
|
|
|
|
b.pretty = pretty
|
|
|
|
return b
|
|
|
|
}
|
|
|
|
|
|
|
|
// Do executes the operation.
|
Add `access` format support for Elasticsearch notification target (#4006)
This change adds `access` format support for notifications to a
Elasticsearch server, and it refactors `namespace` format support.
In the case of `access` format, for each event in Minio, a JSON
document is inserted into Elasticsearch with its timestamp set to the
event's timestamp, and with the ID generated automatically by
elasticsearch. No events are modified or deleted in this mode.
In the case of `namespace` format, for each event in Minio, a JSON
document is keyed together by the bucket and object name is updated in
Elasticsearch. In the case of an object being created or over-written
in Minio, a new document or an existing document is inserted into the
Elasticsearch index. If an object is deleted in Minio, the
corresponding document is deleted from the Elasticsearch index.
Additionally, this change upgrades Elasticsearch support to the 5.x
series. This is a breaking change, and users of previous elasticsearch
versions should upgrade.
Also updates documentation on Elasticsearch notification target usage
and has a link to an elasticsearch upgrade guide.
This is the last patch that finally resolves #3928.
2017-03-31 17:11:27 -04:00
|
|
|
func (b *IndicesCreateService) Do(ctx context.Context) (*IndicesCreateResult, error) {
|
2016-07-24 01:51:12 -04:00
|
|
|
if b.index == "" {
|
|
|
|
return nil, errors.New("missing index name")
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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", "1")
|
|
|
|
}
|
|
|
|
if b.masterTimeout != "" {
|
|
|
|
params.Set("master_timeout", b.masterTimeout)
|
|
|
|
}
|
|
|
|
if b.timeout != "" {
|
|
|
|
params.Set("timeout", b.timeout)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Setup HTTP request body
|
|
|
|
var body interface{}
|
|
|
|
if b.bodyJson != nil {
|
|
|
|
body = b.bodyJson
|
|
|
|
} else {
|
|
|
|
body = b.bodyString
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get response
|
Add `access` format support for Elasticsearch notification target (#4006)
This change adds `access` format support for notifications to a
Elasticsearch server, and it refactors `namespace` format support.
In the case of `access` format, for each event in Minio, a JSON
document is inserted into Elasticsearch with its timestamp set to the
event's timestamp, and with the ID generated automatically by
elasticsearch. No events are modified or deleted in this mode.
In the case of `namespace` format, for each event in Minio, a JSON
document is keyed together by the bucket and object name is updated in
Elasticsearch. In the case of an object being created or over-written
in Minio, a new document or an existing document is inserted into the
Elasticsearch index. If an object is deleted in Minio, the
corresponding document is deleted from the Elasticsearch index.
Additionally, this change upgrades Elasticsearch support to the 5.x
series. This is a breaking change, and users of previous elasticsearch
versions should upgrade.
Also updates documentation on Elasticsearch notification target usage
and has a link to an elasticsearch upgrade guide.
This is the last patch that finally resolves #3928.
2017-03-31 17:11:27 -04:00
|
|
|
res, err := b.client.PerformRequest(ctx, "PUT", path, params, body)
|
2016-07-24 01:51:12 -04:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
ret := new(IndicesCreateResult)
|
|
|
|
if err := b.client.decoder.Decode(res.Body, ret); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return ret, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// -- Result of a create index request.
|
|
|
|
|
|
|
|
// IndicesCreateResult is the outcome of creating a new index.
|
|
|
|
type IndicesCreateResult struct {
|
Add `access` format support for Elasticsearch notification target (#4006)
This change adds `access` format support for notifications to a
Elasticsearch server, and it refactors `namespace` format support.
In the case of `access` format, for each event in Minio, a JSON
document is inserted into Elasticsearch with its timestamp set to the
event's timestamp, and with the ID generated automatically by
elasticsearch. No events are modified or deleted in this mode.
In the case of `namespace` format, for each event in Minio, a JSON
document is keyed together by the bucket and object name is updated in
Elasticsearch. In the case of an object being created or over-written
in Minio, a new document or an existing document is inserted into the
Elasticsearch index. If an object is deleted in Minio, the
corresponding document is deleted from the Elasticsearch index.
Additionally, this change upgrades Elasticsearch support to the 5.x
series. This is a breaking change, and users of previous elasticsearch
versions should upgrade.
Also updates documentation on Elasticsearch notification target usage
and has a link to an elasticsearch upgrade guide.
This is the last patch that finally resolves #3928.
2017-03-31 17:11:27 -04:00
|
|
|
Acknowledged bool `json:"acknowledged"`
|
|
|
|
ShardsAcknowledged bool `json:"shards_acknowledged"`
|
2016-07-24 01:51:12 -04:00
|
|
|
}
|