quickwit-oss/quickwit · error

invalid arguments for `hash_mod`: expected 2 arguments, foun

Error message

invalid arguments for `hash_mod`: expected 2 arguments, found {}

What it means

The routing expression parser requires the `hash_mod` function to receive exactly two arguments: an expression (the field path to hash) and a number (the modulo). `convert_ast` bails with this message when the argument count differs, interpolating the actual count found.

Source

Thrown at quickwit/quickwit-doc-mapper/src/routing_expression/mod.rs:292

}

fn convert_ast(ast: Vec<expression_dsl::ExpressionAst>) -> anyhow::Result<InnerRoutingExpr> {
    use expression_dsl::{Argument, ExpressionAst};

    let mut result = ast
        .into_iter()
        .map(|ast_elem| match ast_elem {
            ExpressionAst::Field(field_name) => {
                let field_path = expression_dsl::parse_field_name(&field_name)?
                    .into_iter()
                    .map(Cow::into_owned)
                    .collect();
                Ok(InnerRoutingExpr::Field(field_path))
            }
            ExpressionAst::Function { name, mut args } => match &*name {
                "hash_mod" => {
                    if args.len() != 2 {
                        anyhow::bail!(
                            "invalid arguments for `hash_mod`: expected 2 arguments, found {}",
                            args.len()
                        );
                    }

                    let Argument::Expression(fields) = args.remove(0) else {
                        anyhow::bail!("invalid 1st argument for `hash_mod`: expected expression");
                    };

                    let Argument::Number(modulo) = args.remove(0) else {
                        anyhow::bail!("invalid 2nd argument for `hash_mod`: expected number");
                    };

                    Ok(InnerRoutingExpr::Modulo(
                        Box::new(convert_ast(fields)?),
                        modulo,
                    ))
                }

View on GitHub (pinned to a39730c5cd)

Solutions

  1. Provide exactly two arguments: an expression and a number, e.g. `hash_mod(tenant_id, 10)`.
  2. If you only want one field with no modulo, use the plain field form `tenant_id` instead of `hash_mod`.
  3. Check the index config's routing_expression string for missing/extra commas or arguments and reload the index config.

Example fix

// before (index config)
routing_expression: hash_mod(tenant_id)
// after
routing_expression: hash_mod(tenant_id, 4)
Defensive patterns

Strategy: validation

Validate before calling

let expr = "hash_mod(tenant_id, 4)";
// count top-level args by rough parse or validate before handing to RoutingExpr::from_str
if !expr.starts_with("hash_mod(") || expr.matches(',').count() != 1 {
    return Err("hash_mod requires exactly 2 arguments: expression, number");
}

Prevention

When it happens

Trigger: Calling `RoutingExpr::from_str` (or the AST converter directly) with a routing expression like `hash_mod(field)` or `hash_mod(a, b, 10)` — i.e. any `hash_mod(...)` with an argument count other than 2.

Common situations: Typo or misunderstanding of `hash_mod` syntax in index config `routing_expression`; forgetting the modulo argument (e.g. `hash_mod(tenant_id)`); programmatic generation of routing expressions with wrong arity.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


AI-assisted analysis of quickwit-oss/quickwit@a39730c5cd (2026-09-08). Data as JSON: /api/errors/6f4b2a5a14a5df23. Report an issue: GitHub.