elastic
elastic copied to clipboard
Operations depend on StaticIndex
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?
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(())
}