search_queries_raw_string.go 821 B

1234567891011121314151617181920212223242526
  1. // Copyright 2012-present Oliver Eilhard, John Stanford. 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. import "encoding/json"
  6. // RawStringQuery can be used to treat a string representation of an ES query
  7. // as a Query. Example usage:
  8. // q := RawStringQuery("{\"match_all\":{}}")
  9. // db.Search().Query(q).From(1).Size(100).Do()
  10. type RawStringQuery string
  11. // NewRawStringQuery ininitializes a new RawStringQuery.
  12. // It is the same as RawStringQuery(q).
  13. func NewRawStringQuery(q string) RawStringQuery {
  14. return RawStringQuery(q)
  15. }
  16. // Source returns the JSON encoded body
  17. func (q RawStringQuery) Source() (interface{}, error) {
  18. var f interface{}
  19. err := json.Unmarshal([]byte(q), &f)
  20. return f, err
  21. }