Docs / Dynamic schemas

Dynamic schemas

Keep field types consistent across a dataset and preserve logs when types conflict. KalDB converts conflicting values to the established type where it can and keeps the value as sent in a new field, protecting existing dashboards and alerts.

A field changing type shouldn’t break your dashboards or erase the log you need to debug an incident. KalDB keeps field types consistent across a dataset. When a new log conflicts with an established type, KalDB converts the value to the established type where it can, and also indexes the value as sent in a separate field. It doesn’t reject the message.

For example, if account_id is an integer and old code later sends the numeric string "1002", KalDB indexes integer 1002 in account_id and the original "1002" in account_id_str. The original field stays an integer, existing numeric queries still match the log, and the value as sent stays searchable.

ONE DATASET. CONSISTENT TYPES. LOGS PRESERVED.Illustrative example

Incoming checkout logs

09:00 · new code

account_id
1001 · integer

10:00 · old PHP code

account_id
"1002" · string

Same kind of ID, sent as a numeric string.

Checkout dataset schema

account_id
integer · unchanged
account_id_str
string · new field

Established types stay consistent across hours.

Type conversions on write

"1002"→ account_id1002 · cast to int
"1002"→ account_id_str"1002" · as sent
"n/a"→ account_id_stronly · can’t cast

Elasticsearch: "n/a" in an index where account_id is a number rejects the whole log by default.

No rejected logs. account_id:1002 matches the 10:00 log, so dashboards and alerts don’t change. account_id_str shows what was sent, including "n/a".

The problem: one field, different types

OpenSearch’s dynamic mappings belong to individual indexes. With hourly indexes, each index maps account_id from the first value it sees. A service where new code logs integer IDs and old code logs the same IDs as numeric strings is enough to cause a conflict: if "1002" is the first value in the 11:00 index, account_id is mapped as text there, while it’s a number in the 10:00 index. Later integers in the 11:00 index are accepted as text, so no logs are lost, but numeric range queries and aggregations that span both indexes fail or return partial results. Changing a dashboard’s time range can expose that conflict, and alerts spanning multiple indexes can be affected too.

There is also a problem within an index: once a type is established, an incompatible value can cause the entire document to be rejected. For example, "n/a" cannot be parsed as an integer. By default, OpenSearch rejects a document with such a malformed value. Its ignore_malformed option can keep the document for supported types, but leaves the conflicting value unindexed in that field.

Rejected log messages leave gaps in the system you depend on during an incident. Unless your ingestion pipeline retains and replays them, the evidence needed to debug the failure is missing.

How KalDB handles it

  1. Establish the type at the dataset level. Once account_id is established as an integer, its type remains consistent across that dataset’s timeline. Each new hour doesn’t independently redefine it.
  2. Detect conflicts during ingestion. A later log with a string account_id is checked against the dataset’s existing field type.
  3. Convert the value where possible. If the string can be cast to the established type, like "1002", KalDB indexes the converted value, integer 1002, in account_id.
  4. Keep the value as sent. KalDB also indexes the original string in a new field, account_id_str. A value that can’t be cast, like "n/a", is indexed only in account_id_str. Either way, the message is preserved instead of rejected.
  5. Keep existing queries type-consistent. Dashboards and alerts using the integer field keep their expected type as new data arrives, and match converted values. The value as sent is available separately for investigation.
SituationOpenSearch dynamic mappingsKalDB dynamic schemas
Same field appears in successive hoursSeparate hourly indexes can assign different typesThe established type is consistent across the dataset
A string conflicts with an integer fieldAn unparseable value can reject the document; ignoring malformed values leaves that value unindexedA castable string is converted into the integer field, and the value as sent is indexed in a new field, such as account_id_str
Existing numeric dashboards and alertsConflicting mappings can cause failures across indexesThe original numeric field keeps its type and still matches converted values
Investigating the conflicting logA rejected message may be missing from the logging systemThe message is retained and its value as sent is searchable

Example: old code sends an account ID as a string

The following excerpts show application fields in a checkout dataset. Timestamps and ingestion metadata are omitted to focus on the conflict.

09:00 — establish the integer field

The application sends:

{
  "message": "checkout completed",
  "account_id": 1001
}

KalDB establishes account_id as an integer for the dataset. An existing dashboard might use a numeric query such as account_id:[1000 TO 2000].

10:00 — receive a conflicting string

Old code that hasn’t been updated sends the same ID as a numeric string:

{
  "message": "checkout completed",
  "account_id": "1002"
}

KalDB detects the conflict. "1002" can be cast to an integer, so KalDB indexes the converted value in account_id and the value as sent in a new field. The searchable application fields are:

{
  "message": "checkout completed",
  "account_id": 1002,
  "account_id_str": "1002"
}

The dataset now has both account_id (integer) and account_id_str (string). The original integer field hasn’t changed, and the log is still available to investigate.

When a value can’t be cast

If a log sends a value that can’t be converted to the established type:

{
  "message": "checkout failed",
  "account_id": "n/a"
}

KalDB indexes it only in the new field, and the log is still preserved:

{
  "message": "checkout failed",
  "account_id_str": "n/a"
}
Value sentaccount_id (integer)account_id_str (string)
10011001—
"1002"1002, cast to integer"1002", as sent
"n/a"— (can’t cast)"n/a", as sent

Search without changing the original field’s type

Existing numeric queries continue to target the integer field, and match both the 09:00 log and the converted 10:00 log:

account_id:[1000 TO 2000]

Find what the old code actually sent, including values that couldn’t be cast:

account_id_str:*

These are illustrative query expressions, not live search results. Select a time range covering the example events in your search client.

Values that can’t be cast appear only in the new field. The numeric query matches the integer and converted events, not the "n/a" event. To see every variant, query both fields. Existing dashboards and alerts keep their type assumptions; values that can’t be cast don’t silently become integers.

Why it matters

  • Consistent dashboards across time. A field’s type doesn’t depend on which hour a query reaches.
  • Alerts keep their type assumptions. Conflicting new values don’t replace the original field’s type.
  • Logs survive field conflicts. The event needed to investigate an incident remains indexed, with the value as sent available in a separate field.

Related