// Source is the URL-encoded query definition (instead of using the request body).
344063
func (s *ExplainService) Source(source string) *ExplainService {
	s.source = source
	return s
}
21678
func (fn *RandomFunction) Source() (interface{}, error) {
	source := make(map[string]interface{})
	if fn.field != "" {
		source["field"] = fn.field
	}
	if fn.seed != nil {
		source["seed"] = fn.seed
	}
	// Notice that the weight has to be serialized in FunctionScoreQuery.
	return source, nil
}
1284027
func (q CommonQuery) Source() interface{} {
	//  {
	//    "common": {
	//      "body": {
	//        "query":            "this is bonsai cool",
	//        "cutoff_frequency": 0.001
	//      }
	//    }
	//  }
	source := make(map[string]interface{})
	body := make(map[string]interface{})
	query := make(map[string]interface{})

	source["common"] = body
	body[q.name] = query
	query["query"] = q.query

	if q.cutoffFreq != nil {
		query["cutoff_frequency"] = *(q.cutoffFreq)
	}

	if q.highFreq != nil {
		query["high_freq"] = *(q.highFreq)
	}
	if q.highFreqOp != "" {
		query["high_freq_operator"] = q.highFreqOp
	}

	if q.lowFreq != nil {
		query["low_freq"] = *(q.lowFreq)
	}
	if q.lowFreqOp != "" {
		query["low_freq_operator"] = q.lowFreqOp
	}

	if q.lowFreqMinMatch != nil || q.highFreqMinMatch != nil {
		mm := make(map[string]interface{})
		if q.lowFreqMinMatch != nil {
			mm["low_freq"] = q.lowFreqMinMatch
		}
		if q.highFreqMinMatch != nil {
			mm["high_freq"] = q.highFreqMinMatch
		}
		query["minimum_should_match"] = mm
	}

	if q.analyzer != "" {
		query["analyzer"] = q.analyzer
	}

	if q.disableCoords != nil {
		query["disable_coords"] = *(q.disableCoords)
	}

	if q.boost != nil {
		query["boost"] = *(q.boost)
	}

	return source
}
478360
func (q CustomFiltersScoreQuery) Source() interface{} {
	// {
	//   "custom_filters_score" : {
	//    "query" : {
	//      "match_all" : {}
	//    },
	//    "filters" : [
	//      {
	//        "filter" : { "range" : { "age" : {"from" : 0, "to" : 10} } },
	//        "boost" : "3"
	//      },
	//      {
	//        "filter" : { "range" : { "age" : {"from" : 10, "to" : 20} } },
	//        "boost" : "2"
	//      }
	//     ],
	//     "score_mode" : "first"
	//   }
	// }

	query := make(map[string]interface{})

	cfs := make(map[string]interface{})
	query["custom_filters_score"] = cfs

	// query
	if q.query != nil {
		cfs["query"] = q.query.Source()
	}
	// filters
	clauses := make([]interface{}, 0)
	for _, filter := range q.filters {
		clauses = append(clauses, filter.Source())
	}
	cfs["filters"] = clauses

	// scoreMode
	if q.scoreMode != "" {
		cfs["score_mode"] = q.scoreMode
	}

	// max_boost
	if q.maxBoost != nil {
		cfs["max_boost"] = *q.maxBoost
	}

	// script
	if q.script != "" {
		cfs["script"] = q.script
	}

	return query
}
489489
func (s *SliceQuery) Source() (interface{}, error) {
	m := make(map[string]interface{})
	if s.field != "" {
		m["field"] = s.field
	}
	if s.id != nil {
		m["id"] = *s.id
	}
	if s.max != nil {
		m["max"] = *s.max
	}
	return m, nil
}
442867
func (a *AliasAddAction) Source() (interface{}, error) {
	a.removeBlankIndexNames()
	if err := a.Validate(); err != nil {
		return nil, err
	}
	src := make(map[string]interface{})
	act := make(map[string]interface{})
	src["add"] = act
	act["alias"] = a.alias
	switch len(a.index) {
	case 1:
		act["index"] = a.index[0]
	default:
		act["indices"] = a.index
	}
	if a.filter != nil {
		f, err := a.filter.Source()
		if err != nil {
			return nil, err
		}
		act["filter"] = f
	}
	if len(a.routing) > 0 {
		act["routing"] = a.routing
	}
	if len(a.indexRouting) > 0 {
		act["index_routing"] = a.indexRouting
	}
	if len(a.searchRouting) > 0 {
		act["search_routing"] = a.searchRouting
	}
	if a.isWriteIndex != nil {
		act["is_write_index"] = *a.isWriteIndex
	}
	return src, nil
}
577907
func (item *MoreLikeThisQueryItem) Source() (interface{}, error) {
	if item.likeText != "" {
		return item.likeText, nil
	}

	source := make(map[string]interface{})

	if item.index != "" {
		source["_index"] = item.index
	}
	if item.typ != "" {
		source["_type"] = item.typ
	}
	if item.id != "" {
		source["_id"] = item.id
	}
	if item.doc != nil {
		source["doc"] = item.doc
	}
	if len(item.fields) > 0 {
		source["fields"] = item.fields
	}
	if item.routing != "" {
		source["_routing"] = item.routing
	}
	if item.fsc != nil {
		src, err := item.fsc.Source()
		if err != nil {
			return nil, err
		}
		source["_source"] = src
	}
	if item.version >= 0 {
		source["_version"] = item.version
	}
	if item.versionType != "" {
		source["_version_type"] = item.versionType
	}

	return source, nil
}
95689
func (e *configErr) Source() string {
	return fmt.Sprintf("%s:%d:%d", e.token.SourceFile(), e.token.Line(), e.token.Position())
}
983425
func (q *SimpleQueryStringQuery) Source() (interface{}, error) {
	// {
	//    "simple_query_string" : {
	//      "query" : "\"fried eggs\" +(eggplant | potato) -frittata",
	//			"analyzer" : "snowball",
	//      "fields" : ["body^5","_all"],
	//      "default_operator" : "and"
	//    }
	// }

	source := make(map[string]interface{})

	query := make(map[string]interface{})
	source["simple_query_string"] = query

	query["query"] = q.queryText

	if len(q.fields) > 0 {
		var fields []string
		for _, field := range q.fields {
			if boost, found := q.fieldBoosts[field]; found {
				if boost != nil {
					fields = append(fields, fmt.Sprintf("%s^%f", field, *boost))
				} else {
					fields = append(fields, field)
				}
			} else {
				fields = append(fields, field)
			}
		}
		query["fields"] = fields
	}

	if q.flags != "" {
		query["flags"] = q.flags
	}
	if q.analyzer != "" {
		query["analyzer"] = q.analyzer
	}
	if q.defaultOperator != "" {
		query["default_operator"] = strings.ToLower(q.defaultOperator)
	}
	if q.lowercaseExpandedTerms != nil {
		query["lowercase_expanded_terms"] = *q.lowercaseExpandedTerms
	}
	if q.lenient != nil {
		query["lenient"] = *q.lenient
	}
	if q.analyzeWildcard != nil {
		query["analyze_wildcard"] = *q.analyzeWildcard
	}
	if q.locale != "" {
		query["locale"] = q.locale
	}
	if q.queryName != "" {
		query["_name"] = q.queryName
	}
	if q.minimumShouldMatch != "" {
		query["minimum_should_match"] = q.minimumShouldMatch
	}
	if q.quoteFieldSuffix != "" {
		query["quote_field_suffix"] = q.quoteFieldSuffix
	}
	if q.boost != nil {
		query["boost"] = *q.boost
	}
	if v := q.autoGenerateSynonymsPhraseQuery; v != nil {
		query["auto_generate_synonyms_phrase_query"] = *v
	}
	if v := q.fuzzyPrefixLength; v != -1 {
		query["fuzzy_prefix_length"] = v
	}
	if v := q.fuzzyMaxExpansions; v != -1 {
		query["fuzzy_max_expansions"] = v
	}
	if v := q.fuzzyTranspositions; v != nil {
		query["fuzzy_transpositions"] = *v
	}

	return source, nil
}
326399
func (item *MultiGetItem) Source() interface{} {
	source := make(map[string]interface{})

	source["_id"] = item.id

	if item.index != "" {
		source["_index"] = item.index
	}
	if item.typ != "" {
		source["_type"] = item.typ
	}
	if item.fsc != nil {
		source["_source"] = item.fsc.Source()
	}
	if item.fields != nil {
		source["fields"] = item.fields
	}
	if item.routing != "" {
		source["_routing"] = item.routing
	}
	if item.version != nil {
		source["version"] = fmt.Sprintf("%d", *item.version)
	}
	if item.versionType != "" {
		source["version_type"] = item.versionType
	}

	return source
}
138874
func (q *ConstantScoreQuery) Source() (interface{}, error) {
	// "constant_score" : {
	//     "filter" : {
	//         ....
	//     },
	//     "boost" : 1.5
	// }

	query := make(map[string]interface{})

	params := make(map[string]interface{})
	query["constant_score"] = params

	// filter
	src, err := q.filter.Source()
	if err != nil {
		return nil, err
	}
	params["filter"] = src

	// boost
	if q.boost != nil {
		params["boost"] = *q.boost
	}

	return query, nil
}
620970
func (q *TermQuery) Source() (interface{}, error) {
	// {"term":{"name":"value"}}
	source := make(map[string]interface{})
	tq := make(map[string]interface{})
	source["term"] = tq

	if q.boost == nil && q.queryName == "" {
		tq[q.name] = q.value
	} else {
		subQ := make(map[string]interface{})
		subQ["value"] = q.value
		if q.boost != nil {
			subQ["boost"] = *q.boost
		}
		if q.queryName != "" {
			subQ["_name"] = q.queryName
		}
		tq[q.name] = subQ
	}
	return source, nil
}
1287370
func Source(source rand.Source) ListOption {
	return listOptionFunc(func(options *listOptions) {
		options.source = source
	})
}
903494
func (q *NestedQuery) Source() (interface{}, error) {
	query := make(map[string]interface{})
	nq := make(map[string]interface{})
	query["nested"] = nq

	src, err := q.query.Source()
	if err != nil {
		return nil, err
	}
	nq["query"] = src

	nq["path"] = q.path

	if q.scoreMode != "" {
		nq["score_mode"] = q.scoreMode
	}
	if q.boost != nil {
		nq["boost"] = *q.boost
	}
	if q.queryName != "" {
		nq["_name"] = q.queryName
	}
	if q.ignoreUnmapped != nil {
		nq["ignore_unmapped"] = *q.ignoreUnmapped
	}
	if q.innerHit != nil {
		src, err := q.innerHit.Source()
		if err != nil {
			return nil, err
		}
		nq["inner_hits"] = src
	}
	return query, nil
}
1080456
func (q *GeoPolygonQuery) Source() (interface{}, error) {
	// "geo_polygon" : {
	//  	"person.location" : {
	//         "points" : [
	//             {"lat" : 40, "lon" : -70},
	//             {"lat" : 30, "lon" : -80},
	//             {"lat" : 20, "lon" : -90}
	//         ]
	//     }
	// }
	source := make(map[string]interface{})

	params := make(map[string]interface{})
	source["geo_polygon"] = params

	polygon := make(map[string]interface{})
	params[q.name] = polygon

	var points []interface{}
	for _, point := range q.points {
		points = append(points, point.Source())
	}
	polygon["points"] = points

	if q.queryName != "" {
		params["_name"] = q.queryName
	}

	return source, nil
}
574687
func (s *Script) Source() (interface{}, error) {
	if s.typ == "" && s.lang == "" && len(s.params) == 0 {
		return s.script, nil
	}
	source := make(map[string]interface{})
	// Beginning with 6.0, the type can only be "source" or "id"
	if s.typ == "" || s.typ == "inline" {
		src, err := s.rawScriptSource(s.script)
		if err != nil {
			return nil, err
		}
		source["source"] = src
	} else {
		source["id"] = s.script
	}
	if s.lang != "" {
		source["lang"] = s.lang
	}
	if len(s.params) > 0 {
		source["params"] = s.params
	}
	return source, nil
}
60938
func (q *RangeQuery) Source() (interface{}, error) {
	source := make(map[string]interface{})

	rangeQ := make(map[string]interface{})
	source["range"] = rangeQ

	params := make(map[string]interface{})
	rangeQ[q.name] = params

	params["from"] = q.from
	params["to"] = q.to
	if q.timeZone != "" {
		params["time_zone"] = q.timeZone
	}
	if q.format != "" {
		params["format"] = q.format
	}
	if q.relation != "" {
		params["relation"] = q.relation
	}
	if q.boost != nil {
		params["boost"] = *q.boost
	}
	params["include_lower"] = q.includeLower
	params["include_upper"] = q.includeUpper

	if q.queryName != "" {
		rangeQ["_name"] = q.queryName
	}

	return source, nil
}