Add 'Or Condition' to specific field in Entity Query
So, the simplest way to rewrite this, would be:

$searchname = 'test'; 
$searchtype = 'type_1';

$field_types_array = [$searchtype, 'both'];
$query-&gt;condition('status', NODE_PUBLISHED);
$query-&gt;condition('field_type', $field_types_array, 'IN');
$query-&gt;sort('created','DESC');


The use of an array for the condition method forces the SQL query to be written as an IN query.

Reference documentation: QueryInterface::condition