protosearch reference

March 3, 2026 ยท View on GitHub

This document describes the complete protosearch API.

API

protosearch exposes two extensions.

ExtensionMessageDescription
protosearch.fieldprotosearch.FieldManage field configuration
protosearch.indexprotosearch.IndexManage index configuration

field

protosearch.Field is a message with the following fields:

FieldTypeDescription
namestringRename a field in the mapping.
mappingprotosearch.FieldMappingDefine mapping field parameters.
targetrepeated protosearch.TargetConfigure a literal mapping for a specific target.

The protoc-gen-protosearch plugin compiles these message options to a JSON file containing the document mapping.

The simplest way to annotate a field is:

string uid = 1 [(protosearch.field) = {}];

This will generate a basic field mapping with no parameters except for type. See type inference below.

If you do not annotate a protobuf field with (protosearch.field) options, it will be excluded from the mapping.

name

The name field lets you rename a protobuf field in the compiled mapping.

string uid = 1 [(protosearch.field).name = "user_uid"];
{
  "properties": {
    "user_uid": {
      "type": "keyword"
    }
  }
}

mapping

In most cases, you will need to use mapping to define field parameters. FieldMapping supports the most common mapping parameters with one important difference:

  • It does not support properties, because the plugin supports defining object and nested fields as protobuf message fields.

Certain fields, namely dynamic, index_options, and term_vector, are enums. All provide a default UNSPECIFIED value. The plugin will not output an enum parameter if it has the default UNSPECIFIED value.

If you need to generate a parameter that is not in this list, see target below.

FieldTypeDescription
typestringThe field type. If omitted, the plugin infers the type from the protobuf field type.
analyzerstringAnalyzer used at index time. Applies to text fields.
boostdoubleBoost a field's score at index time.
coerceboolWhether to coerce values to the declared mapping type. Applies to numeric and date fields.
copy_torepeated stringCopy this field's value to the named field.
doc_valuesboolWhether to store doc values for sorting and aggregation.
dynamicprotosearch.DynamicHow to handle unknown subfields. Applies to object fields.
eager_global_ordinalsboolWhether to load global ordinals at refresh time.
enabledboolWhether to parse and index the field.
fielddataboolWhether to use in-memory fielddata for sorting and aggregations. Applies to text fields.
fieldsmap<string, FieldMapping>A multi-field mapping.
formatstringThe date format. Applies to date and date_nanos fields.
ignore_aboveint32Do not index strings longer than this length. Applies to keyword fields.
ignore_malformedboolIgnore invalid values instead of rejecting the document.
index_optionsprotosearch.IndexOptionsWhich information to store in the index. Applies to text fields.
index_phrasesboolWhether to index bigrams separately. Applies to text fields.
index_prefixesprotosearch.IndexPrefixesIndex term prefixes to speed up prefix queries. Applies to text fields.
indexboolWhether to index the field.
metamap<string, string>Metadata about the field.
normalizerstringNormalize keyword fields with this normalizer.
normsboolWhether to store field length norms for scoring.
null_valuegoogle.protobuf.ValueReplace explicit null values with this value at index time.
position_increment_gapint32A gap inserted between elements in an array to prevent spurious matches. Applies to text fields.
search_analyzerstringAnalyzer used at search time.
similaritystringThe scoring algorithm.
storeboolWhether to store this field separately from _source.
subobjectsboolWhether dotted field names are interpreted as nested subobjects.
term_vectorprotosearch.TermVectorWhether to store term vectors.
dynamic

protosearch.Dynamic is an enum with the following values:

  • DYNAMIC_TRUE
  • DYNAMIC_FALSE
  • DYNAMIC_STRICT
  • DYNAMIC_RUNTIME
index_options

protosearch.IndexOptions is an enum with the following values:

  • INDEX_OPTIONS_DOCS
  • INDEX_OPTIONS_FREQS
  • INDEX_OPTIONS_POSITIONS
  • INDEX_OPTIONS_OFFSETS
index_prefixes

protosearch.IndexPrefixes is a message with the following fields:

FieldTypeDescription
min_charsint32Minimum prefix length to index.
max_charsint32Maximum prefix length to index.
term_vector

protosearch.TermVector is an enum with the following values:

  • TERM_VECTOR_NO
  • TERM_VECTOR_YES
  • TERM_VECTOR_WITH_POSITIONS
  • TERM_VECTOR_WITH_OFFSETS
  • TERM_VECTOR_WITH_POSITIONS_OFFSETS
  • TERM_VECTOR_WITH_POSITIONS_PAYLOADS
  • TERM_VECTOR_WITH_POSITIONS_OFFSETS_PAYLOADS

