How to make Wordpress search by post ID?

use functions.php

//in frontend only
function custom_search_query_ids( $query ) {
if ( !is_admin() && $query->is_search ) {
$result = $query->query_vars['s'];
$query->query_vars['s'] = '';    

$query->query_vars['p'] = intval( $result );//or use this one 
//$query->set('post__in', intval( $result ));//or this one
}
}
add_filter( 'pre_get_posts', 'custom_search_query_ids',1,9);

and you will search in standard wordpress search by post ID