Index: src/wp-admin/includes/post.php
===================================================================
--- src/wp-admin/includes/post.php	(revision 39408)
+++ src/wp-admin/includes/post.php	(working copy)
@@ -1155,35 +1155,6 @@
 }
 
 /**
- * Filter the SQL clauses of an attachment query to include filenames.
- *
- * @since 4.7.0
- * @access private
- *
- * @global wpdb $wpdb WordPress database abstraction object.
- *
- * @param array $clauses An array including WHERE, GROUP BY, JOIN, ORDER BY,
- *                       DISTINCT, fields (SELECT), and LIMITS clauses.
- * @return array The modified clauses.
- */
-function _filter_query_attachment_filenames( $clauses ) {
-	global $wpdb;
-	remove_filter( 'posts_clauses', __FUNCTION__ );
-
-	// Add a LEFT JOIN of the postmeta table so we don't trample existing JOINs.
-	$clauses['join'] .= " LEFT JOIN {$wpdb->postmeta} AS sq1 ON ( {$wpdb->posts}.ID = sq1.post_id AND sq1.meta_key = '_wp_attached_file' )";
-
-	$clauses['groupby'] = "{$wpdb->posts}.ID";
-
-	$clauses['where'] = preg_replace(
-		"/\({$wpdb->posts}.post_content (NOT LIKE|LIKE) (\'[^']+\')\)/",
-		"$0 OR ( sq1.meta_value $1 $2 )",
-		$clauses['where'] );
-
-	return $clauses;
-}
-
-/**
  * Executes a query for attachments. An array of WP_Query arguments
  * can be passed in, which will override the arguments set by this function.
  *
Index: src/wp-includes/post.php
===================================================================
--- src/wp-includes/post.php	(revision 39408)
+++ src/wp-includes/post.php	(working copy)
@@ -6183,3 +6183,32 @@
 	clean_post_cache( $post->ID );
 	return $post_name;
 }
+
+/**
+ * Filter the SQL clauses of an attachment query to include filenames.
+ *
+ * @since 4.7.0
+ * @access private
+ *
+ * @global wpdb $wpdb WordPress database abstraction object.
+ *
+ * @param array $clauses An array including WHERE, GROUP BY, JOIN, ORDER BY,
+ *                       DISTINCT, fields (SELECT), and LIMITS clauses.
+ * @return array The modified clauses.
+ */
+function _filter_query_attachment_filenames( $clauses ) {
+	global $wpdb;
+	remove_filter( 'posts_clauses', __FUNCTION__ );
+
+	// Add a LEFT JOIN of the postmeta table so we don't trample existing JOINs.
+	$clauses['join'] .= " LEFT JOIN {$wpdb->postmeta} AS sq1 ON ( {$wpdb->posts}.ID = sq1.post_id AND sq1.meta_key = '_wp_attached_file' )";
+
+	$clauses['groupby'] = "{$wpdb->posts}.ID";
+
+	$clauses['where'] = preg_replace(
+		"/\({$wpdb->posts}.post_content (NOT LIKE|LIKE) (\'[^']+\')\)/",
+		"$0 OR ( sq1.meta_value $1 $2 )",
+		$clauses['where'] );
+
+	return $clauses;
+}
Index: src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php
===================================================================
--- src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php	(revision 39408)
+++ src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php	(working copy)
@@ -47,6 +47,11 @@
 			}
 		}
 
+		// Filter query clauses to include filenames.
+		if ( isset( $query_args['s'] ) ) {
+			add_filter( 'posts_clauses', '_filter_query_attachment_filenames' );
+		}
+
 		return $query_args;
 	}
 
Index: tests/phpunit/tests/rest-api/rest-attachments-controller.php
===================================================================
--- tests/phpunit/tests/rest-api/rest-attachments-controller.php	(revision 39408)
+++ tests/phpunit/tests/rest-api/rest-attachments-controller.php	(working copy)
@@ -1143,6 +1143,26 @@
 		$wp_rest_additional_fields = array();
 	}
 
+	public function test_search_item_by_filename() {
+		$this->factory->attachment->create_object( $this->test_file, 0, array(
+			'post_mime_type' => 'image/jpeg',
+		) );
+		$this->factory->attachment->create_object( $this->test_file2, 0, array(
+			'post_mime_type' => 'image/png',
+		) );
+
+		$filename = basename( $this->test_file2 );
+
+		$request = new WP_REST_Request( 'GET', '/wp/v2/media' );
+		$request->set_param( 'search', $filename );
+		$response = $this->server->dispatch( $request );
+		$data = $response->get_data();
+
+		$this->assertCount( 1, $data );
+		$this->assertArrayHasKey( 0, $data );
+		$this->assertEquals( 'image/png', $data[0]['mime_type'] );
+	}
+
 	public function additional_field_get_callback( $object, $request ) {
 		return 123;
 	}
