Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
bobgroup-go-utils
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Bob Public Utils
bobgroup-go-utils
Commits
cfe7a39f
Commit
cfe7a39f
authored
3 years ago
by
Jan Semmelink
Browse files
Options
Downloads
Patches
Plain Diff
Update query to fix text search
parent
a9d36e4d
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!6
Search package improvements to retrieve documents with text searches from OpenSearch
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
search/opensearch_types.go
+3
-2
3 additions, 2 deletions
search/opensearch_types.go
search/time_series.go
+5
-1
5 additions, 1 deletion
search/time_series.go
with
8 additions
and
3 deletions
search/opensearch_types.go
+
3
−
2
View file @
cfe7a39f
...
@@ -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:
// {
// {
...
...
This diff is collapsed.
Click to expand it.
search/time_series.go
+
5
−
1
View file @
cfe7a39f
...
@@ -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
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment