Skip to content
Snippets Groups Projects
Commit cfe7a39f authored by Jan Semmelink's avatar Jan Semmelink
Browse files

Update query to fix text search

parent a9d36e4d
No related branches found
No related tags found
1 merge request!6Search package improvements to retrieve documents with text searches from OpenSearch
......@@ -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:
// {
......
......@@ -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
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment