{"record":{"id":"bfc2a2f9e2d0b30d","repo":"quickwit-oss/quickwit","slug":"fields-and-default-field-cannot-be-both-set-in-qu","errorCode":null,"errorMessage":"fields and default_field cannot be both set in `query_string` queries","messagePattern":"fields and default_field cannot be both set in `query_string` queries","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"quickwit/quickwit-query/src/elastic_query_dsl/query_string_query.rs","lineNumber":46,"sourceCode":"    /// We do not support JSON field either.\n    ///\n    /// Note that following elastic, we do not support \"string\" and require an array here.\n    #[serde(default)]\n    fields: Option<Vec<String>>,\n    #[serde(default)]\n    default_field: Option<String>,\n    #[serde(default)]\n    default_operator: BooleanOperand,\n    #[serde(default)]\n    boost: Option<NotNaNf32>,\n    #[serde(default)]\n    lenient: LeniencyBool,\n}\n\nimpl ConvertibleToQueryAst for QueryStringQuery {\n    fn convert_to_query_ast(self) -> anyhow::Result<crate::query_ast::QueryAst> {\n        if self.default_field.is_some() && self.fields.is_some() {\n            anyhow::bail!(\"fields and default_field cannot be both set in `query_string` queries\");\n        }\n        let default_fields: Option<Vec<String>> = self\n            .default_field\n            .map(|default_field| vec![default_field])\n            .or(self.fields);\n        let user_text_query = UserInputQuery {\n            user_text: self.query,\n            default_fields,\n            default_operator: self.default_operator,\n            lenient: self.lenient,\n        };\n        Ok(user_text_query.into())\n    }\n}\n\n#[cfg(test)]\nmod tests {\n    use crate::BooleanOperand;","sourceCodeStart":28,"sourceCodeEnd":64,"githubUrl":"https://github.com/quickwit-oss/quickwit/blob/a39730c5cdcd1a4fe798403737ae293999ea21f8/quickwit/quickwit-query/src/elastic_query_dsl/query_string_query.rs#L28-L64","documentation":"In QueryStringQuery::convert_to_query_ast, the Elastic-compatible `query_string` query rejects requests that supply both `default_field` (single field) and `fields` (list of fields). These two options are alternative ways to scope the search, so setting both is ambiguous and is treated as an invalid request. Either omit one, or use only `fields` with a single-element list.","triggerScenarios":"Calling convert_to_query_ast (e.g. via the query_string DSL or REST API with query_string queries) when both `default_field` and `fields` are set to Some, such as `{\"query_string\": {\"query\": \"foo\", \"default_field\": \"body\", \"fields\": [\"title\", \"body\"]}}`.","commonSituations":"Mixing Elasticsearch client libraries that set `default_field` by default while the user also passes `fields`; copying ES examples that use both; migrating from simple single-field queries to multi-field queries without removing the old `default_field` parameter.","solutions":["Remove `default_field` and keep only `fields` (list) when targeting multiple fields.","Remove `fields` and keep only `default_field` when targeting a single field.","If a single field is intended, move it into `fields` as a one-element list and drop `default_field`.","Check client/library defaults that may inject `default_field` automatically."],"exampleFix":"// before\n{\"query_string\": {\"query\": \"error\", \"default_field\": \"message\", \"fields\": [\"message\", \"level\"]}}\n// after\n{\"query_string\": {\"query\": \"error\", \"fields\": [\"message\", \"level\"]}}","handlingStrategy":"validation","validationCode":"if qs.default_field.is_some() && qs.fields.is_some() {\n    return Err(\"query_string: provide either default_field or fields, not both\");\n}","typeGuard":null,"tryCatchPattern":"match parse_and_build(query) {\n    Err(e) if e.to_string().contains(\"cannot be both set\") => {\n        // retry with fields only\n    }\n    r => r?,\n}","preventionTips":["Pick one scoping style: fields for multi-field, default_field for single-field.","Inspect client library defaults that inject default_field automatically.","Validate query JSON payloads before submission in your API layer."],"tags":["query-string","query-dsl","validation"],"backgroundTag":"mutually-exclusive-options","analyzedSha":"a39730c5cdcd1a4fe798403737ae293999ea21f8","analyzedAt":"2026-09-08T13:19:37.784Z","contentChangedAt":"2026-09-08T13:19:37.784Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}