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