Skip to content

Commit

Permalink
Add elastic.MatchAll shortcut
Browse files Browse the repository at this point in the history
  • Loading branch information
rowanseymour committed Sep 25, 2024
1 parent adff137 commit ccfa2b2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
5 changes: 5 additions & 0 deletions elastic/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ func Match(field string, value any) Query {
return Query{"match": map[string]any{field: map[string]any{"query": value}}}
}

// MatchAll is a shortcut for a match all query
func MatchAll() Query {
return Query{"match_all": map[string]any{}}
}

// MatchPhrase is a shortcut for a match_phrase query
func MatchPhrase(field, value string) Query {
return Query{"match_phrase": map[string]any{field: map[string]any{"query": value}}}
Expand Down
1 change: 1 addition & 0 deletions elastic/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ func TestQuery(t *testing.T) {
{elastic.Term("age", 42), []byte(`{"term": {"age": {"value":42}}}`)},
{elastic.Exists("age"), []byte(`{"exists": {"field": "age"}}`)},
{elastic.Match("name", "Bob"), []byte(`{"match": {"name": {"query": "Bob"}}}`)},
{elastic.MatchAll(), []byte(`{"match_all": {}}`)},
{elastic.MatchPhrase("name", "Bob"), []byte(`{"match_phrase": {"name": {"query": "Bob"}}}`)},
{elastic.GreaterThan("age", 45), []byte(`{"range": {"age": {"gt": 45}}}`)},
{elastic.GreaterThanOrEqual("age", 45), []byte(`{"range": {"age": {"gte": 45}}}`)},
Expand Down

0 comments on commit ccfa2b2

Please sign in to comment.