MCPcopy Create free account
hub / github.com/olivere/elastic / Source

Method Source

script.go:86–108  ·  view source on GitHub ↗

Source returns the JSON serializable data for this Script.

()

Source from the content-addressed store, hash-verified

84
85// Source returns the JSON serializable data for this Script.
86func (s *Script) Source() (interface{}, error) {
87 if s.typ == "" && s.lang == "" && len(s.params) == 0 {
88 return s.script, nil
89 }
90 source := make(map[string]interface{})
91 // Beginning with 6.0, the type can only be "source" or "id"
92 if s.typ == "" || s.typ == "inline" {
93 src, err := s.rawScriptSource(s.script)
94 if err != nil {
95 return nil, err
96 }
97 source["source"] = src
98 } else {
99 source["id"] = s.script
100 }
101 if s.lang != "" {
102 source["lang"] = s.lang
103 }
104 if len(s.params) > 0 {
105 source["params"] = s.params
106 }
107 return source, nil
108}
109
110// rawScriptSource returns an embeddable script. If it uses a short
111// script form, e.g. "ctx._source.likes++" (without the quotes), it

Callers 1

TestScriptingDefaultFunction · 0.95

Calls 1

rawScriptSourceMethod · 0.95

Tested by 1

TestScriptingDefaultFunction · 0.76