search_queries_match_none.go 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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. package elastic
  5. // MatchNoneQuery returns no documents. It is the inverse of
  6. // MatchAllQuery.
  7. //
  8. // For more details, see
  9. // https://www.elastic.co/guide/en/elasticsearch/reference/5.6/query-dsl-match-all-query.html
  10. type MatchNoneQuery struct {
  11. queryName string
  12. }
  13. // NewMatchNoneQuery creates and initializes a new match none query.
  14. func NewMatchNoneQuery() *MatchNoneQuery {
  15. return &MatchNoneQuery{}
  16. }
  17. // QueryName sets the query name.
  18. func (q *MatchNoneQuery) QueryName(name string) *MatchNoneQuery {
  19. q.queryName = name
  20. return q
  21. }
  22. // Source returns JSON for the match none query.
  23. func (q MatchNoneQuery) Source() (interface{}, error) {
  24. // {
  25. // "match_none" : { ... }
  26. // }
  27. source := make(map[string]interface{})
  28. params := make(map[string]interface{})
  29. source["match_none"] = params
  30. if q.queryName != "" {
  31. params["_name"] = q.queryName
  32. }
  33. return source, nil
  34. }