panic with "thread 'main' panicked at 'not currently running on the Tokio runtime

It looks like Elasticsearch's crate is using Tokio internally, so you must use it too to match their assumptions.

Looking for block_on function in their documentation, I've got this. So, it appears that your main should look like this:

use tokio::runtime::Runtime;

fn main() {
    Runtime::new()
        .expect("Failed to create Tokio runtime")
        .block_on(elastic_search_example());
}

Or you can make you main function itself async with the attribute macro, which will generate runtime creation and block_on call for you:

#[tokio::main]
async fn main() {
    elastic_search_example().await;
}

I had the same error when I used to tokio::run (from tokio version = 0.1) with crate that use tokio02 (tokio version = 0.2) internally (in my case it was reqwest). First I just changed std::future::Future to futures01::future::Future with futures03::compat. To make it compile. After run I get exactly your error.

Solution:

Adding tokio-compat resolved my problem.


More about tokio compat