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
41 changes: 26 additions & 15 deletions search_queries_match.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,22 @@ package elastic
// For more details, see
// https://www.elastic.co/guide/en/elasticsearch/reference/7.0/query-dsl-match-query.html
type MatchQuery struct {
name string
text interface{}
operator string // or / and
analyzer string
boost *float64
fuzziness string
prefixLength *int
maxExpansions *int
minimumShouldMatch string
fuzzyRewrite string
lenient *bool
fuzzyTranspositions *bool
zeroTermsQuery string
cutoffFrequency *float64
queryName string
name string
text interface{}
operator string // or / and
analyzer string
boost *float64
fuzziness string
prefixLength *int
maxExpansions *int
minimumShouldMatch string
fuzzyRewrite string
lenient *bool
fuzzyTranspositions *bool
zeroTermsQuery string
cutoffFrequency *float64
queryName string
autoGenerateSynonymsPhraseQuery *bool
}

// NewMatchQuery creates and initializes a new MatchQuery.
Expand Down Expand Up @@ -132,6 +133,13 @@ func (q *MatchQuery) QueryName(queryName string) *MatchQuery {
return q
}

// AutoGenerateSynonymsPhraseQuery indicates whether match phrase queries
// will be automatically created for multi-term synonyms.
func (q *MatchQuery) AutoGenerateSynonymsPhraseQuery(autoGenerateSynonymsPhraseQuery bool) *MatchQuery {
q.autoGenerateSynonymsPhraseQuery = &autoGenerateSynonymsPhraseQuery
return q
}

// Source returns JSON for the function score query.
func (q *MatchQuery) Source() (interface{}, error) {
// {"match":{"name":{"query":"value","type":"boolean/phrase"}}}
Expand Down Expand Up @@ -184,6 +192,9 @@ func (q *MatchQuery) Source() (interface{}, error) {
if q.queryName != "" {
query["_name"] = q.queryName
}
if q.autoGenerateSynonymsPhraseQuery != nil {
query["auto_generate_synonyms_phrase_query"] = *q.autoGenerateSynonymsPhraseQuery
}

return source, nil
}
49 changes: 30 additions & 19 deletions search_queries_multi_match.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,26 @@ import (
// For more details, see
// https://www.elastic.co/guide/en/elasticsearch/reference/7.0/query-dsl-multi-match-query.html
type MultiMatchQuery struct {
text interface{}
fields []string
fieldBoosts map[string]*float64
typ string // best_fields, boolean, most_fields, cross_fields, phrase, phrase_prefix
operator string // AND or OR
analyzer string
boost *float64
slop *int
fuzziness string
prefixLength *int
maxExpansions *int
minimumShouldMatch string
rewrite string
fuzzyRewrite string
tieBreaker *float64
lenient *bool
cutoffFrequency *float64
zeroTermsQuery string
queryName string
text interface{}
fields []string
fieldBoosts map[string]*float64
typ string // best_fields, boolean, most_fields, cross_fields, phrase, phrase_prefix
operator string // AND or OR
analyzer string
boost *float64
slop *int
fuzziness string
prefixLength *int
maxExpansions *int
minimumShouldMatch string
rewrite string
fuzzyRewrite string
tieBreaker *float64
lenient *bool
cutoffFrequency *float64
zeroTermsQuery string
queryName string
autoGenerateSynonymsPhraseQuery *bool
}

// MultiMatchQuery creates and initializes a new MultiMatchQuery.
Expand Down Expand Up @@ -182,6 +183,13 @@ func (q *MultiMatchQuery) QueryName(queryName string) *MultiMatchQuery {
return q
}

// AutoGenerateSynonymsPhraseQuery indicates whether match phrase queries
// will be automatically created for multi-term synonyms.
func (q *MultiMatchQuery) AutoGenerateSynonymsPhraseQuery(autoGenerateSynonymsPhraseQuery bool) *MultiMatchQuery {
q.autoGenerateSynonymsPhraseQuery = &autoGenerateSynonymsPhraseQuery
return q
}

// Source returns JSON for the query.
func (q *MultiMatchQuery) Source() (interface{}, error) {
//
Expand Down Expand Up @@ -266,5 +274,8 @@ func (q *MultiMatchQuery) Source() (interface{}, error) {
if q.queryName != "" {
multiMatch["_name"] = q.queryName
}
if q.autoGenerateSynonymsPhraseQuery != nil {
multiMatch["auto_generate_synonyms_phrase_query"] = *q.autoGenerateSynonymsPhraseQuery
}
return source, nil
}