elastic-rs / elastic

An Elasticsearch REST API client for Rust
Apache License 2.0
253 stars 40 forks source link

Why does index_exists take an Index<'static> #367

Closed DevQps closed 5 years ago

DevQps commented 5 years ago

Description

I am trying to dynamically query if an index exists or not using the following code snippet:

let myindex = get a &str here (tried it with clone() as well)
let response = match client.index_exists(index(myindex)).send() {
    Ok(x) => x,
    Err(x) => panic!("Could not send an Index Exists request.")
};

and I get the following error:

    |         let myindex = get a &str here (tried it with clone() as well)
    |                      ^^^^^^^^^^-------------------
    |                      |
    |                      borrowed value does not live long enough
    | } <- END OF PROGRAM
    | - `myindex` dropped here while still borrowed
KodrAus commented 5 years ago

Hi @DevQps :wave:

This is just for simplicity on the client side, but it isn't strictly necessary and I'd like to fix it up so you can use borrowed data (since we do eventually just build an owned url from it). In the meantime you can create an owned string to use:

let myindex = get a &str here (tried it with clone() as well)
let response = match client.index(myindex.to_owned()).exists().send() {
    Ok(x) => x,
    Err(x) => panic!("Could not send an Index Exists request.")
};
KodrAus commented 5 years ago

We've got #313 to track fixing this up so I'll close this one in favour of that issue. Please feel free to re-open though if you run into any more problems!