elastic/elasticsearch · error · IllegalArgumentException

dynamic getter [{}, {}] not found

Error message

dynamic getter [{}, {}] not found

What it means

Def.lookupGetter, after exhausting Map and List special cases (and the integer-parse path for lists), throws 'dynamic getter [type, name] not found' as the terminal fallback. It means the receiver class is neither Map nor List, no whitelisted field named 'name' exists, and no whitelisted getX()/isX() method matches — the dot-access has no resolution.

Source

Thrown at modules/lang-painless/src/main/java/org/elasticsearch/painless/Def.java:662

            // arrays expose .length as a read-only getter
            return arrayLengthGetter(receiverClass);
        } else if (Map.class.isAssignableFrom(receiverClass)) {
            // maps allow access like mymap.key
            // wire 'key' as a parameter, its a constant in painless
            return MethodHandles.insertArguments(MAP_GET, 1, name);
        } else if (List.class.isAssignableFrom(receiverClass)) {
            // lists allow access like mylist.0
            // wire '0' (index) as a parameter, its a constant. this also avoids
            // parsing the same integer millions of times!
            try {
                int index = Integer.parseInt(name);
                return MethodHandles.insertArguments(LIST_GET, 1, index);
            } catch (NumberFormatException exception) {
                throw new IllegalArgumentException("Illegal list shortcut value [" + name + "].");
            }
        }

        throw new IllegalArgumentException("dynamic getter [" + typeToCanonicalTypeName(receiverClass) + ", " + name + "] not found");
    }

    /**
     * Looks up handle for a dynamic field setter (field store)
     * <p>
     * A dynamic field store for variable {@code x} of type {@code def} looks like:
     * {@code x.field = y}
     * <p>
     * The following field stores are allowed:
     * <ul>
     *   <li>Whitelisted {@code field} from receiver's class or any superclasses.
     *   <li>Whitelisted method named {@code setField()} from receiver's class/superclasses/interfaces.
     *   <li>The value corresponding to a map key named {@code field} when the receiver is a Map.
     *   <li>The value in a list at element {@code field} (integer) when the receiver is a List.
     * </ul>
     * <p>
     * This method traverses {@code recieverClass}'s class hierarchy (including interfaces)
     * until it finds a matching whitelisted setter. If one is not found, it throws an exception.

View on GitHub (pinned to db6a809a66)

Solutions

  1. Verify the field/getter name against the Painless API allowlist for the receiver's runtime class.
  2. Use the documented doc-values access (doc['field'].value) for indexed fields rather than arbitrary object access.
  3. Type the receiver concretely so missing access is a compile-time error with a clearer message.
  4. Check for typos and case sensitivity (camelCase).

Example fix

// before
def v = doc['timestamp'];
return v.millis; // not a whitelisted getter
// after
return doc['timestamp'].value.toEpochMilli();
Defensive patterns

Strategy: type-guard

Type guard

// Prefer concrete types or doc-values access: doc['field'].value over arbitrary def dot-access.
// In tests, assert the field path resolves via the Painless allowlist before shipping the script.

Try / catch

// On 'dynamic getter [..., name] not found', show the author the allowlisted fields/getters for the receiver class.

Prevention

When it happens

Trigger: A Painless script reads x.someField on a 'def' receiver whose runtime class has no whitelisted field or getter for 'someField'. Examples: accessing a private field, a field removed in a version, or a property name typo.

Common situations: Accessing _source/doc field via wrong path. Property name mismatch after a mapping change. Expecting a Java bean property that isn't whitelisted. Receiver resolved to null or a wrapper type.

Related errors


AI-assisted analysis of elastic/elasticsearch@db6a809a66 (2026-08-12). Data as JSON: /api/errors/dc4bae4bc77832a7. Report an issue: GitHub.