search_terms_lookup.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. package elastic
  5. // TermsLookup encapsulates the parameters needed to fetch terms.
  6. //
  7. // For more details, see
  8. // https://www.elastic.co/guide/en/elasticsearch/reference/5.3/query-dsl-terms-query.html#query-dsl-terms-lookup.
  9. type TermsLookup struct {
  10. index string
  11. typ string
  12. id string
  13. path string
  14. routing string
  15. }
  16. // NewTermsLookup creates and initializes a new TermsLookup.
  17. func NewTermsLookup() *TermsLookup {
  18. t := &TermsLookup{}
  19. return t
  20. }
  21. // Index name.
  22. func (t *TermsLookup) Index(index string) *TermsLookup {
  23. t.index = index
  24. return t
  25. }
  26. // Type name.
  27. func (t *TermsLookup) Type(typ string) *TermsLookup {
  28. t.typ = typ
  29. return t
  30. }
  31. // Id to look up.
  32. func (t *TermsLookup) Id(id string) *TermsLookup {
  33. t.id = id
  34. return t
  35. }
  36. // Path to use for lookup.
  37. func (t *TermsLookup) Path(path string) *TermsLookup {
  38. t.path = path
  39. return t
  40. }
  41. // Routing value.
  42. func (t *TermsLookup) Routing(routing string) *TermsLookup {
  43. t.routing = routing
  44. return t
  45. }
  46. // Source creates the JSON source of the builder.
  47. func (t *TermsLookup) Source() (interface{}, error) {
  48. src := make(map[string]interface{})
  49. if t.index != "" {
  50. src["index"] = t.index
  51. }
  52. if t.typ != "" {
  53. src["type"] = t.typ
  54. }
  55. if t.id != "" {
  56. src["id"] = t.id
  57. }
  58. if t.path != "" {
  59. src["path"] = t.path
  60. }
  61. if t.routing != "" {
  62. src["routing"] = t.routing
  63. }
  64. return src, nil
  65. }