target

The target field gives you complete control over how a protobuf field compiles to a mapping property.

It is a message with the following fields:

FieldTypeDescription
labelstringA human-readable label used to target that particular mapping with --protosearch_opt=target=<label>.
jsonstringA literal JSON string containing the mapping.

Use this to define more complex mapping types, or specify parameters that are not supported in FieldMapping. You can also use this to define mappings for different clusters or vendors. You can specify this field more than once.

For example, you might want to represent a Point object as a geo_point in Elasticsearch and an xy_point in OpenSearch. You can create targets for both mappings:

Point origin = 1 [(protosearch.field) = {
  target: {
    label: "elasticsearch"
    json: '{"type": "point"}'
  }
  target: {
    label: "opensearch"
    json: '{"type": "xy_point"}'
  }
}];

With --protosearch_opt=target=elasticsearch:

{
  "properties": {
    "origin": {
      "type": "point"
    }
  }
}

With --protosearch_opt=target=opensearch:

{
  "properties": {
    "origin": {
      "type": "xy_point"
    }
  }
}

If target does not match an existing label, the plugin falls back on the common mapping parameters.

index

protosearch.Index is a message with the following fields:

FieldTypeDescription
mappingprotosearch.IndexMappingDefine index mapping parameters.

mapping

protosearch.IndexMapping is a message with the following fields:

FieldTypeDescription
date_detectionboolWhether to detect date strings as date fields.
dynamicprotosearch.DynamicHow to handle unknown fields.
dynamic_date_formatsrepeated stringDate formats to use for dynamic date detection.
_field_namesprotosearch.IndexFieldNamesControls the _field_names metadata field.
_metamap<string, string>Metadata about the index mapping.
numeric_detectionboolWhether to detect numeric strings as numeric fields.
_routingprotosearch.IndexRoutingControls the _routing metadata field.
_sourceprotosearch.IndexSourceControls the _source metadata field.

dynamic uses the same protosearch.Dynamic enum as field.mapping.dynamic.

_field_names

protosearch.IndexFieldNames is a message with the following fields:

FieldTypeDescription
enabledboolWhether to enable the _field_names metadata field.
_routing

protosearch.IndexRouting is a message with the following fields:

FieldTypeDescription
requiredboolWhether to require routing for all document operations.
_source

protosearch.IndexSource is a message with the following fields:

FieldTypeDescription
compressboolWhether to compress stored source data. OpenSearch only.
compress_thresholdstringMinimum source size to trigger compression. OpenSearch only.
enabledboolWhether to store the _source field.
excludesrepeated stringFields to exclude from the stored _source.
includesrepeated stringFields to include in the stored _source.
modeprotosearch.SourceModeHow to store the _source field.
mode

protosearch.SourceMode is an enum with the following values:

  • SOURCE_MODE_DISABLED
  • SOURCE_MODE_STORED
  • SOURCE_MODE_SYNTHETIC

Type inference

If type is not specified, protoc-gen-protosearch will infer a field type from the protobuf type.

ProtobufElasticsearch
stringkeyword
boolboolean
int32, sint32, sfixed32integer
uint32, fixed32long
int64, sint64, sfixed64long
uint64, fixed64unsigned_long
floatfloat
doubledouble
bytesbinary
messageobject
enumkeyword
google.protobuf.Timestampdate

Diagnostics

The plugin validates some field options and collects diagnostics during compilation. Errors (EXXX) are fatal; protoc will exit with an error code and will not produce any output. The plugin prints warnings (WXXX) to standard output.

Errors

E001

The specified value is invalid for this parameter. The plugin will report the reason.

E002

target.json is not valid JSON.

E003

target.json is not a JSON object.

Warnings

W001

name is invalid.

Names must match the pattern [@a-z][a-z0-9_]*(\.[a-z0-9_]+)*. These are all allowed names:

@timestamp
foo
foo_bar
foo.bar.baz
foo_123

W002

The target label does not correspond to a known target.

protoc-gen-protosearch

With protoc-gen-protosearch installed on your $PATH, you can compile mappings like so:

protoc -I proto/ --plugin=protoc-gen-protosearch --protosearch_out=. proto/example/article.proto

Specify --protosearch_opt=target=<label> to compile the mapping for a specific target.

protoc -I proto/ --plugin=protoc-gen-protosearch --protosearch_out=. --protosearch_opt=target=<label> proto/example/article.proto

The plugin pretty-prints output by default. Specify --protosearch_opt=pretty=false to disable this.