mirror of
https://github.com/minio/minio.git
synced 2024-12-26 23:25:54 -05:00
a2a8d54bb6
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.
98 lines
2.2 KiB
Go
98 lines
2.2 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
|
|
|
|
// A boosting query can be used to effectively
|
|
// demote results that match a given query.
|
|
// For more details, see:
|
|
// https://www.elastic.co/guide/en/elasticsearch/reference/5.2/query-dsl-boosting-query.html
|
|
type BoostingQuery struct {
|
|
Query
|
|
positiveClause Query
|
|
negativeClause Query
|
|
negativeBoost *float64
|
|
boost *float64
|
|
}
|
|
|
|
// Creates a new boosting query.
|
|
func NewBoostingQuery() *BoostingQuery {
|
|
return &BoostingQuery{}
|
|
}
|
|
|
|
func (q *BoostingQuery) Positive(positive Query) *BoostingQuery {
|
|
q.positiveClause = positive
|
|
return q
|
|
}
|
|
|
|
func (q *BoostingQuery) Negative(negative Query) *BoostingQuery {
|
|
q.negativeClause = negative
|
|
return q
|
|
}
|
|
|
|
func (q *BoostingQuery) NegativeBoost(negativeBoost float64) *BoostingQuery {
|
|
q.negativeBoost = &negativeBoost
|
|
return q
|
|
}
|
|
|
|
func (q *BoostingQuery) Boost(boost float64) *BoostingQuery {
|
|
q.boost = &boost
|
|
return q
|
|
}
|
|
|
|
// Creates the query source for the boosting query.
|
|
func (q *BoostingQuery) Source() (interface{}, error) {
|
|
// {
|
|
// "boosting" : {
|
|
// "positive" : {
|
|
// "term" : {
|
|
// "field1" : "value1"
|
|
// }
|
|
// },
|
|
// "negative" : {
|
|
// "term" : {
|
|
// "field2" : "value2"
|
|
// }
|
|
// },
|
|
// "negative_boost" : 0.2
|
|
// }
|
|
// }
|
|
|
|
query := make(map[string]interface{})
|
|
|
|
boostingClause := make(map[string]interface{})
|
|
query["boosting"] = boostingClause
|
|
|
|
// Negative and positive clause as well as negative boost
|
|
// are mandatory in the Java client.
|
|
|
|
// positive
|
|
if q.positiveClause != nil {
|
|
src, err := q.positiveClause.Source()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
boostingClause["positive"] = src
|
|
}
|
|
|
|
// negative
|
|
if q.negativeClause != nil {
|
|
src, err := q.negativeClause.Source()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
boostingClause["negative"] = src
|
|
}
|
|
|
|
if q.negativeBoost != nil {
|
|
boostingClause["negative_boost"] = *q.negativeBoost
|
|
}
|
|
|
|
if q.boost != nil {
|
|
boostingClause["boost"] = *q.boost
|
|
}
|
|
|
|
return query, nil
|
|
}
|