Following is the definition of the getFields function in org.apache.lucene.document.Document class. As you can see, it can't handle the dynamic fields because dynamic fields have pattern like field_name_*, so the equals condition won't match in following function. Shouldn't we use matches function instead of equals so that a dynamic field string can be passed to the function?
/** * Returns an array of {@link IndexableField}s with the given name. * This method returns an empty array when there are no * matching fields. It never returns null. * * @param name the name of the field * @return a <code>Field[]</code> array */ public IndexableField[] getFields(String name) { List<IndexableField> result = new ArrayList<>(); for (IndexableField field : fields) { if (field.name().equals(name)) { result.add(field); } }