def serialize(self):
res = {}<EOL>if self.query:<EOL><INDENT>if isinstance(self.query, dict):<EOL><INDENT>res["<STR_LIT>"] = self.query<EOL><DEDENT>elif isinstance(self.query, Query):<EOL><INDENT>res["<STR_LIT>"] = self.query.serialize()<EOL><DEDENT>else:<EOL><INDENT>raise InvalidQuery("<STR_LIT>")<EOL><DEDENT><DEDENT>if self.filter:<EOL><INDENT>res['<STR_LIT>'] = self.filter.serialize()<EOL><DEDENT>if self.facet.facets:<EOL><INDENT>res['<STR_LIT>'] = self.facet.serialize()<EOL><DEDENT>if self.agg.aggs:<EOL><INDENT>res['<STR_LIT>'] = self.agg.serialize()<EOL><DEDENT>if self.rescore:<EOL><INDENT>res['<STR_LIT>'] = self.rescore.serialize()<EOL><DEDENT>if self.window_size:<EOL><INDENT>res['<STR_LIT>'] = self.window_size<EOL><DEDENT>if self.fields is not None: <EOL><INDENT>res['<STR_LIT>'] = self.fields<EOL><DEDENT>if self.size is not None:<EOL><INDENT>res['<STR_LIT:size>'] = self.size<EOL><DEDENT>if self.start is not None:<EOL><INDENT>res['<STR_LIT>'] = self.start<EOL><DEDENT>if self._highlight:<EOL><INDENT>res['<STR_LIT>'] = self._highlight.serialize()<EOL><DEDENT>if self.sort:<EOL><INDENT>if isinstance(self.sort, SortFactory):<EOL><INDENT>sort = self.sort.serialize()<EOL>if sort:<EOL><INDENT>res['<STR_LIT>'] = sort<EOL><DEDENT><DEDENT>else:<EOL><INDENT>res['<STR_LIT>'] = self.sort<EOL><DEDENT><DEDENT>if self.explain:<EOL><INDENT>res['<STR_LIT>'] = self.explain<EOL><DEDENT>if self.version:<EOL><INDENT>res['<STR_LIT:version>'] = self.version<EOL><DEDENT>if self.track_scores:<EOL><INDENT>res['<STR_LIT>'] = self.track_scores<EOL><DEDENT>if self._script_fields:<EOL><INDENT>if isinstance(self.script_fields, ScriptFields):<EOL><INDENT>res['<STR_LIT>'] = self.script_fields.serialize()<EOL><DEDENT>elif isinstance(self.script_fields, dict):<EOL><INDENT>res['<STR_LIT>'] = self.script_fields<EOL><DEDENT>else:<EOL><INDENT>raise ScriptFieldsError("<STR_LIT>")<EOL><DEDENT><DEDENT>if self.index_boost:<EOL><INDENT>res['<STR_LIT>'] = self.index_boost<EOL><DEDENT>if self.min_score:<EOL><INDENT>res['<STR_LIT>'] = self.min_score<EOL><DEDENT>if self.stats:<EOL><INDENT>res['<STR_LIT>'] = self.stats<EOL><DEDENT>if self.partial_fields:<EOL><INDENT>res['<STR_LIT>'] = self.partial_fields<EOL><DEDENT>if self._source:<EOL><INDENT>res['<STR_LIT>'] = self._source<EOL><DEDENT>if self.timeout:<EOL><INDENT>res['<STR_LIT>'] = self.timeout<EOL><DEDENT>return res<EOL>
Serialize the search to a structure as passed for a search body.