Is there a nice way to get back _termvectors using DSL?
e.g. to replace this
GET /index/doc_type/ID/_termvectors?fields=text
{
"term_statistics" : true,
"field_statistics" : false,
"positions": false,
"offsets": false,
"payloads":false,
"filter" : {
"min_term_freq" : 2
}
}
Or even better, directly in the search results.
Hi, @eamonnmag!
AFAIK, there's no way to get term vectors back with search results. However, if you have a list of document IDs, you can fetch term vectors for all of those IDs using es.mtermvectors().
This is a case where I bypass elasticsearch-dsl-py and use elasticsearch-py straight.
I hope that helps!
Raj
Hi, exactly as @brainix said - the dsl only covers the most common use cases, for something like this, which I'd consider advanced functionality, please use the underlying elasticsearch-py library.
If you want to integrate this nicely with the DocType class you can create a subclass that adds this API as a method:
from elasticsearch_dsl import DocType
from elasticsearch_dsl.connections import connections
class TermVectorDocType(DocType):
def termvectors(self, *fields, **kwargs):
es = connections.get_connection(self._doc_type.using)
return es.termvectors(
index=self._get_index(),
doc_type=self._doc_type.name,
id=self.meta.id,
fields=fields,
**kwargs
)
Hope this helps
Most helpful comment
Hi, exactly as @brainix said - the
dslonly covers the most common use cases, for something like this, which I'd consider advanced functionality, please use the underlyingelasticsearch-pylibrary.If you want to integrate this nicely with the
DocTypeclass you can create a subclass that adds this API as a method:Hope this helps