From 49a92fc25e9dab2ffe10380889ca01b8b21cb557 Mon Sep 17 00:00:00 2001 From: Hardy Date: Mon, 15 Mar 2021 15:43:59 +0800 Subject: [PATCH 1/7] =?UTF-8?q?Features:=20SearchAfter=E3=80=81Term=20Aggr?= =?UTF-8?q?egation=20Order=E3=80=81Aggregation=20=20Include=20Filter=20Val?= =?UTF-8?q?ues=20(#14)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add support for multi_match queries * Add support for highlights * Add support for nested aggregations and filtered aggregations * Update README * Fix formatting * fix * feat: add support for search after * fix:set search after []string to []interface * fix:add .gitignore * feat:Support for term aggs order * Feat: Support include filter for termAggs * Update aggregations_test.go Fix conflict. * Update go.mod Co-authored-by: Caleb Champlin Co-authored-by: Hardy Co-authored-by: Oran Moshai <12291998+oranmoshai@users.noreply.github.com> --- .gitignore | 1 + aggregations_test.go | 76 ++++++++++++++++++++++++++++++++++++++++---- aggs_bucket.go | 26 +++++++++++++++ go.sum | 4 --- search.go | 33 +++++++++++++------ search_test.go | 7 ++++ 6 files changed, 127 insertions(+), 20 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..62c8935 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.idea/ \ No newline at end of file diff --git a/aggregations_test.go b/aggregations_test.go index 39eeaa3..949123d 100644 --- a/aggregations_test.go +++ b/aggregations_test.go @@ -61,8 +61,8 @@ func TestAggregations(t *testing.T) { { "a complex, multi-aggregation, nested", Aggregate( - NestedAgg("categories","categories"). - Aggs(TermsAgg("type","outdoors")), + NestedAgg("categories", "categories"). + Aggs(TermsAgg("type", "outdoors")), FilterAgg("filtered", Term("type", "t-shirt")), ), @@ -72,9 +72,9 @@ func TestAggregations(t *testing.T) { "nested": map[string]interface{}{ "path": "categories", }, - "aggs": map[string]interface{} { - "type": map[string]interface{} { - "terms": map[string]interface{} { + "aggs": map[string]interface{}{ + "type": map[string]interface{}{ + "terms": map[string]interface{}{ "field": "outdoors", }, }, @@ -83,7 +83,7 @@ func TestAggregations(t *testing.T) { "filtered": map[string]interface{}{ "filter": map[string]interface{}{ "term": map[string]interface{}{ - "type": map[string]interface{} { + "type": map[string]interface{}{ "value": "t-shirt", }, }, @@ -92,5 +92,69 @@ func TestAggregations(t *testing.T) { }, }, }, + { + "order for termsAggs", + //eq.Aggregate(eq.TermsAgg("a1", "FIELD1").Size(0).Aggs(eq.Sum("a2", "FIELD2.SUBFIELD"))) + Aggregate( + TermsAgg("categories", "categories"). + Order(map[string]string{"priceSum": "desc"}). + Size(5).Aggs(Sum("priceSum", "price"))), + map[string]interface{}{ + "aggs": map[string]interface{}{ + "categories": map[string]interface{}{ + "terms": map[string]interface{}{ + "field": "categories", + "order": map[string]interface{}{ + "priceSum": "desc", + }, + "size": 5, + }, + "aggs": map[string]interface{}{ + "priceSum": map[string]interface{}{ + "sum": map[string]interface{}{ + "field": "price", + }, + }, + }, + }, + }, + }, + }, + { + "Single include for termsAggs", + //eq.Aggregate(eq.TermsAgg("a1", "FIELD1").Size(0).Aggs(eq.Sum("a2", "FIELD2.SUBFIELD"))) + Aggregate( + TermsAgg("categories", "categories"). + Include("red.*|blue.*"), + ), + map[string]interface{}{ + "aggs": map[string]interface{}{ + "categories": map[string]interface{}{ + "terms": map[string]interface{}{ + "field": "categories", + "include": "red.*|blue.*", + }, + }, + }, + }, + }, + { + "Multi include for termsAggs", + //eq.Aggregate(eq.TermsAgg("a1", "FIELD1").Size(0).Aggs(eq.Sum("a2", "FIELD2.SUBFIELD"))) + Aggregate( + TermsAgg("categories", "categories"). + Include("red", "blue"), + ), + map[string]interface{}{ + "aggs": map[string]interface{}{ + "categories": map[string]interface{}{ + "terms": map[string]interface{}{ + "field": "categories", + "include": []string{"red", "blue"}, + }, + }, + }, + }, + }, }) } diff --git a/aggs_bucket.go b/aggs_bucket.go index 09b5185..1a45a14 100644 --- a/aggs_bucket.go +++ b/aggs_bucket.go @@ -12,6 +12,8 @@ type TermsAggregation struct { shardSize *float64 showTermDoc *bool aggs []Aggregation + order map[string]string + include []string } // TermsAgg creates a new aggregation of type "terms". The method name includes @@ -54,6 +56,18 @@ func (agg *TermsAggregation) Aggs(aggs ...Aggregation) *TermsAggregation { return agg } +// Order sets the sort for terms agg +func (agg *TermsAggregation) Order(order map[string]string) *TermsAggregation { + agg.order = order + return agg +} + +// Include filter the values for buckets +func (agg *TermsAggregation) Include(include ...string) *TermsAggregation { + agg.include = include + return agg +} + // Map returns a map representation of the aggregation, thus implementing the // Mappable interface. func (agg *TermsAggregation) Map() map[string]interface{} { @@ -70,6 +84,18 @@ func (agg *TermsAggregation) Map() map[string]interface{} { if agg.showTermDoc != nil { innerMap["show_term_doc_count_error"] = *agg.showTermDoc } + if agg.order != nil { + innerMap["order"] = agg.order + } + + if agg.include != nil { + if len(agg.include) <= 1 { + innerMap["include"] = agg.include[0] + } else { + innerMap["include"] = agg.include + } + + } outerMap := map[string]interface{}{ "terms": innerMap, diff --git a/go.sum b/go.sum index 4108027..fae67ff 100644 --- a/go.sum +++ b/go.sum @@ -1,9 +1,5 @@ -github.com/elastic/go-elasticsearch v0.0.0 h1:Pd5fqOuBxKxv83b0+xOAJDAkziWYwFinWnBO0y+TZaA= -github.com/elastic/go-elasticsearch v0.0.0/go.mod h1:TkBSJBuTyFdBnrNqoPc54FN0vKf5c04IdM4zuStJ7xg= github.com/elastic/go-elasticsearch/v7 v7.6.0 h1:sYpGLpEFHgLUKLsZUBfuaVI9QgHjS3JdH9fX4/z8QI8= github.com/elastic/go-elasticsearch/v7 v7.6.0/go.mod h1:OJ4wdbtDNk5g503kvlHLyErCgQwwzmDtaFC4XyOxXA4= -github.com/elastic/go-elasticsearch/v8 v8.0.0-20200210103600-aff00e5adfde h1:Y9SZx8RQqFycLxi5W5eFmxMqnmijULVc3LMjBTtZQdM= -github.com/elastic/go-elasticsearch/v8 v8.0.0-20200210103600-aff00e5adfde/go.mod h1:xe9a/L2aeOgFKKgrO3ibQTnMdpAeL0GC+5/HpGScSa4= github.com/fatih/structs v1.1.0 h1:Q7juDM0QtcnhCpeyLGQKyg4TOIghuNXrkL32pHAUMxo= github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M= github.com/jgroeneveld/schema v1.0.0 h1:J0E10CrOkiSEsw6dfb1IfrDJD14pf6QLVJ3tRPl/syI= diff --git a/search.go b/search.go index 39dabf6..5c661a2 100644 --- a/search.go +++ b/search.go @@ -15,16 +15,18 @@ import ( // Not all features of the search API are currently supported, but a request can // currently include a query, aggregations, and more. type SearchRequest struct { - aggs []Aggregation - explain *bool - from *uint64 - highlight Mappable - postFilter Mappable - query Mappable - size *uint64 - sort Sort - source Source - timeout *time.Duration + aggs []Aggregation + explain *bool + from *uint64 + highlight Mappable + searchAfter []interface{} + postFilter Mappable + query Mappable + size *uint64 + sort Sort + source Source + timeout *time.Duration + } // Search creates a new SearchRequest object, to be filled via method chaining. @@ -74,6 +76,12 @@ func (req *SearchRequest) Sort(name string, order Order) *SearchRequest { return req } +// SearchAfter retrieve the sorted result +func (req *SearchRequest) SearchAfter(s ...interface{}) *SearchRequest { + req.searchAfter = append(req.searchAfter, s...) + return req +} + // Explain sets whether the ElasticSearch API should return an explanation for // how each hit's score was calculated. func (req *SearchRequest) Explain(b bool) *SearchRequest { @@ -106,6 +114,7 @@ func (req *SearchRequest) Highlight(highlight Mappable) *SearchRequest { } + // Map implements the Mappable interface. It converts the request to into a // nested map[string]interface{}, as expected by the go-elasticsearch library. func (req *SearchRequest) Map() map[string]interface{} { @@ -142,6 +151,10 @@ func (req *SearchRequest) Map() map[string]interface{} { if req.highlight != nil { m["highlight"] = req.highlight.Map() } + if req.searchAfter != nil { + m["search_after"] = req.searchAfter + } + source := req.source.Map() if len(source) > 0 { diff --git a/search_test.go b/search_test.go index ad8a1ce..1bcf948 100644 --- a/search_test.go +++ b/search_test.go @@ -7,6 +7,13 @@ import ( func TestSearchMaps(t *testing.T) { runMapTests(t, []mapTest{ + { + "a simple query with search after", + Search().SearchAfter("_id", "name"), + map[string]interface{}{ + "search_after": []string{"_id", "name"}, + }, + }, { "a simple match_all query with a size and no aggs", Search().Query(MatchAll()).Size(20), From 11bb2b31eb6a230543733020c8c353935adf5df4 Mon Sep 17 00:00:00 2001 From: k-yomo Date: Tue, 21 Dec 2021 22:00:39 +0900 Subject: [PATCH 2/7] Add support for combined_fields query --- query_combined_fields.go | 86 +++++++++++++++++++++++++++++++++++ query_combined_fields_test.go | 43 ++++++++++++++++++ 2 files changed, 129 insertions(+) create mode 100644 query_combined_fields.go create mode 100644 query_combined_fields_test.go diff --git a/query_combined_fields.go b/query_combined_fields.go new file mode 100644 index 0000000..87b4e2d --- /dev/null +++ b/query_combined_fields.go @@ -0,0 +1,86 @@ +package esquery + +import "github.com/fatih/structs" + +type CombinedFieldsQuery struct { + params combinedFieldsParams +} + +// Map returns a map representation of the query; implementing the +// Mappable interface. +func (q *CombinedFieldsQuery) Map() map[string]interface{} { + return map[string]interface{}{ + "combined_fields": structs.Map(q.params), + } +} + +type combinedFieldsParams struct { + Qry interface{} `structs:"query"` + Fields []string `structs:"fields"` + Boost float32 `structs:"boost,omitempty"` + AutoGenerate *bool `structs:"auto_generate_synonyms_phrase_query,omitempty"` + Op MatchOperator `structs:"operator,string,omitempty"` + MinMatch string `structs:"minimum_should_match,omitempty"` + ZeroTerms ZeroTerms `structs:"zero_terms_query,string,omitempty"` +} + +// CombinedFields creates a new query of type "combined_fields" +func CombinedFields(simpleQuery interface{}) *CombinedFieldsQuery { + return newCombinedFields(simpleQuery) +} + +func newCombinedFields(simpleQuery interface{}) *CombinedFieldsQuery { + return &CombinedFieldsQuery{ + params: combinedFieldsParams{ + Qry: simpleQuery, + }, + } +} + +// Query sets the data to find in the query's field (it is the "query" component +// of the query). +func (q *CombinedFieldsQuery) Query(data interface{}) *CombinedFieldsQuery { + q.params.Qry = data + return q +} + +// Fields sets the fields used in the query +func (q *CombinedFieldsQuery) Fields(a ...string) *CombinedFieldsQuery { + q.params.Fields = append(q.params.Fields, a...) + return q +} + +// AutoGenerateSynonymsPhraseQuery sets the "auto_generate_synonyms_phrase_query" +// boolean. +func (q *CombinedFieldsQuery) AutoGenerateSynonymsPhraseQuery(b bool) *CombinedFieldsQuery { + q.params.AutoGenerate = &b + return q +} + +// Boost +func (q *CombinedFieldsQuery) Boost(l float32) *CombinedFieldsQuery { + q.params.Boost = l + return q +} + +// Operator sets the boolean logic used to interpret text in the query value. +func (q *CombinedFieldsQuery) Operator(op MatchOperator) *CombinedFieldsQuery { + q.params.Op = op + return q +} + +// MinimumShouldMatch sets the minimum number of clauses that must match for a +// document to be returned. +func (q *CombinedFieldsQuery) MinimumShouldMatch(s string) *CombinedFieldsQuery { + q.params.MinMatch = s + return q +} + +// ZeroTermsQuery sets the "zero_terms_query" option to use. This indicates +// whether no documents are returned if the analyzer removes all tokens, such as +// when using a stop filter. +func (q *CombinedFieldsQuery) ZeroTermsQuery(s ZeroTerms) *CombinedFieldsQuery { + q.params.ZeroTerms = s + return q +} + diff --git a/query_combined_fields_test.go b/query_combined_fields_test.go new file mode 100644 index 0000000..d9183c0 --- /dev/null +++ b/query_combined_fields_test.go @@ -0,0 +1,43 @@ +package esquery + +import ( + "testing" +) + +func TestCombinedFields(t *testing.T) { + runMapTests(t, []mapTest{ + { + "simple combined_fields", + CombinedFields("value1").Fields("title"), + map[string]interface{}{ + "combined_fields": map[string]interface{}{ + "fields": []string{"title"}, + "query": "value1", + }, + }, + }, + { + "combined_fields all params", + CombinedFields("original"). + Query("test"). + Fields("title", "body"). + AutoGenerateSynonymsPhraseQuery(true). + Boost(6.4). + Operator(OperatorAnd). + MinimumShouldMatch("3<90%"). + ZeroTermsQuery(ZeroTermsAll), + map[string]interface{}{ + "combined_fields": map[string]interface{}{ + "auto_generate_synonyms_phrase_query": true, + "boost": 6.4, + "minimum_should_match": "3<90%", + "operator": "AND", + "zero_terms_query": "all", + "query": "test", + "fields": []string{"title", "body"}, + }, + }, + }, + }) +} + From 5bad0e6d3eb330f8e7e7263f7e04c19c400f01de Mon Sep 17 00:00:00 2001 From: PesTospertnyj Date: Thu, 6 Jan 2022 22:54:24 +0200 Subject: [PATCH 3/7] boost support added into match statement --- query_match.go | 7 +++++++ query_match_test.go | 12 ++++++++++++ 2 files changed, 19 insertions(+) diff --git a/query_match.go b/query_match.go index f34779b..b0a9608 100644 --- a/query_match.go +++ b/query_match.go @@ -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. @@ -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 diff --git a/query_match_test.go b/query_match_test.go index 238c68d..a7c957c 100644 --- a/query_match_test.go +++ b/query_match_test.go @@ -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), From c2693c64015b47377eece55eeac205137f9e4415 Mon Sep 17 00:00:00 2001 From: Jacky Wu Date: Fri, 21 Jan 2022 14:09:06 +0800 Subject: [PATCH 4/7] feat: add date_histogram agg. --- aggregations_test.go | 25 +++++++- aggs_bucket.go | 141 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 165 insertions(+), 1 deletion(-) diff --git a/aggregations_test.go b/aggregations_test.go index 949123d..4d0238f 100644 --- a/aggregations_test.go +++ b/aggregations_test.go @@ -62,7 +62,14 @@ func TestAggregations(t *testing.T) { "a complex, multi-aggregation, nested", Aggregate( NestedAgg("categories", "categories"). - Aggs(TermsAgg("type", "outdoors")), + Aggs( + TermsAgg("type", "outdoors").Aggs( + DateHistogramAgg("time", "timestamp"). + Fixedinterval("3m").MinDocCount(0).Aggs( + Sum("sumPeople", "people"), + ), + ), + ), FilterAgg("filtered", Term("type", "t-shirt")), ), @@ -77,6 +84,22 @@ func TestAggregations(t *testing.T) { "terms": map[string]interface{}{ "field": "outdoors", }, + "aggs": map[string]interface{}{ + "time": map[string]interface{}{ + "date_histogram": map[string]interface{}{ + "field": "timestamp", + "fixed_interval": "3m", + "min_doc_count": 0, + }, + "aggs": map[string]interface{}{ + "sumPeople": map[string]interface{}{ + "sum": map[string]interface{}{ + "field": "people", + }, + }, + }, + }, + }, }, }, }, diff --git a/aggs_bucket.go b/aggs_bucket.go index 1a45a14..f4bcfbe 100644 --- a/aggs_bucket.go +++ b/aggs_bucket.go @@ -110,3 +110,144 @@ func (agg *TermsAggregation) Map() map[string]interface{} { return outerMap } + +//----------------------------------------------------------------------------// + +// DateHistogramAggregation represents an aggregation of type "date_histogram", as described in +// https://www.elastic.co/guide/en/elasticsearch/reference/current/ +// search-aggregations-bucket-datehistogram-aggregation.html +type DateHistogramAggregation struct { + name string + field string + calendarInterval string + fixedInterval string + format string + offset string + keyed *bool + minDocCount *uint64 + missing string + order map[string]string + + aggs []Aggregation +} + +// DateHistogramAgg creates a new aggregation of type "date_histogram". +func DateHistogramAgg(name, field string) *DateHistogramAggregation { + return &DateHistogramAggregation{ + name: name, + field: field, + } +} + +// Name returns the name of the aggregation. +func (agg *DateHistogramAggregation) Name() string { + return agg.name +} + +// Aggs sets sub-aggregations for the aggregation. +func (agg *DateHistogramAggregation) Aggs(aggs ...Aggregation) *DateHistogramAggregation { + agg.aggs = aggs + return agg +} + +// CalendarInterval sets calendarInterval +func (agg *DateHistogramAggregation) CalendarInterval(interval string) *DateHistogramAggregation { + agg.calendarInterval = interval + return agg +} + +// Fixedinterval sets fixedInterval +func (agg *DateHistogramAggregation) Fixedinterval(interval string) *DateHistogramAggregation { + agg.fixedInterval = interval + return agg +} + +// Format sets format +func (agg *DateHistogramAggregation) Format(format string) *DateHistogramAggregation { + agg.format = format + return agg +} + +// Offset sets offset +func (agg *DateHistogramAggregation) Offset(offset string) *DateHistogramAggregation { + agg.offset = offset + return agg +} + +// Order sets the sort for terms agg +func (agg *DateHistogramAggregation) Order(order map[string]string) *DateHistogramAggregation { + agg.order = order + return agg +} + +// Keyed sets keyed is true or false +func (agg *DateHistogramAggregation) Keyed(keyed bool) *DateHistogramAggregation { + agg.keyed = &keyed + return agg +} + +// Missing sets missing value +func (agg *DateHistogramAggregation) Missing(missing string) *DateHistogramAggregation { + agg.missing = missing + return agg +} + +// MinDocCount sets min doc count +func (agg *DateHistogramAggregation) MinDocCount(minDocCount uint64) *DateHistogramAggregation { + agg.minDocCount = &minDocCount + return agg +} + +// Map returns a map representation of the aggregation, thus implementing the +// Mappable interface. +func (agg *DateHistogramAggregation) Map() map[string]interface{} { + innerMap := map[string]interface{}{ + "field": agg.field, + } + + if agg.calendarInterval != "" { + innerMap["calendar_interval"] = agg.calendarInterval + } + + if agg.fixedInterval != "" { + innerMap["fixed_interval"] = agg.fixedInterval + } + + if agg.format != "" { + innerMap["format"] = agg.format + } + + if agg.offset != "" { + innerMap["offset"] = agg.offset + } + + if agg.missing != "" { + innerMap["missing"] = agg.missing + } + + if agg.minDocCount != nil { + innerMap["min_doc_count"] = agg.minDocCount + } + + if agg.keyed != nil { + innerMap["keyed"] = *agg.keyed + } + + if agg.order != nil { + innerMap["order"] = agg.order + } + + outerMap := map[string]interface{}{ + "date_histogram": innerMap, + } + + if len(agg.aggs) > 0 { + subAggs := make(map[string]map[string]interface{}) + for _, sub := range agg.aggs { + subAggs[sub.Name()] = sub.Map() + } + outerMap["aggs"] = subAggs + } + + return outerMap +} From 2a3074fe893c70d503c6d26ddd4ccff9a759d967 Mon Sep 17 00:00:00 2001 From: Jacky Wu Date: Fri, 21 Jan 2022 14:15:54 +0800 Subject: [PATCH 5/7] doc: add date histogram agg in supported agg function list. --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 7e0eea7..52d6680 100644 --- a/README.md +++ b/README.md @@ -158,6 +158,7 @@ The following aggregations are currently supported: | `"string_stats"` | `StringStats()` | | `"top_hits"` | `TopHits()` | | `"terms"` | `TermsAgg()` | +| `"date_histogram"` | `DateHistogramAgg()` | ### Supported Top Level Options From a8129fde5ae8060f695c39afc58be1469be1dbf7 Mon Sep 17 00:00:00 2001 From: aliheydarabadii Date: Fri, 12 May 2023 18:41:47 +0330 Subject: [PATCH 6/7] add support for geo_distance --- query_term_level.go | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/query_term_level.go b/query_term_level.go index 2604d3e..d2fb7cc 100644 --- a/query_term_level.go +++ b/query_term_level.go @@ -518,3 +518,45 @@ func (q TermsSetQuery) Map() map[string]interface{} { }, } } + +// geoFilterParams represents a query of type "geo_distance", as described in: +// https://www.elastic.co/guide/en/elasticsearch/reference/7.17/query-dsl-geo-distance-query.html +type GeoFilter struct { + params geoFilterParams + filed string +} + +func GeoFilterFunc(distance string, MiddleCentroid []float64, filed string) *GeoFilter { + return &GeoFilter{ + params: geoFilterParams{ + Distance: distance, + MiddleCentroid: MiddleCentroid, + }, + filed: filed, + } +} + +type geoFilterParams struct { + Distance string `structs:"distance,omitempty"` + MiddleCentroid []float64 `structs:"location,omitempty"` +} + +func (g *GeoFilter) Distance(distance string) *GeoFilter { + g.params.Distance = distance + return g +} +func (g *GeoFilter) MiddleCentroid(middleCentroid []float64) *GeoFilter { + g.params.MiddleCentroid = middleCentroid + return g +} + +func (g *GeoFilter) Map() map[string]interface{} { + m := structs.Map(g.params) + m[g.filed] = m["location"] + delete(m, "location") + response := map[string]interface{}{ + "geo_distance": m} + + return response + +} From 37bbc43bbabd5e5f422065a0b3f5449580b84af5 Mon Sep 17 00:00:00 2001 From: Bin <49082129+songzhibin97@users.noreply.github.com> Date: Wed, 12 Jul 2023 10:44:59 +0800 Subject: [PATCH 7/7] Update query_multi_match.go MultiMatchType eq MatchTypeBestFields, field Can be empty --- query_multi_match.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/query_multi_match.go b/query_multi_match.go index 0d5f2a2..3dc6caf 100644 --- a/query_multi_match.go +++ b/query_multi_match.go @@ -18,7 +18,7 @@ func (q *MultiMatchQuery) Map() map[string]interface{} { type multiMatchParams struct { Qry interface{} `structs:"query"` - Fields []string `structs:"fields"` + Fields []string `structs:"fields,omitempty"` Type MultiMatchType `structs:"type,string,omitempty"` TieBrk float32 `structs:"tie_breaker,omitempty"` Boost float32 `structs:"boost,omitempty"`