diff --git a/apachesolr.module b/apachesolr.module
index b7556f3..2ca90ad 100644
--- a/apachesolr.module
+++ b/apachesolr.module
@@ -1805,7 +1805,10 @@ function apachesolr_index_key($field) {
     return $type_prefix . $sm . $field['name'];
   }
   else {
-    return substr($type_prefix . $sm . $field['name'], 0, $apachesolr_field_length_limit);
+    $tmp = substr($type_prefix . $sm . $field['name'], 0, $apachesolr_field_length_limit);
+    // Remove any trailing underscore characters.
+    $tmp = trim($tmp, '_');
+    return $tmp;
   }
 }
 
