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.
89 lines
2.3 KiB
Go
89 lines
2.3 KiB
Go
// Copyright 2012-present 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
|
|
|
|
// IndicesQuery can be used when executed across multiple indices, allowing
|
|
// to have a query that executes only when executed on an index that matches
|
|
// a specific list of indices, and another query that executes when it is
|
|
// executed on an index that does not match the listed indices.
|
|
//
|
|
// For more details, see
|
|
// https://www.elastic.co/guide/en/elasticsearch/reference/5.2/query-dsl-indices-query.html
|
|
type IndicesQuery struct {
|
|
query Query
|
|
indices []string
|
|
noMatchQueryType string
|
|
noMatchQuery Query
|
|
queryName string
|
|
}
|
|
|
|
// NewIndicesQuery creates and initializes a new indices query.
|
|
func NewIndicesQuery(query Query, indices ...string) *IndicesQuery {
|
|
return &IndicesQuery{
|
|
query: query,
|
|
indices: indices,
|
|
}
|
|
}
|
|
|
|
// NoMatchQuery sets the query to use when it executes on an index that
|
|
// does not match the indices provided.
|
|
func (q *IndicesQuery) NoMatchQuery(query Query) *IndicesQuery {
|
|
q.noMatchQuery = query
|
|
return q
|
|
}
|
|
|
|
// NoMatchQueryType sets the no match query which can be either all or none.
|
|
func (q *IndicesQuery) NoMatchQueryType(typ string) *IndicesQuery {
|
|
q.noMatchQueryType = typ
|
|
return q
|
|
}
|
|
|
|
// QueryName sets the query name for the filter.
|
|
func (q *IndicesQuery) QueryName(queryName string) *IndicesQuery {
|
|
q.queryName = queryName
|
|
return q
|
|
}
|
|
|
|
// Source returns JSON for the function score query.
|
|
func (q *IndicesQuery) Source() (interface{}, error) {
|
|
// {
|
|
// "indices" : {
|
|
// "indices" : ["index1", "index2"],
|
|
// "query" : {
|
|
// "term" : { "tag" : "wow" }
|
|
// },
|
|
// "no_match_query" : {
|
|
// "term" : { "tag" : "kow" }
|
|
// }
|
|
// }
|
|
// }
|
|
|
|
source := make(map[string]interface{})
|
|
params := make(map[string]interface{})
|
|
source["indices"] = params
|
|
|
|
params["indices"] = q.indices
|
|
|
|
src, err := q.query.Source()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
params["query"] = src
|
|
|
|
if q.noMatchQuery != nil {
|
|
src, err := q.noMatchQuery.Source()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
params["no_match_query"] = src
|
|
} else if q.noMatchQueryType != "" {
|
|
params["no_match_query"] = q.noMatchQueryType
|
|
}
|
|
if q.queryName != "" {
|
|
params["_name"] = q.queryName
|
|
}
|
|
|
|
return source, nil
|
|
}
|