{"record":{"id":"e190d2b5d1cd4809","repo":"fluent/fluentd","slug":"duplicate-key-in-and-e-key","errorCode":null,"errorMessage":"Duplicate key in <and>: #{e.key}","messagePattern":"Duplicate key in <and>: #(.+?)","errorType":"validation","errorClass":"Fluent::ConfigError","httpStatus":null,"severity":"error","filePath":"lib/fluent/plugin/filter_grep.rb","lineNumber":133,"sourceCode":"      @regexps.each do |e|\n        raise Fluent::ConfigError, \"Duplicate key: #{e.key}\" if regexp_and_conditions.key?(e.key)\n        regexp_and_conditions[e.key] = Expression.new(record_accessor_create(e.key), e.pattern)\n      end\n\n      if @excludes.size > 1\n        log.info \"Top level multiple <exclude> is interpreted as 'or' condition\"\n      end\n      @excludes.each do |e|\n        raise Fluent::ConfigError, \"Duplicate key: #{e.key}\" if exclude_or_conditions.key?(e.key)\n        exclude_or_conditions[e.key] = Expression.new(record_accessor_create(e.key), e.pattern)\n      end\n\n      @and_conditions.each do |and_condition|\n        if !and_condition.regexps.empty? && !and_condition.excludes.empty?\n          raise Fluent::ConfigError, \"Do not specify both <regexp> and <exclude> in <and>\"\n        end\n        and_condition.regexps.each do |e|\n          raise Fluent::ConfigError, \"Duplicate key in <and>: #{e.key}\" if regexp_and_conditions.key?(e.key)\n          regexp_and_conditions[e.key] = Expression.new(record_accessor_create(e.key), e.pattern)\n        end\n        and_condition.excludes.each do |e|\n          raise Fluent::ConfigError, \"Duplicate key in <and>: #{e.key}\" if exclude_and_conditions.key?(e.key)\n          exclude_and_conditions[e.key] = Expression.new(record_accessor_create(e.key), e.pattern)\n        end\n      end\n\n      @or_conditions.each do |or_condition|\n        if !or_condition.regexps.empty? && !or_condition.excludes.empty?\n          raise Fluent::ConfigError, \"Do not specify both <regexp> and <exclude> in <or>\"\n        end\n        or_condition.regexps.each do |e|\n          raise Fluent::ConfigError, \"Duplicate key in <or>: #{e.key}\" if regexp_or_conditions.key?(e.key)\n          regexp_or_conditions[e.key] = Expression.new(record_accessor_create(e.key), e.pattern)\n        end\n        or_condition.excludes.each do |e|\n          raise Fluent::ConfigError, \"Duplicate key in <or>: #{e.key}\" if exclude_or_conditions.key?(e.key)","sourceCodeStart":115,"sourceCodeEnd":151,"githubUrl":"https://github.com/fluent/fluentd/blob/dd45c6e18dc7be33b5e5a0f0767bf46307ff5626/lib/fluent/plugin/filter_grep.rb#L115-L151","documentation":"When folding nested <regexp> directives of an <and> section into the global AND-condition map, configure rejects a key that already exists in regexp_and_conditions (from regexpN lines, top-level <regexp> sections, or earlier <and> blocks' regexps) with Fluent::ConfigError 'Duplicate key in <and>'.","triggerScenarios":"An <and> section whose <regexp> key repeats a field already registered, e.g. top-level <regexp> key message ... plus <and> <regexp> key message ... </and>; or the same key in two different <and> blocks' regexp parts.","commonSituations":"Building complex and/or logic and reusing the same field in multiple places; assuming each <and> block has its own key namespace (it does not — regexp AND-conditions share one global map).","solutions":["Use a different field, or consolidate the conditions on that field into one regex","If OR over the same field was intended, put the <regexp>s in an <or> section instead","Remove the duplicated directive identified by the key in the error message","Validate with fluentd --dry-run"],"exampleFix":"# before\n<regexp>\n  key message\n  pattern /error/\n</regexp>\n<and>\n  <regexp>\n    key message\n    pattern /fatal/\n  </regexp>\n</and>\n\n# after\n<regexp>\n  key message\n  pattern /(error|fatal)/\n</regexp>","handlingStrategy":"validation","validationCode":"taken = Set.new\nconf.sections(:regexp) { |s| taken << s['key'] }\n(1..20).each { |i| conf[\"regexp#{i}\"]&.split(/ /, 2)&.first&.then { |k| taken << k } }\nconf.sections(:and).each do |a|\n  a.sections(:regexp).each do |r|\n    abort \"duplicate regexp key in <and>: #{r['key']}\" if taken.include?(r['key'])\n    taken << r['key']\n  end\nend","typeGuard":null,"tryCatchPattern":"begin\n  filter.configure(conf)\nrescue Fluent::ConfigError => e\n  abort \"#{e.message} — regexp AND-conditions share one global key namespace\" if e.message.include?('Duplicate key in <and>')\n  raise\nend","preventionTips":["Treat the grep filter as having one global AND-key namespace across all sources","Combine multiple patterns on one field with alternation instead of repeating the key","Dry-run in CI","Document intended boolean logic before writing <and>/<or> sections"],"tags":["fluentd","grep-filter","duplicate-key","and-section","configerror"],"backgroundTag":"duplicate-config-key","analyzedSha":"dd45c6e18dc7be33b5e5a0f0767bf46307ff5626","analyzedAt":"2026-08-21T16:22:07.332Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}