diff --git a/search/opensearch_types.go b/search/opensearch_types.go index b46a9ffe1729e7948ed94a778864fe389b2b94fe..72c048ad80c0655e974af0af735b2cba37f332c6 100644 --- a/search/opensearch_types.go +++ b/search/opensearch_types.go @@ -26,6 +26,7 @@ type MappingProperty struct { Enabled bool `json:"enabled,omitempty"` Fields map[string]MappingFieldProperties `json:"fields,omitempty"` Properties map[string]MappingProperty `json:"properties,omitempty"` + //Index bool `json:"index,omitempty"` //set true to make text field searchable } type MappingFieldProperties struct { @@ -53,7 +54,7 @@ type Query struct { type QueryMultiMatch struct { Query string `json:"query" doc:"Text search in below fields"` - Fields []string `json:"fields" doc:"List of fields"` + Fields []string `json:"fields,omitempty" doc:"List of fields"` } //https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-bool-query.html @@ -85,7 +86,7 @@ func QueryValueTime(t time.Time) QueryValue { type QueryRange map[string]QueryExpr -type QueryExpr map[string]QueryValue //<oper>:<value> e.g. "gte":"10" +type QueryExpr map[string]string //<oper>:<value> e.g. "gte":"10" //example of search response body: // { diff --git a/search/time_series.go b/search/time_series.go index 46cc0493e3d28cbbae098cf32f139d723e4f1abf..3a13720a1706ca99d1fcb3d93176804ced4bcc84 100644 --- a/search/time_series.go +++ b/search/time_series.go @@ -4,6 +4,7 @@ import ( "bytes" "context" "encoding/json" + "io/ioutil" "net/http" "reflect" "strings" @@ -15,6 +16,8 @@ import ( "gitlab.com/uafrica/go-utils/reflection" ) +const TimeFormat = "2006-01-02T15:04:05+07:00" + //embed this into your log struct type TimeSeriesHeader struct { StartTime time.Time `json:"@timestamp"` @@ -339,7 +342,8 @@ func (ts *timeSeries) Search(query Query, limit int64) (docs interface{}, totalC switch searchResponse.StatusCode { case http.StatusOK: default: - err = errors.Errorf("Search failed with HTTP status %v", searchResponse.StatusCode) + resBody, _ := ioutil.ReadAll(searchResponse.Body) + err = errors.Errorf("Search failed with HTTP status %v: %s", searchResponse.StatusCode, string(resBody)) return }