search_queries_match_all.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // Copyright 2012-2015 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. // A query that matches all documents. Maps to Lucene MatchAllDocsQuery.
  6. // For more details, see
  7. // http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-match-all-query.html
  8. type MatchAllQuery struct {
  9. Query
  10. normsField string
  11. boost *float32
  12. }
  13. // NewMatchAllQuery creates a new match all query.
  14. func NewMatchAllQuery() MatchAllQuery {
  15. q := MatchAllQuery{}
  16. return q
  17. }
  18. func (q MatchAllQuery) NormsField(normsField string) MatchAllQuery {
  19. q.normsField = normsField
  20. return q
  21. }
  22. func (q MatchAllQuery) Boost(boost float32) MatchAllQuery {
  23. q.boost = &boost
  24. return q
  25. }
  26. // Creates the query source for the match all query.
  27. func (q MatchAllQuery) Source() interface{} {
  28. // {
  29. // "match_all" : { ... }
  30. // }
  31. source := make(map[string]interface{})
  32. params := make(map[string]interface{})
  33. source["match_all"] = params
  34. if q.boost != nil {
  35. params["boost"] = q.boost
  36. }
  37. if q.normsField != "" {
  38. params["norms_field"] = q.normsField
  39. }
  40. return source
  41. }