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
|
|
|
|
|
|
|
|
// -- SuggesterGeoMapping --
|
|
|
|
|
|
|
|
// SuggesterGeoMapping provides a mapping for a geolocation context in a suggester.
|
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/suggester-context.html#_geo_location_mapping.
|
2016-07-24 01:51:12 -04:00
|
|
|
type SuggesterGeoMapping struct {
|
|
|
|
name string
|
|
|
|
defaultLocations []*GeoPoint
|
|
|
|
precision []string
|
|
|
|
neighbors *bool
|
|
|
|
fieldName string
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewSuggesterGeoMapping creates a new SuggesterGeoMapping.
|
|
|
|
func NewSuggesterGeoMapping(name string) *SuggesterGeoMapping {
|
|
|
|
return &SuggesterGeoMapping{
|
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
|
|
|
name: name,
|
2016-07-24 01:51:12 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (q *SuggesterGeoMapping) DefaultLocations(locations ...*GeoPoint) *SuggesterGeoMapping {
|
|
|
|
q.defaultLocations = append(q.defaultLocations, locations...)
|
|
|
|
return q
|
|
|
|
}
|
|
|
|
|
|
|
|
func (q *SuggesterGeoMapping) Precision(precision ...string) *SuggesterGeoMapping {
|
|
|
|
q.precision = append(q.precision, precision...)
|
|
|
|
return q
|
|
|
|
}
|
|
|
|
|
|
|
|
func (q *SuggesterGeoMapping) Neighbors(neighbors bool) *SuggesterGeoMapping {
|
|
|
|
q.neighbors = &neighbors
|
|
|
|
return q
|
|
|
|
}
|
|
|
|
|
|
|
|
func (q *SuggesterGeoMapping) FieldName(fieldName string) *SuggesterGeoMapping {
|
|
|
|
q.fieldName = fieldName
|
|
|
|
return q
|
|
|
|
}
|
|
|
|
|
|
|
|
// Source returns a map that will be used to serialize the context query as JSON.
|
|
|
|
func (q *SuggesterGeoMapping) Source() (interface{}, error) {
|
|
|
|
source := make(map[string]interface{})
|
|
|
|
|
|
|
|
x := make(map[string]interface{})
|
|
|
|
source[q.name] = x
|
|
|
|
|
|
|
|
x["type"] = "geo"
|
|
|
|
|
|
|
|
if len(q.precision) > 0 {
|
|
|
|
x["precision"] = q.precision
|
|
|
|
}
|
|
|
|
if q.neighbors != nil {
|
|
|
|
x["neighbors"] = *q.neighbors
|
|
|
|
}
|
|
|
|
|
|
|
|
switch len(q.defaultLocations) {
|
|
|
|
case 0:
|
|
|
|
case 1:
|
|
|
|
x["default"] = q.defaultLocations[0].Source()
|
|
|
|
default:
|
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
|
|
|
var arr []interface{}
|
2016-07-24 01:51:12 -04:00
|
|
|
for _, p := range q.defaultLocations {
|
|
|
|
arr = append(arr, p.Source())
|
|
|
|
}
|
|
|
|
x["default"] = arr
|
|
|
|
}
|
|
|
|
|
|
|
|
if q.fieldName != "" {
|
|
|
|
x["path"] = q.fieldName
|
|
|
|
}
|
|
|
|
return source, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// -- SuggesterGeoQuery --
|
|
|
|
|
|
|
|
// SuggesterGeoQuery provides querying a geolocation context in a suggester.
|
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/suggester-context.html#_geo_location_query
|
2016-07-24 01:51:12 -04:00
|
|
|
type SuggesterGeoQuery struct {
|
|
|
|
name string
|
|
|
|
location *GeoPoint
|
|
|
|
precision []string
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewSuggesterGeoQuery creates a new SuggesterGeoQuery.
|
|
|
|
func NewSuggesterGeoQuery(name string, location *GeoPoint) *SuggesterGeoQuery {
|
|
|
|
return &SuggesterGeoQuery{
|
|
|
|
name: name,
|
|
|
|
location: location,
|
|
|
|
precision: make([]string, 0),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (q *SuggesterGeoQuery) Precision(precision ...string) *SuggesterGeoQuery {
|
|
|
|
q.precision = append(q.precision, precision...)
|
|
|
|
return q
|
|
|
|
}
|
|
|
|
|
|
|
|
// Source returns a map that will be used to serialize the context query as JSON.
|
|
|
|
func (q *SuggesterGeoQuery) Source() (interface{}, error) {
|
|
|
|
source := make(map[string]interface{})
|
|
|
|
|
|
|
|
if len(q.precision) == 0 {
|
|
|
|
if q.location != nil {
|
|
|
|
source[q.name] = q.location.Source()
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
x := make(map[string]interface{})
|
|
|
|
source[q.name] = x
|
|
|
|
|
|
|
|
if q.location != nil {
|
|
|
|
x["value"] = q.location.Source()
|
|
|
|
}
|
|
|
|
|
|
|
|
switch len(q.precision) {
|
|
|
|
case 0:
|
|
|
|
case 1:
|
|
|
|
x["precision"] = q.precision[0]
|
|
|
|
default:
|
|
|
|
x["precision"] = q.precision
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return source, nil
|
|
|
|
}
|