Elasticsearch-dsl-py: Any way to use the Explain API with this library?

Created on 12 Oct 2020  路  2Comments  路  Source: elastic/elasticsearch-dsl-py

It it possible to use the Explain API (https://www.elastic.co/guide/en/elasticsearch/reference/current/search-explain.html) and if not what would be the best way to use an existing query defined with this library for an explain call?
Any pointers in the right direction, would be greatly appreciated!

Most helpful comment

Thanks for answering the question @brainix. My only recommendation to add to your answer is to use keyword arguments within es.explain():

explanation = es.explain(index=my_index_name, id=some_doc_id, body=s.to_dict())

All 2 comments

I use .explain() provided by the lower level elasticsearch-py library, which this higher level elasticsearch-dsl-py builds upon.

Assuming that you have an elasticsearch-py client called es and an elasticseach-dsl-py query called s, you can get the query explanation like so:

explanation = es.explain(my_index_name, some_doc_id, body=s.to_dict())

This explanation tells you why your document ID some_doc_id matches (or doesn't match) your query s.

Hope that helps! 馃槃

Thanks for answering the question @brainix. My only recommendation to add to your answer is to use keyword arguments within es.explain():

explanation = es.explain(index=my_index_name, id=some_doc_id, body=s.to_dict())
Was this page helpful?
0 / 5 - 0 ratings

Related issues

quasiben picture quasiben  路  4Comments

leoliuxd picture leoliuxd  路  4Comments

ypkkhatri picture ypkkhatri  路  4Comments

beanaroo picture beanaroo  路  4Comments

njoannin picture njoannin  路  3Comments