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
Branches
Tags
1 merge request!6Search package improvements to retrieve documents with text searches from OpenSearch
...@@ -26,6 +26,7 @@ type MappingProperty struct { ...@@ -26,6 +26,7 @@ type MappingProperty struct {
Enabled bool `json:"enabled,omitempty"` Enabled bool `json:"enabled,omitempty"`
Fields map[string]MappingFieldProperties `json:"fields,omitempty"` Fields map[string]MappingFieldProperties `json:"fields,omitempty"`
Properties map[string]MappingProperty `json:"properties,omitempty"` Properties map[string]MappingProperty `json:"properties,omitempty"`
//Index bool `json:"index,omitempty"` //set true to make text field searchable
} }
type MappingFieldProperties struct { type MappingFieldProperties struct {
...@@ -53,7 +54,7 @@ type Query struct { ...@@ -53,7 +54,7 @@ type Query struct {
type QueryMultiMatch struct { type QueryMultiMatch struct {
Query string `json:"query" doc:"Text search in below fields"` 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 //https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-bool-query.html
...@@ -85,7 +86,7 @@ func QueryValueTime(t time.Time) QueryValue { ...@@ -85,7 +86,7 @@ func QueryValueTime(t time.Time) QueryValue {
type QueryRange map[string]QueryExpr 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: //example of search response body:
// { // {
......
...@@ -4,6 +4,7 @@ import ( ...@@ -4,6 +4,7 @@ import (
"bytes" "bytes"
"context" "context"
"encoding/json" "encoding/json"
"io/ioutil"
"net/http" "net/http"
"reflect" "reflect"
"strings" "strings"
...@@ -15,6 +16,8 @@ import ( ...@@ -15,6 +16,8 @@ import (
"gitlab.com/uafrica/go-utils/reflection" "gitlab.com/uafrica/go-utils/reflection"
) )
const TimeFormat = "2006-01-02T15:04:05+07:00"
//embed this into your log struct //embed this into your log struct
type TimeSeriesHeader struct { type TimeSeriesHeader struct {
StartTime time.Time `json:"@timestamp"` StartTime time.Time `json:"@timestamp"`
...@@ -339,7 +342,8 @@ func (ts *timeSeries) Search(query Query, limit int64) (docs interface{}, totalC ...@@ -339,7 +342,8 @@ func (ts *timeSeries) Search(query Query, limit int64) (docs interface{}, totalC
switch searchResponse.StatusCode { switch searchResponse.StatusCode {
case http.StatusOK: case http.StatusOK:
default: 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 return
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment