elastic icon indicating copy to clipboard operation
elastic copied to clipboard

Operations depend on StaticIndex

Open ryankurte opened this issue 5 years ago • 1 comments

Hey, thanks for making this!

In the docs it's noted that you can specify index expressions, however, turning this on results in a huge pile of the trait `elastic::prelude::StaticIndex` is not implemented for ... errors as afaik many of the library methods are implemented over StaticIndex, and it's not super clear how to fix this?

An example is put_mapping, which requires StaticIndex to create a PutMappingRequestBuilder, unfortunately the inner type is private so unless the type fulfills StaticIndex it is,, impossible (?), to set a mapping?

ryankurte avatar Jan 11 '20 04:01 ryankurte

FYI for anyone else in this predicament, this can be approximated with:

fn elastic_create_index_mapping<T: elastic::prelude::DocumentType>(client: &mut elastic::SyncClient, index: String) -> Result<(), elastic::Error> {
    let doc = T::index_mapping();
    let mapping = serde_json::to_string(&doc).unwrap();

    let body = json!({
        "mappings": {
            &index: mapping,
        }
    });

    client.index(index.clone()).create().send()?;

    let req = elastic::endpoints::IndicesPutMappingRequest::for_index(index.clone(), body);
    client.request(req).send()?;

    Ok(())
}

ryankurte avatar Jan 11 '20 05:01 ryankurte