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.
99 lines
2.6 KiB
Go
99 lines
2.6 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
|
|
|
|
// -- SuggesterCategoryMapping --
|
|
|
|
// SuggesterCategoryMapping provides a mapping for a category context in a suggester.
|
|
// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/suggester-context.html#_category_mapping.
|
|
type SuggesterCategoryMapping struct {
|
|
name string
|
|
fieldName string
|
|
defaultValues []string
|
|
}
|
|
|
|
// NewSuggesterCategoryMapping creates a new SuggesterCategoryMapping.
|
|
func NewSuggesterCategoryMapping(name string) *SuggesterCategoryMapping {
|
|
return &SuggesterCategoryMapping{
|
|
name: name,
|
|
defaultValues: make([]string, 0),
|
|
}
|
|
}
|
|
|
|
func (q *SuggesterCategoryMapping) DefaultValues(values ...string) *SuggesterCategoryMapping {
|
|
q.defaultValues = append(q.defaultValues, values...)
|
|
return q
|
|
}
|
|
|
|
func (q *SuggesterCategoryMapping) FieldName(fieldName string) *SuggesterCategoryMapping {
|
|
q.fieldName = fieldName
|
|
return q
|
|
}
|
|
|
|
// Source returns a map that will be used to serialize the context query as JSON.
|
|
func (q *SuggesterCategoryMapping) Source() (interface{}, error) {
|
|
source := make(map[string]interface{})
|
|
|
|
x := make(map[string]interface{})
|
|
source[q.name] = x
|
|
|
|
x["type"] = "category"
|
|
|
|
switch len(q.defaultValues) {
|
|
case 0:
|
|
x["default"] = q.defaultValues
|
|
case 1:
|
|
x["default"] = q.defaultValues[0]
|
|
default:
|
|
x["default"] = q.defaultValues
|
|
}
|
|
|
|
if q.fieldName != "" {
|
|
x["path"] = q.fieldName
|
|
}
|
|
return source, nil
|
|
}
|
|
|
|
// -- SuggesterCategoryQuery --
|
|
|
|
// SuggesterCategoryQuery provides querying a category context in a suggester.
|
|
// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/suggester-context.html#_category_query.
|
|
type SuggesterCategoryQuery struct {
|
|
name string
|
|
values []string
|
|
}
|
|
|
|
// NewSuggesterCategoryQuery creates a new SuggesterCategoryQuery.
|
|
func NewSuggesterCategoryQuery(name string, values ...string) *SuggesterCategoryQuery {
|
|
q := &SuggesterCategoryQuery{
|
|
name: name,
|
|
values: make([]string, 0),
|
|
}
|
|
if len(values) > 0 {
|
|
q.values = append(q.values, values...)
|
|
}
|
|
return q
|
|
}
|
|
|
|
func (q *SuggesterCategoryQuery) Values(values ...string) *SuggesterCategoryQuery {
|
|
q.values = append(q.values, values...)
|
|
return q
|
|
}
|
|
|
|
// Source returns a map that will be used to serialize the context query as JSON.
|
|
func (q *SuggesterCategoryQuery) Source() (interface{}, error) {
|
|
source := make(map[string]interface{})
|
|
|
|
switch len(q.values) {
|
|
case 0:
|
|
source[q.name] = q.values
|
|
case 1:
|
|
source[q.name] = q.values[0]
|
|
default:
|
|
source[q.name] = q.values
|
|
}
|
|
|
|
return source, nil
|
|
}
|