def annotate(self, *args, **kwargs):
obj = self._clone()<EOL>for arg in args:<EOL><INDENT>if isinstance(arg, Facet):<EOL><INDENT>obj._facets.append(arg)<EOL><DEDENT>elif isinstance(arg, six.string_types):<EOL><INDENT>obj._facets.append(TermFacet(arg.replace("<STR_LIT>", "<STR_LIT:.>")))<EOL><DEDENT>elif isinstance(arg, Agg):<EOL><INDENT>obj._aggs.append(arg)<EOL><DEDENT>elif isinstance(arg, six.string_types):<EOL><INDENT>obj._facets.append(TermFacet(arg.replace("<STR_LIT>", "<STR_LIT:.>")))<EOL><DEDENT>else:<EOL><INDENT>raise NotImplementedError("<STR_LIT>")<EOL><DEDENT><DEDENT>for name, field in kwargs.items():<EOL><INDENT>obj._facets.append(TermFacet(field=field.replace("<STR_LIT>", "<STR_LIT:.>"), name=name.replace("<STR_LIT>", "<STR_LIT:.>")))<EOL>obj._aggs.append(TermsAgg(field=field.replace("<STR_LIT>", "<STR_LIT:.>"), name=name.replace("<STR_LIT>", "<STR_LIT:.>")))<EOL><DEDENT>return obj<EOL>
Return a query set in which the returned objects have been annotated
with data aggregated from related fields.