-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Decoder
Oliver Eilhard edited this page Feb 26, 2015
·
2 revisions
Elastic enables you to use your own decoder for deserializing JSON data as received from Elasticsearch. Set your own decoder when creating a new client via elastic.SetDecoder(...)
.
Here is an example:
// CountingDecoder needs to implement the elastic.Decoder interface.
type CountingDecoder struct {
dec json.Decoder
N int64
}
func (d *CountingDecoder) Decode(data []byte, v interface{}) error {
atomic.AddInt64(&d.N, 1)
return json.NewDecoder(bytes.NewReader(data)).Decode(v)
}
...
client, err := elastic.NewClient(elastic.SetDecoder(&CountingDecoder{}))