// Performs a search request for a document based on the
// request in buf, and checks for any errors down the line.
Performs a search request for a document based on the
request in buf, and checks for any errors down the line.
// Performs a search request for a document based on the // request in buf and checks for any errors down the line .
func performQuery(buf bytes.Buffer) (*esapi.Response, error) {
	res, err := client.Search(
		client.Search.WithContext(context.Background()),
		client.Search.WithIndex("documents"),
		client.Search.WithBody(&buf),
		client.Search.WithTrackTotalHits(true),
		client.Search.WithPretty(),
	)
	if err != nil {
		return nil, fmt.Errorf("Error performing ES Search: %s", err)
	}
	if res.IsError() {
		var e map[string]interface{}
		if err := json.NewDecoder(res.Body).Decode(&e); err != nil {
			return nil, fmt.Errorf("Error parsing the error response body: %s", err)
		}
		return nil, fmt.Errorf("[%s] %s: %s",
			res.Status(),
			e["error"].(map[string]interface{})["type"],
			e["error"].(map[string]interface{})["reason"],
		)
	}
	return res, nil
}
func performQuery ( buf bytes . Buffer ) ( * esapi . Response , error ) { res , err := client . Search ( client . Search . WithContext ( context . Background ( ) ) , client . Search . WithIndex ( " " ) , client . Search . WithBody ( & buf ) , client . Search . WithTrackTotalHits ( true ) , client . Search . WithPretty ( ) , ) if err != nil { return nil , fmt . Errorf ( " " , err ) } if res . IsError ( ) { var e map [ string ] interface { } if err := json . NewDecoder ( res . Body ) . Decode ( & e ) ; err != nil { return nil , fmt . Errorf ( " " , err ) } return nil , fmt . Errorf ( " " , res . Status ( ) , e [ " " ] . ( map [ string ] interface { } ) [ " " ] , e [ " " ] . ( map [ string ] interface { } ) [ " " ] , ) } return res , nil }
Performs a search request for a document based on the
request in buf, and checks for any errors down the line.
Performs a search request for a document based on the request in buf and checks for any errors down the line .
// Perform the search request. // Check if ElasticSearch returned an error // Print the response status and error information.