Skip to content

Commit ccfa2b2

Browse files
committed
Add elastic.MatchAll shortcut
1 parent adff137 commit ccfa2b2

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

elastic/query.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ func Match(field string, value any) Query {
2222
return Query{"match": map[string]any{field: map[string]any{"query": value}}}
2323
}
2424

25+
// MatchAll is a shortcut for a match all query
26+
func MatchAll() Query {
27+
return Query{"match_all": map[string]any{}}
28+
}
29+
2530
// MatchPhrase is a shortcut for a match_phrase query
2631
func MatchPhrase(field, value string) Query {
2732
return Query{"match_phrase": map[string]any{field: map[string]any{"query": value}}}

elastic/query_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ func TestQuery(t *testing.T) {
1717
{elastic.Term("age", 42), []byte(`{"term": {"age": {"value":42}}}`)},
1818
{elastic.Exists("age"), []byte(`{"exists": {"field": "age"}}`)},
1919
{elastic.Match("name", "Bob"), []byte(`{"match": {"name": {"query": "Bob"}}}`)},
20+
{elastic.MatchAll(), []byte(`{"match_all": {}}`)},
2021
{elastic.MatchPhrase("name", "Bob"), []byte(`{"match_phrase": {"name": {"query": "Bob"}}}`)},
2122
{elastic.GreaterThan("age", 45), []byte(`{"range": {"age": {"gt": 45}}}`)},
2223
{elastic.GreaterThanOrEqual("age", 45), []byte(`{"range": {"age": {"gte": 45}}}`)},

0 commit comments

Comments
 (0)