{"record":{"id":"b4a2f574828fce62","repo":"fluent/fluentd","slug":"duplicate-key-in-or-e-key","errorCode":null,"errorMessage":"Duplicate key in <or>: #{e.key}","messagePattern":"Duplicate key in <or>: #(.+?)","errorType":"exception","errorClass":"Fluent::ConfigError","httpStatus":null,"severity":"error","filePath":"lib/fluent/plugin/filter_grep.rb","lineNumber":147,"sourceCode":"        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)\n          exclude_or_conditions[e.key] = Expression.new(record_accessor_create(e.key), e.pattern)\n        end\n      end\n\n      @_regexp_and_conditions = regexp_and_conditions.values unless regexp_and_conditions.empty?\n      @_exclude_and_conditions = exclude_and_conditions.values unless exclude_and_conditions.empty?\n      @_regexp_or_conditions = regexp_or_conditions.values unless regexp_or_conditions.empty?\n      @_exclude_or_conditions = exclude_or_conditions.values unless exclude_or_conditions.empty?\n    end\n\n    def filter(tag, time, record)\n      begin\n        if @_regexp_and_conditions && @_regexp_and_conditions.any? { |expression| !expression.match?(record) }\n          return nil","sourceCodeStart":129,"sourceCodeEnd":165,"githubUrl":"https://github.com/fluent/fluentd/blob/dd45c6e18dc7be33b5e5a0f0767bf46307ff5626/lib/fluent/plugin/filter_grep.rb#L129-L165","documentation":"The grep filter builds lookup hashes keyed by record field; while iterating every <or> block it raises Fluent::ConfigError 'Duplicate key in <or>: <key>' when a regexp key already exists in regexp_or_conditions. Because the hash accumulates across all <or> sections, the duplicate can be two <regexp> entries for the same key inside one <or> or the same key reused in different <or> blocks. This is a load-time configuration error: fluentd fails to start.","triggerScenarios":"Two or more <regexp> stanzas in <or> using the same field key (e.g. regexp1 message ... twice), or the same key appearing in separate <or> blocks; the second insertion triggers the check before the Expression is created.","commonSituations":"Copy-pasted regexp lines where only the pattern differs; teams adding another <or> block for the same field; refactors that merge <and> content into <or> without deduping keys.","solutions":["Deduplicate: keep one <regexp> entry per field key across all <or> blocks.","Combine multiple patterns for one key into a single regex with alternation, e.g. regexp1 message (timeout|refused).","Run fluentd --dry-run -c /etc/fluent/fluent.conf in CI to catch config errors before deploy."],"exampleFix":"# before\n<filter app.**>\n  @type grep\n  <or>\n    regexp1 message error\n    regexp1 message ERROR\n  </or>\n</filter>\n# after\n<filter app.**>\n  @type grep\n  <or>\n    regexp1 message (?i)error\n  </or>\n</filter>","handlingStrategy":"validation","validationCode":"# CI/config gate: fail before deploy on duplicate regexp keys across <or> blocks\n# (run: fluentd --dry-run -c /etc/fluent/fluent.conf && echo OK)\n# or scan the config text:\nkeys = conf.scan(/^\\s*regexp\\d+\\s+(\\S+)/).flatten\ncounts = Hash.new(0); keys.each { |k| counts[k] += 1 }\nabort \"duplicate regexp keys: #{counts.select { |_k, c| c > 1 }.keys}\" unless counts.values.all? { |c| c == 1 }","typeGuard":null,"tryCatchPattern":"begin\n  Fluent::Plugin.new_filter('grep').configure(conf)\nrescue Fluent::ConfigError => e\n  abort \"grep filter config rejected: #{e.message}\" # duplicate key in <or>: ...\nend","preventionTips":["Run fluentd --dry-run on every config change in CI.","One <regexp> per field key; combine patterns with regex alternation.","Lint configs for repeated keys in grep sections before review merge."],"tags":["fluentd","ruby","filter-grep","configuration","duplicate-key"],"backgroundTag":"duplicate-config-key","analyzedSha":"dd45c6e18dc7be33b5e5a0f0767bf46307ff5626","analyzedAt":"2026-08-21T16:22:07.332Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}