rawScriptSource returns an embeddable script. If it uses a short script form, e.g. "ctx._source.likes++" (without the quotes), it is quoted. Otherwise it returns the raw script that will be directly embedded into the JSON data.
(script string)
| 112 | // is quoted. Otherwise it returns the raw script that will be directly |
| 113 | // embedded into the JSON data. |
| 114 | func (s *Script) rawScriptSource(script string) (interface{}, error) { |
| 115 | v := strings.TrimSpace(script) |
| 116 | if !strings.HasPrefix(v, "{") && !strings.HasPrefix(v, `"`) { |
| 117 | v = fmt.Sprintf("%q", v) |
| 118 | } |
| 119 | raw := json.RawMessage(v) |
| 120 | return &raw, nil |
| 121 | } |
| 122 | |
| 123 | // -- Script Field -- |
| 124 |