Skip to content

Commit

Permalink
Merge pull request #4 from GokselKUCUKSAHIN/hotfix/match
Browse files Browse the repository at this point in the history
fix: match query
  • Loading branch information
GokselKUCUKSAHIN committed Apr 12, 2024
2 parents 2ef6a37 + acdb88f commit 2b7baac
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
20 changes: 12 additions & 8 deletions es/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,21 +286,25 @@ func Match[T any](key string, query T) matchType {
}
}

func (m matchType) putInField(key string, value any) matchType {
for field := range m {
if matchObject, ok := m[field].(Object); ok {
matchObject[key] = value
func (m matchType) putInTheField(key string, value any) matchType {
if match, exists := m["match"]; exists {
if matchObject, moOk := match.(Object); moOk {
for field := range matchObject {
if fieldObject, foOk := matchObject[field].(Object); foOk {
fieldObject[key] = value
}
}
}
}
return m
}

func (m matchType) Operator(operator Operator.Operator) matchType {
return m.putInField("operator", operator)
return m.putInTheField("operator", operator)
}

func (m matchType) Boost(boost float64) matchType {
return m.putInField("boost", boost)
return m.putInTheField("boost", boost)
}

func MatchAll() matchAllType {
Expand All @@ -309,15 +313,15 @@ func MatchAll() matchAllType {
}
}

func (m matchAllType) putInField(key string, value any) matchAllType {
func (m matchAllType) putInTheField(key string, value any) matchAllType {
if matchAll, exists := m["match_all"]; exists {
matchAll.(Object)[key] = value
}
return m
}

func (m matchAllType) Boost(boost float64) matchAllType {
return m.putInField("boost", boost)
return m.putInTheField("boost", boost)
}

func Range(key string) rangeType {
Expand Down
2 changes: 1 addition & 1 deletion es/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -771,7 +771,7 @@ func Test_Match_should_create_json_with_match_field_inside_query(t *testing.T) {
assert.NotNil(t, query)
bodyJSON := assert.MarshalWithoutError(t, query)
assert.Equal(t,
"{\"query\":{\"match\":{\"boost\":2.14,\"message\":{\"query\":\"this is a test\"},\"operator\":\"or\"}}}", bodyJSON)
"{\"query\":{\"match\":{\"message\":{\"boost\":2.14,\"operator\":\"or\",\"query\":\"this is a test\"}}}}", bodyJSON)
}

//// MatchAll ////
Expand Down

0 comments on commit 2b7baac

Please sign in to comment.