Is there anyway to print the final Query sent to Elasticsearch?
Thank you.
You can always ask the Search object for it's raw representation by calling the .to_dict() method. If you want to log what's going on I'd recommend that you enable logging for the elasticsearch-py library (0) by using the standard logging module. You can either choose the elasticsearch logger which logs exactly what's going on (set the log level to INFO to see all requests) or elasticsearch.trace for a more friendly representation where all calls to elasticsearch will be logged as curl commands against localhost:9200 with pretty printed json.
0 - http://elasticsearch-py.readthedocs.io/en/master/#logging
Thank you, that's very helpful.
While waiting for your answer, I hacked the following which helped to understand how the Facetted DSL query is formed:
pp = pprint.PrettyPrinter(indent=4)
logger.debug(pp.pformat(s.build_search().to_dict()))
For reference, this StackOverflow post shows how you can turn on logs dynamically.
PUT /_settings
{
"index": {
"search.slowlog.level": "trace",
"search.slowlog.threshold.query.trace": "1ms"
}
}
TL;DR you just have to set up Python logging before running the query.
Then you will find the full query in JSON in your log file.
import logging
logging.basicConfig(filename='myfile.log', level=logging.DEBUG)
# ...
res = es.search(index="my_index", body={ #...
Most helpful comment
Thank you, that's very helpful.
While waiting for your answer, I hacked the following which helped to understand how the Facetted DSL query is formed: