protosearch is a protobuf library and plugin to define document mappings as protobuf message types.
It has two connected components:
- The
protosearchlibrary provides the core protobuf field options extension. - The
protoc-gen-protosearchprotoccompiler plugin compiles messages annotated with these options into document mappings.
This is a Rust project with two crates:
-
This crate compiles Elasticsearch/OpenSearch OpenAPI specifications into protobuf libraries providing field options specific to that vendor. It is only of interest to
protosearchdevelopers. -
This crate provides the
protoccompiler pluginprotoc-gen-protosearchthat compiles messages annotated withprotosearchfield options into document mappings.
The protosearch-vendor binary provides three commands:
-
extractExtract an abstract specification of the vendor's supported mapping types.
-
compileCompile the abstract specification into a representation suitable to render as a protobuf file. Map OpenAPI types to protobuf types (e.g.
numbertodouble). -
renderRender the compiled specification as a protobuf file.
The protoc-gen-protosearch plugin transforms Protobuf descriptors into document mappings.
The plugin iterates over all top-level messages declared in the input files and looks for fields annotated with protosearch options.
If it finds any, it adds them to an internal representation of the document mapping.
Finally, it outputs the document mapping to a file named {package}.{message}.json.
The plugin passes most field values through to the mapping without validation. It does validate certain fields. Refer to the reference documentation for details.
This means it is possible to declare invalid mappings:
string uuid = 1 [(protosearch.field).mapping.type = "long"];Refer to the reference documentation.