| 1 |
// Copyright 2012-present Oliver Eilhard. All rights reserved. |
| 2 |
// Use of this source code is governed by a MIT-license. |
| 3 |
// See http://olivere.mit-license.org/license.txt for details. |
| 4 |
|
| 5 |
package elastic |
| 6 |
|
| 7 |
// MatchNoneQuery returns no documents. It is the inverse of |
| 8 |
// MatchAllQuery. |
| 9 |
// |
| 10 |
// For more details, see |
| 11 |
// https://www.elastic.co/guide/en/elasticsearch/reference/5.6/query-dsl-match-all-query.html |
| 12 |
type MatchNoneQuery struct { |
| 13 |
queryName string |
| 14 |
} |
| 15 |
|
| 16 |
// NewMatchNoneQuery creates and initializes a new match none query. |
| 17 |
func NewMatchNoneQuery() *MatchNoneQuery { |
| 18 |
return &MatchNoneQuery{} |
| 19 |
} |
| 20 |
|
| 21 |
// QueryName sets the query name. |
| 22 |
func (q *MatchNoneQuery) QueryName(name string) *MatchNoneQuery { |
| 23 |
q.queryName = name |
| 24 |
return q |
| 25 |
} |
| 26 |
|
| 27 |
// Source returns JSON for the match none query. |
| 28 |
func (q MatchNoneQuery) Source() (interface{}, error) { |
| 29 |
// { |
| 30 |
// "match_none" : { ... } |
| 31 |
// } |
| 32 |
source := make(map[string]interface{}) |
| 33 |
params := make(map[string]interface{}) |
| 34 |
source["match_none"] = params |
| 35 |
if q.queryName != "" { |
| 36 |
params["_name"] = q.queryName |
| 37 |
} |
| 38 |
return source, nil |
| 39 |
} |