| Crates.io | mapstic |
| lib.rs | mapstic |
| version | 0.1.0 |
| created_at | 2025-01-24 01:42:50.375019+00 |
| updated_at | 2025-01-24 01:42:50.375019+00 |
| description | Tooling to generate Elasticsearch index mappings from type definitions |
| homepage | |
| repository | https://github.com/LawnGnome/mapstic |
| max_upload_size | |
| id | 1528915 |
| size | 79,986 |
Mapstic provides a derive macro that allows for explicit Elasticsearch mappings to be generated based on Rust types.
Full documentation is available on docs.rs, but here's a simple example of how this looks in practice:
use mapstic::ToMapping;
#[derive(ToMapping)]
struct MyIndex {
id: u64,
score: f64,
time: std::time::SystemTime,
tags: Vec<Tag>,
}
#[derive(ToMapping)]
struct Tag(String);
The ToMapping trait then provides a to_mapping() method on the type that
can be used to get a Mapping that implements serde::Serialize and can be
provided directly to Elasticsearch:
use elasticsearch::{Elasticsearch, indices::IndicesPutMappingParts};
let client = Elasticsearch::default();
let mapping = MyIndex::to_mapping();
let response = client
.indices()
.put_mapping(IndicesPutMappingParts::Index(&["my-index"]))
.body(mapping)
.send()
.await;
Development of this project was supported by the Rust Foundation.
Right now, I don't really have too many plans. This was developed for a specific project, and implements all the functionality needed for that project.
This could easily be used as the base for a full blown Elasticsearch mapping migration tool, but since I personally don't need that, I won't be writing it.
I'm happy to review PRs for things like:
time or jiff.#[mapstic(params(...))] attribute,
mostly because it seemed hard to do with Darling and it wasn't necessary for
any common field parameters.)Since this was also my first "real" derive macro project, and first time using Darling at all, it's inevitable that I've done some of it badly. Feedback welcome!
The Rust Foundation has adopted a Code of Conduct that we expect project participants to adhere to. Please read the full text so that you can understand what actions will and will not be tolerated.
See CONTRIBUTING.md.
Rust is primarily distributed under the terms of both the MIT license and the Apache License (Version 2.0), with documentation portions covered by the Creative Commons Attribution 4.0 International license..
See LICENSE-APACHE, LICENSE-MIT, LICENSE-documentation, and COPYRIGHT for details.
You can also read more under the Foundation's intellectual property policy.
You can read about other Rust Foundation policies in the footer of the Foundation website.