Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Operations depend on StaticIndex #408

Open
ryankurte opened this issue Jan 11, 2020 · 1 comment
Open

Operations depend on StaticIndex #408

ryankurte opened this issue Jan 11, 2020 · 1 comment

Comments

@ryankurte
Copy link

ryankurte commented Jan 11, 2020

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
Copy link
Author

ryankurte commented Jan 11, 2020

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(())
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant