func (s *ScriptSort) Source() (interface{}, error) {
	if s.script == nil {
		return nil, errors.New("ScriptSort expected a script")
	}
	source := make(map[string]interface{})
	x := make(map[string]interface{})
	source["_script"] = x
	src, err := s.script.Source()
	if err != nil {
		return nil, err
	}
	x["script"] = src
	x["type"] = s.typ
	if s.ascending {
		x["order"] = "asc"
	} else {
		x["order"] = "desc"
	}
	if s.sortMode != nil {
		x["mode"] = *s.sortMode
	}
	if s.nestedFilter != nil {
		src, err := s.nestedFilter.Source()
		if err != nil {
			return nil, err
		}
		x["nested_filter"] = src
	}
	if s.nestedPath != nil {
		x["nested_path"] = *s.nestedPath
	}
	return source, nil
}
Source returns the JSON-serializable data.
package elastic
import "errors"
type Sorter interface {
	Source() (interface{}, error)
}
type SortInfo struct {
	Sorter
	Field          string
	Ascending      bool
	Missing        interface{}
	IgnoreUnmapped *bool
	UnmappedType   string
	SortMode       string
	NestedFilter   Query
	NestedPath     string
}
func (info SortInfo) Source() (interface{}, error) {
	prop := make(map[string]interface{})
	if info.Ascending {
		prop["order"] = "asc"
	} else {
		prop["order"] = "desc"
	}
	if info.Missing != nil {
		prop["missing"] = info.Missing
	}
	if info.IgnoreUnmapped != nil {
		prop["ignore_unmapped"] = *info.IgnoreUnmapped
	}
	if info.UnmappedType != "" {
		prop["unmapped_type"] = info.UnmappedType
	}
	if info.SortMode != "" {
		prop["mode"] = info.SortMode
	}
	if info.NestedFilter != nil {
		src, err := info.NestedFilter.Source()
		if err != nil {
			return nil, err
		}
		prop["nested_filter"] = src
	}
	if info.NestedPath != "" {
		prop["nested_path"] = info.NestedPath
	}
	source := make(map[string]interface{})
	source[info.Field] = prop
	return source, nil
}
type SortByDoc struct {
	Sorter
}
func (s SortByDoc) Source() (interface{}, error) {
	return "_doc", nil
}
type ScoreSort struct {
	Sorter
	ascending bool
}
func NewScoreSort() *ScoreSort {
	return &ScoreSort{ascending: false}  
}
func (s *ScoreSort) Order(ascending bool) *ScoreSort {
	s.ascending = ascending
	return s
}
func (s *ScoreSort) Asc() *ScoreSort {
	s.ascending = true
	return s
}
func (s *ScoreSort) Desc() *ScoreSort {
	s.ascending = false
	return s
}
func (s *ScoreSort) Source() (interface{}, error) {
	source := make(map[string]interface{})
	x := make(map[string]interface{})
	source["_score"] = x
	if s.ascending {
		x["order"] = "asc"
	} else {
		x["order"] = "desc"
	}
	return source, nil
}
type FieldSort struct {
	Sorter
	fieldName    string
	ascending    bool
	missing      interface{}
	unmappedType *string
	sortMode     *string
	nestedFilter Query
	nestedPath   *string
}
func NewFieldSort(fieldName string) *FieldSort {
	return &FieldSort{
		fieldName: fieldName,
		ascending: true,
	}
}
func (s *FieldSort) FieldName(fieldName string) *FieldSort {
	s.fieldName = fieldName
	return s
}
func (s *FieldSort) Order(ascending bool) *FieldSort {
	s.ascending = ascending
	return s
}
func (s *FieldSort) Asc() *FieldSort {
	s.ascending = true
	return s
}
func (s *FieldSort) Desc() *FieldSort {
	s.ascending = false
	return s
}
func (s *FieldSort) Missing(missing interface{}) *FieldSort {
	s.missing = missing
	return s
}
func (s *FieldSort) UnmappedType(typ string) *FieldSort {
	s.unmappedType = &typ
	return s
}
func (s *FieldSort) SortMode(sortMode string) *FieldSort {
	s.sortMode = &sortMode
	return s
}
func (s *FieldSort) NestedFilter(nestedFilter Query) *FieldSort {
	s.nestedFilter = nestedFilter
	return s
}
func (s *FieldSort) NestedPath(nestedPath string) *FieldSort {
	s.nestedPath = &nestedPath
	return s
}
func (s *FieldSort) Source() (interface{}, error) {
	source := make(map[string]interface{})
	x := make(map[string]interface{})
	source[s.fieldName] = x
	if s.ascending {
		x["order"] = "asc"
	} else {
		x["order"] = "desc"
	}
	if s.missing != nil {
		x["missing"] = s.missing
	}
	if s.unmappedType != nil {
		x["unmapped_type"] = *s.unmappedType
	}
	if s.sortMode != nil {
		x["mode"] = *s.sortMode
	}
	if s.nestedFilter != nil {
		src, err := s.nestedFilter.Source()
		if err != nil {
			return nil, err
		}
		x["nested_filter"] = src
	}
	if s.nestedPath != nil {
		x["nested_path"] = *s.nestedPath
	}
	return source, nil
}
type GeoDistanceSort struct {
	Sorter
	fieldName    string
	points       []*GeoPoint
	geohashes    []string
	distanceType *string
	unit         string
	ascending    bool
	sortMode     *string
	nestedFilter Query
	nestedPath   *string
}
func NewGeoDistanceSort(fieldName string) *GeoDistanceSort {
	return &GeoDistanceSort{
		fieldName: fieldName,
		ascending: true,
	}
}
func (s *GeoDistanceSort) FieldName(fieldName string) *GeoDistanceSort {
	s.fieldName = fieldName
	return s
}
func (s *GeoDistanceSort) Order(ascending bool) *GeoDistanceSort {
	s.ascending = ascending
	return s
}
func (s *GeoDistanceSort) Asc() *GeoDistanceSort {
	s.ascending = true
	return s
}
func (s *GeoDistanceSort) Desc() *GeoDistanceSort {
	s.ascending = false
	return s
}
func (s *GeoDistanceSort) Point(lat, lon float64) *GeoDistanceSort {
	s.points = append(s.points, GeoPointFromLatLon(lat, lon))
	return s
}
func (s *GeoDistanceSort) Points(points ...*GeoPoint) *GeoDistanceSort {
	s.points = append(s.points, points...)
	return s
}
func (s *GeoDistanceSort) GeoHashes(geohashes ...string) *GeoDistanceSort {
	s.geohashes = append(s.geohashes, geohashes...)
	return s
}
func (s *GeoDistanceSort) Unit(unit string) *GeoDistanceSort {
	s.unit = unit
	return s
}
func (s *GeoDistanceSort) GeoDistance(geoDistance string) *GeoDistanceSort {
	return s.DistanceType(geoDistance)
}
func (s *GeoDistanceSort) DistanceType(distanceType string) *GeoDistanceSort {
	s.distanceType = &distanceType
	return s
}
func (s *GeoDistanceSort) SortMode(sortMode string) *GeoDistanceSort {
	s.sortMode = &sortMode
	return s
}
func (s *GeoDistanceSort) NestedFilter(nestedFilter Query) *GeoDistanceSort {
	s.nestedFilter = nestedFilter
	return s
}
func (s *GeoDistanceSort) NestedPath(nestedPath string) *GeoDistanceSort {
	s.nestedPath = &nestedPath
	return s
}
func (s *GeoDistanceSort) Source() (interface{}, error) {
	source := make(map[string]interface{})
	x := make(map[string]interface{})
	source["_geo_distance"] = x
	var ptarr []interface{}
	for _, pt := range s.points {
		ptarr = append(ptarr, pt.Source())
	}
	for _, geohash := range s.geohashes {
		ptarr = append(ptarr, geohash)
	}
	x[s.fieldName] = ptarr
	if s.unit != "" {
		x["unit"] = s.unit
	}
	if s.distanceType != nil {
		x["distance_type"] = *s.distanceType
	}
	if s.ascending {
		x["order"] = "asc"
	} else {
		x["order"] = "desc"
	}
	if s.sortMode != nil {
		x["mode"] = *s.sortMode
	}
	if s.nestedFilter != nil {
		src, err := s.nestedFilter.Source()
		if err != nil {
			return nil, err
		}
		x["nested_filter"] = src
	}
	if s.nestedPath != nil {
		x["nested_path"] = *s.nestedPath
	}
	return source, nil
}
type ScriptSort struct {
	Sorter
	script       *Script
	typ          string
	ascending    bool
	sortMode     *string
	nestedFilter Query
	nestedPath   *string
}
func NewScriptSort(script *Script, typ string) *ScriptSort {
	return &ScriptSort{
		script:    script,
		typ:       typ,
		ascending: true,
	}
}
func (s *ScriptSort) Type(typ string) *ScriptSort {
	s.typ = typ
	return s
}
func (s *ScriptSort) Order(ascending bool) *ScriptSort {
	s.ascending = ascending
	return s
}
func (s *ScriptSort) Asc() *ScriptSort {
	s.ascending = true
	return s
}
func (s *ScriptSort) Desc() *ScriptSort {
	s.ascending = false
	return s
}
func (s *ScriptSort) SortMode(sortMode string) *ScriptSort {
	s.sortMode = &sortMode
	return s
}
func (s *ScriptSort) NestedFilter(nestedFilter Query) *ScriptSort {
	s.nestedFilter = nestedFilter
	return s
}
func (s *ScriptSort) NestedPath(nestedPath string) *ScriptSort {
	s.nestedPath = &nestedPath
	return s
}