quickwit-oss/quickwit · error
Encountered unknown command: code {other}
Error message
Encountered unknown command: code {other} What it means
The REST search handler converts an Elasticsearch-style aggregation request (`aggs` JSON value) into the proto SearchRequest by serializing it to a JSON string with serde_json. `.expect` fires if `serde_json::to_string` fails, meaning the aggregation JSON could not be serialized. Since the input is already a parsed JSON value this indicates a non-serializable value (e.g. NaN/Infinity floats) or an aggregation type the serializer rejects.
Source
Thrown at quickwit/quickwit-ingest/src/doc_batch.rs:46
Commit,
// ... more to come?
}
/// We can use this byte to track both commands and their version changes
/// If serialization protocol changes, we can just use the next number
#[derive(Debug)]
#[repr(u8)]
pub enum DocCommandCode {
IngestV1 = 0,
CommitV1 = 1,
}
impl From<u8> for DocCommandCode {
fn from(value: u8) -> Self {
match value {
0 => DocCommandCode::IngestV1,
1 => DocCommandCode::CommitV1,
other => panic!("Encountered unknown command: code {other}"),
}
}
}
impl<T> DocCommand<T>
where T: Buf + Default
{
/// Returns the binary serialization code for the current version of this command.
pub fn code(&self) -> DocCommandCode {
match self {
DocCommand::Ingest { payload: _ } => DocCommandCode::IngestV1,
DocCommand::Commit => DocCommandCode::CommitV1,
}
}
/// Builds a command for bytes::Buf
pub fn read(mut buf: T) -> Self {
match buf.get_u8().into() {View on GitHub (pinned to a39730c5cd)
Solutions
- Inspect the `aggs` field of the failing request and remove or fix non-finite numbers (NaN, Infinity).
- Validate the aggregation JSON before sending: ensure all numeric literals are finite.
- If the aggs come from a template or generated config, fix the generator to emit finite values.
- If aggregation definitions are valid but rejected, check for a version mismatch between client and server aggregation schema.
Example fix
// before
serde_json::to_string(&agg).expect("could not serialize JsonValue")
// after
serde_json::to_string(&agg).map_err(|err| {
anyhow::anyhow!("failed to serialize aggregation request: {err}")
})? Defensive patterns
Strategy: validation
Validate before calling
// validate aggs before sending
function validateAggs(aggs) {
for (const n of extractNumbers(aggs)) {
if (!Number.isFinite(n)) throw new Error(`aggs contains non-finite number: ${n}`);
}
}
validateAggs(requestBody.aggs); Type guard
const isFiniteNumber = (v) => typeof v === 'number' && Number.isFinite(v);
Try / catch
// client-side: reject bad aggs before the request reaches the server
try {
validateAggs(aggs);
} catch (e) {
return res.status(400).json({ error: e.message });
} Prevention
- Never embed NaN/Infinity in aggregation bodies.
- Sanitize numbers generated by templates or computed expressions.
- Prefer YAML-safe values (avoid .nan/.inf) feeding into aggs.
- Pin client/server versions so aggregation schemas match.
When it happens
Trigger: Sending a POST /api/v1/_search (or _search/async) request with an `aggs` payload containing values serde_json cannot serialize — most commonly non-finite floats (NaN, Infinity) produced by numeric expressions in the aggregation body.
Common situations: Clients templating aggregations with computed numbers that yield NaN/Infinity; passing unusual JSON values (e.g. from YAML with .nan/.inf) in aggs; programmatic clients building aggs from floats without validating finiteness.
Understand the failure class
Background: "JSON serialization failed", "not JSON serializable", "Failed to serialize": why JSON marshaling errors happen and how to fix them — this error's family across 46 libraries.
Related errors
- `doc_batch` should not be empty
- invalid named document. there are more than 1 value associat
- the `{key}` value has to be a json object
- `index_id` in config file does not match index_id from query
- path based file sources are limited to a local usage, please
AI-assisted analysis of quickwit-oss/quickwit@a39730c5cd (2026-09-08).
Data as JSON: /api/errors/51e6458fef30db52.
Report an issue: GitHub.