I'm relatively new to Go and I'm currently trying to search records in elastic search, below is the basic code I have created, so far I'm able to perform a simple GET request "http://10.132.0.13:9200/" and results are returned as expected. However, once I try to run a slightly more complex GET request it fails.
Below is the code I have created so far.
package main
import (
"fmt"
"io/ioutil"
"net/http"
)
func main() {
//request, err := http.Get(`http://10.132.0.13:9200/`) // this just returns the test page
request, err := http.Get(`http://10.132.0.13:9200/database-*/_search?pretty -d { "query": { "match": {"_all": "searchterm"}}}`)
if err != nil {
//error
}
defer request.Body.Close()
body, err := ioutil.ReadAll(request.Body)
fmt.Println(string(body))
}
I can query the index directly with the use of curl -xget and it returns the expected results
Is there a way to implement a similar curl -xget in golang?