| 1 |
// Copyright 2012-present Oliver Eilhard. All rights reserved. |
| 2 |
// Use of this source code is governed by a MIT-license. |
| 3 |
// See http://olivere.mit-license.org/license.txt for details. |
| 4 |
|
| 5 |
package elastic |
| 6 |
|
| 7 |
// TermsLookup encapsulates the parameters needed to fetch terms. |
| 8 |
// |
| 9 |
// For more details, see |
| 10 |
// https://www.elastic.co/guide/en/elasticsearch/reference/5.3/query-dsl-terms-query.html#query-dsl-terms-lookup. |
| 11 |
type TermsLookup struct { |
| 12 |
index string |
| 13 |
typ string |
| 14 |
id string |
| 15 |
path string |
| 16 |
routing string |
| 17 |
} |
| 18 |
|
| 19 |
// NewTermsLookup creates and initializes a new TermsLookup. |
| 20 |
func NewTermsLookup() *TermsLookup { |
| 21 |
t := &TermsLookup{} |
| 22 |
return t |
| 23 |
} |
| 24 |
|
| 25 |
// Index name. |
| 26 |
func (t *TermsLookup) Index(index string) *TermsLookup { |
| 27 |
t.index = index |
| 28 |
return t |
| 29 |
} |
| 30 |
|
| 31 |
// Type name. |
| 32 |
func (t *TermsLookup) Type(typ string) *TermsLookup { |
| 33 |
t.typ = typ |
| 34 |
return t |
| 35 |
} |
| 36 |
|
| 37 |
// Id to look up. |
| 38 |
func (t *TermsLookup) Id(id string) *TermsLookup { |
| 39 |
t.id = id |
| 40 |
return t |
| 41 |
} |
| 42 |
|
| 43 |
// Path to use for lookup. |
| 44 |
func (t *TermsLookup) Path(path string) *TermsLookup { |
| 45 |
t.path = path |
| 46 |
return t |
| 47 |
} |
| 48 |
|
| 49 |
// Routing value. |
| 50 |
func (t *TermsLookup) Routing(routing string) *TermsLookup { |
| 51 |
t.routing = routing |
| 52 |
return t |
| 53 |
} |
| 54 |
|
| 55 |
// Source creates the JSON source of the builder. |
| 56 |
func (t *TermsLookup) Source() (interface{}, error) { |
| 57 |
src := make(map[string]interface{}) |
| 58 |
if t.index != "" { |
| 59 |
src["index"] = t.index |
| 60 |
} |
| 61 |
if t.typ != "" { |
| 62 |
src["type"] = t.typ |
| 63 |
} |
| 64 |
if t.id != "" { |
| 65 |
src["id"] = t.id |
| 66 |
} |
| 67 |
if t.path != "" { |
| 68 |
src["path"] = t.path |
| 69 |
} |
| 70 |
if t.routing != "" { |
| 71 |
src["routing"] = t.routing |
| 72 |
} |
| 73 |
return src, nil |
| 74 |
} |