How node_access tag works with query? I'm not able to understand the use and role of the node_access tag. I used the Node View permission module to restrict the access to the article content type for anonymous users.

Now I have created an auto-complete search box that searches node titles. This is the query I used.

$query = \Drupal::entityquery('node');
$query-&gt;condition('title', trim($search));
$query-&gt;condition('status', 1);
$query-&gt;addTag('node_access');
$nids = $query-&gt;execute();
$nodes = Node::loadMultiple($nids);


I don't want this search box to search titles that belong to the article content type, and I used the node_access tag.

Will this tag serves my purpose here or is there any other approach to achieve the same?
No, it will not serve for the purpose you have in mind. It checks the currently logged-in user has view access to the node, which means that if the currently logged-in user is the user #1, it will see every node, including the ones that aren't published, and independently from the content type.

As @Neograph734 says, you should not use that tag to filter out nodes basing on their content type. If you want to filter the result by content type, you should use a line like $query-&gt;condition('type', 'article'); to built the query.