Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions query_match.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ type matchParams struct {
MinMatch string `structs:"minimum_should_match,omitempty"`
ZeroTerms ZeroTerms `structs:"zero_terms_query,string,omitempty"`
Slp uint16 `structs:"slop,omitempty"` // only relevant for match_phrase query
Boost float32 `structs:"boost,omitempty"`
}

// Match creates a new query of type "match" with the provided field name.
Expand Down Expand Up @@ -202,6 +203,12 @@ func (q *MatchQuery) ZeroTermsQuery(s ZeroTerms) *MatchQuery {
return q
}

// Boost sets the boost value of the query.
func (a *MatchQuery) Boost(b float32) *MatchQuery {
a.params.Boost = b
return a
}

// MatchOperator is an enumeration type representing supported values for a
// match query's "operator" parameter.
type MatchOperator uint8
Expand Down
12 changes: 12 additions & 0 deletions query_match_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,18 @@ func TestMatch(t *testing.T) {
},
},
},
{
"simple match",
Match("title", "sample text").Boost(50),
map[string]interface{}{
"match": map[string]interface{}{
"title": map[string]interface{}{
"query": "sample text",
"boost": 50,
},
},
},
},
{
"match with more params",
Match("issue_number").Query(16).Transpositions(false).MaxExpansions(32).Operator(OperatorAnd),
Expand Down