protected Document buildDocument(K id, Map<String, Object> fields) {
    String stringId = convert(id, String.class);
    Builder documentBuilder = Document.newBuilder();
    documentBuilder.setId(stringId);
    for (Map.Entry<String, Object> fieldData : fields.entrySet()) {
      Object value = fieldData.getValue();
      String fieldName = fieldData.getKey();
      for (Object object : getCollectionValues(value)) {
        try {
          Field field = buildField(metadata, fieldName, object);
          documentBuilder.addField(field);
        } catch (Exception e) {
          throw new SearchException(
              e,
              "Failed to add field '%s' with value '%s' to document with id '%s': %s",
              fieldName,
              value.toString(),
              id,
              e.getMessage());
        }
      }
    }

    return documentBuilder.build();
  }
 @Override
 public T from(Map<String, Object> from) {
   try {
     T instance = type.newInstance();
     for (Map.Entry<String, Object> entry : from.entrySet()) {
       String field = metadata.getDecodedFieldName(entry.getKey());
       BeanUtil.setDeclaredPropertyForcedSilent(instance, field, entry.getValue());
     }
     return instance;
   } catch (Exception e) {
     throw new SearchException(
         e,
         "Failed to create a new instance of %s for search results: %s",
         type.getName(),
         e.getMessage());
   }
 }