// Source returns serializable JSON of the TermsOrder.
815
func (order *TermsOrder) Source() (interface{}, error) {
	source := make(map[string]string)
	if order.Ascending {
		source[order.Field] = "asc"
	} else {
		source[order.Field] = "desc"
	}
	return source, nil
}
141143
func Source(filename string, src []byte) ([]byte, error) {
	module, err := ast.ParseModule(filename, string(src))
	if err != nil {
		return nil, err
	}
	formatted, err := Ast(module)
	if err != nil {
		return nil, fmt.Errorf("%s: %v", filename, err)
	}
	return formatted, nil
}
126127
func (c *Consumer) Source(
	genLine, genColumn int,
) (source, name string, line, column int, ok bool) {
	for i := range c.sections {
		s := &c.sections[i]
		if s.Offset.Line < genLine ||
			(s.Offset.Line+1 == genLine && s.Offset.Column <= genColumn) {
			genLine -= s.Offset.Line
			genColumn -= s.Offset.Column
			return c.source(s.Map, genLine, genColumn)
		}
	}
	return
}
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
}
1287370
func Source(source rand.Source) ListOption {
	return listOptionFunc(func(options *listOptions) {
		options.source = source
	})
}
401852
func (fsc *FetchSourceContext) Source() (interface{}, error) {
	if !fsc.fetchSource {
		return false, nil
	}
	if len(fsc.includes) == 0 && len(fsc.excludes) == 0 {
		return true, nil
	}
	src := make(map[string]interface{})
	if len(fsc.includes) > 0 {
		src["includes"] = fsc.includes
	}
	if len(fsc.excludes) > 0 {
		src["excludes"] = fsc.excludes
	}
	return src, nil
}
984770
func (q *PercolatorQuery) Source() (interface{}, error) {
	if len(q.field) == 0 {
		return nil, errors.New("elastic: Field is required in PercolatorQuery")
	}

	// {
	//   "percolate" : { ... }
	// }
	source := make(map[string]interface{})
	params := make(map[string]interface{})
	source["percolate"] = params
	params["field"] = q.field
	if q.documentType != "" {
		params["document_type"] = q.documentType
	}
	if q.name != "" {
		params["name"] = q.name
	}

	switch len(q.documents) {
	case 0:
	case 1:
		params["document"] = q.documents[0]
	default:
		params["documents"] = q.documents
	}

	if s := q.indexedDocumentIndex; s != "" {
		params["index"] = s
	}
	if s := q.indexedDocumentType; s != "" {
		params["type"] = s
	}
	if s := q.indexedDocumentId; s != "" {
		params["id"] = s
	}
	if s := q.indexedDocumentRouting; s != "" {
		params["routing"] = s
	}
	if s := q.indexedDocumentPreference; s != "" {
		params["preference"] = s
	}
	if v := q.indexedDocumentVersion; v != nil {
		params["version"] = *v
	}
	return source, nil
}
838292
func (s *MultiTermvectorItem) Source() interface{} {
	source := make(map[string]interface{})

	source["_id"] = s.id

	if s.index != "" {
		source["_index"] = s.index
	}
	if s.typ != "" {
		source["_type"] = s.typ
	}
	if s.fields != nil {
		source["fields"] = s.fields
	}
	if s.fieldStatistics != nil {
		source["field_statistics"] = fmt.Sprintf("%v", *s.fieldStatistics)
	}
	if s.offsets != nil {
		source["offsets"] = s.offsets
	}
	if s.parent != "" {
		source["parent"] = s.parent
	}
	if s.payloads != nil {
		source["payloads"] = fmt.Sprintf("%v", *s.payloads)
	}
	if s.positions != nil {
		source["positions"] = fmt.Sprintf("%v", *s.positions)
	}
	if s.preference != "" {
		source["preference"] = s.preference
	}
	if s.realtime != nil {
		source["realtime"] = fmt.Sprintf("%v", *s.realtime)
	}
	if s.routing != "" {
		source["routing"] = s.routing
	}
	if s.termStatistics != nil {
		source["term_statistics"] = fmt.Sprintf("%v", *s.termStatistics)
	}
	if s.doc != nil {
		source["doc"] = s.doc
	}
	if s.perFieldAnalyzer != nil && len(s.perFieldAnalyzer) > 0 {
		source["per_field_analyzer"] = s.perFieldAnalyzer
	}

	return source
}
43688
func (d DocvalueField) Source() (interface{}, error) {
	if d.Format == "" {
		return d.Field, nil
	}
	return map[string]interface{}{
		"field":  d.Field,
		"format": d.Format,
	}, nil
}
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
}
619144
func (q MoreLikeThisQuery) Source() interface{} {
	// {
	//   "match_all" : { ... }
	// }
	params := make(map[string]interface{})
	source := make(map[string]interface{})
	source["mlt"] = params

	if q.likeText == "" && len(q.docs) == 0 && len(q.ids) == 0 {
		// We have no form of returning errors for invalid queries as of Elastic.
		// We also don't have access to the client here, so we can't log anything.
		// All we can do is to return an empty query, I suppose.
		// TODO Is there a better approach here?
		//return nil, errors.New(`more_like_this requires some documents to be "liked"`)
		return source
	}

	if len(q.fields) > 0 {
		params["fields"] = q.fields
	}
	if q.likeText != "" {
		params["like_text"] = q.likeText
	}
	if q.minimumShouldMatch != "" {
		params["minimum_should_match"] = q.minimumShouldMatch
	}
	if q.minTermFreq != nil {
		params["min_term_freq"] = *q.minTermFreq
	}
	if q.maxQueryTerms != nil {
		params["max_query_terms"] = *q.maxQueryTerms
	}
	if len(q.stopWords) > 0 {
		params["stop_words"] = q.stopWords
	}
	if q.minDocFreq != nil {
		params["min_doc_freq"] = *q.minDocFreq
	}
	if q.maxDocFreq != nil {
		params["max_doc_freq"] = *q.maxDocFreq
	}
	if q.minWordLen != nil {
		params["min_word_len"] = *q.minWordLen
	}
	if q.maxWordLen != nil {
		params["max_word_len"] = *q.maxWordLen
	}
	if q.boostTerms != nil {
		params["boost_terms"] = *q.boostTerms
	}
	if q.boost != nil {
		params["boost"] = *q.boost
	}
	if q.analyzer != "" {
		params["analyzer"] = q.analyzer
	}
	if q.failOnUnsupportedField != nil {
		params["fail_on_unsupported_field"] = *q.failOnUnsupportedField
	}
	if q.queryName != "" {
		params["_name"] = q.queryName
	}
	if len(q.ids) > 0 {
		params["ids"] = q.ids
	}
	if len(q.docs) > 0 {
		docs := make([]interface{}, 0)
		for _, doc := range q.docs {
			docs = append(docs, doc.Source())
		}
		params["docs"] = docs
	}
	if q.include != nil {
		params["exclude"] = !(*q.include) // ES 1.x only has exclude
	}

	return source
}
693366
func (o *FuzzyCompletionSuggesterOptions) Source() (interface{}, error) {
	out := make(map[string]interface{})

	if o.editDistance != nil {
		out["fuzziness"] = o.editDistance
	}
	if o.transpositions != nil {
		out["transpositions"] = *o.transpositions
	}
	if o.minLength != nil {
		out["min_length"] = *o.minLength
	}
	if o.prefixLength != nil {
		out["prefix_length"] = *o.prefixLength
	}
	if o.unicodeAware != nil {
		out["unicode_aware"] = *o.unicodeAware
	}
	if o.maxDeterminizedStates != nil {
		out["max_determinized_states"] = *o.maxDeterminizedStates
	}

	return out, nil
}
367773
func (t *TermsLookup) Source() (interface{}, error) {
	src := make(map[string]interface{})
	if t.index != "" {
		src["index"] = t.index
	}
	if t.typ != "" {
		src["type"] = t.typ
	}
	if t.id != "" {
		src["id"] = t.id
	}
	if t.path != "" {
		src["path"] = t.path
	}
	if t.routing != "" {
		src["routing"] = t.routing
	}
	return src, nil
}
602957
func (q *TermsSetQuery) Source() (interface{}, error) {
	// {"terms_set":{"codes":{"terms":["abc","def"],"minimum_should_match_field":"required_matches"}}}
	source := make(map[string]interface{})
	inner := make(map[string]interface{})
	params := make(map[string]interface{})
	inner[q.name] = params
	source["terms_set"] = inner

	// terms
	params["terms"] = q.values

	// minimum_should_match_field
	if match := q.minimumShouldMatchField; match != "" {
		params["minimum_should_match_field"] = match
	}

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

	// Common parameters for all queries
	if q.boost != nil {
		params["boost"] = *q.boost
	}
	if q.queryName != "" {
		params["_name"] = q.queryName
	}

	return source, 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
}
414492
func (s *IndicesShrinkService) Source(source string) *IndicesShrinkService {
	s.source = source
	return s
}
690972
func (q *TermSuggester) Source(includeName bool) (interface{}, error) {
	// "suggest" : {
	//   "my-suggest-1" : {
	//     "text" : "the amsterdma meetpu",
	//     "term" : {
	//       "field" : "body"
	//     }
	//   },
	//   "my-suggest-2" : {
	//     "text" : "the rottredam meetpu",
	//     "term" : {
	//       "field" : "title",
	//     }
	//   }
	// }
	ts := &termSuggesterRequest{}
	if q.text != "" {
		ts.Text = q.text
	}

	suggester := make(map[string]interface{})
	ts.Term = suggester

	if q.analyzer != "" {
		suggester["analyzer"] = q.analyzer
	}
	if q.field != "" {
		suggester["field"] = q.field
	}
	if q.size != nil {
		suggester["size"] = *q.size
	}
	if q.shardSize != nil {
		suggester["shard_size"] = *q.shardSize
	}
	switch len(q.contextQueries) {
	case 0:
	case 1:
		src, err := q.contextQueries[0].Source()
		if err != nil {
			return nil, err
		}
		suggester["contexts"] = src
	default:
		ctxq := make([]interface{}, len(q.contextQueries))
		for i, query := range q.contextQueries {
			src, err := query.Source()
			if err != nil {
				return nil, err
			}
			ctxq[i] = src
		}
		suggester["contexts"] = ctxq
	}

	// Specific to term suggester
	if q.suggestMode != "" {
		suggester["suggest_mode"] = q.suggestMode
	}
	if q.accuracy != nil {
		suggester["accuracy"] = *q.accuracy
	}
	if q.sort != "" {
		suggester["sort"] = q.sort
	}
	if q.stringDistance != "" {
		suggester["string_distance"] = q.stringDistance
	}
	if q.maxEdits != nil {
		suggester["max_edits"] = *q.maxEdits
	}
	if q.maxInspections != nil {
		suggester["max_inspections"] = *q.maxInspections
	}
	if q.maxTermFreq != nil {
		suggester["max_term_freq"] = *q.maxTermFreq
	}
	if q.prefixLength != nil {
		suggester["prefix_length"] = *q.prefixLength
	}
	if q.minWordLength != nil {
		suggester["min_word_len"] = *q.minWordLength
	}
	if q.minDocFreq != nil {
		suggester["min_doc_freq"] = *q.minDocFreq
	}

	if !includeName {
		return ts, nil
	}

	source := make(map[string]interface{})
	source[q.name] = ts
	return source, nil
}