Yes. That's how it works. RawStringQuery
is a query, not the message body. As such, you use it like you'd do with any query:
package main
import (
"fmt"
"gopkg.in/olivere/elastic.v3"
)
func main() {
client, err := elastic.NewClient()
if err != nil {
panic(err)
}
s := `{"match_all":{}}`
res, err := client.Search().
Index("store2").
Query(elastic.RawStringQuery(s)).
Sort("price", true).
Do()
if err != nil {
panic(err)
}
fmt.Printf("%d results
", res.TotalHits)
}
If you want to pass raw JSON and send it as the body for your request, this does the job:
package main
import (
"fmt"
"gopkg.in/olivere/elastic.v3"
)
func main() {
client, err := elastic.NewClient()
if err != nil {
panic(err)
}
s := `{"query":{"match_all":{}},"sort":[{"price":{"order":"asc"}}]}`
res, err := client.Search().
Index("store2").
Source(s).
Do()
if err != nil {
panic(err)
}
fmt.Printf("%d results
", res.TotalHits)
}