I already extracted employees belong to specific Departments by using this query which I added to Query Template inside Search Results of PnP Modern Search:

{searchTerms} Department:"Accounting" OR Department:"Finance"

Now, I would like to add a filter for email domains, want to filter out emails which ends with @abcholding.com

I tried to include this: AND mail:"*@abcholding.com but it did not work.

Anyone knows how to handle such an issue?

1 Answer 1

  1. Correct Syntax for Filtering Email Domains:

    The syntax for filtering by email domain in a search query isn't as straightforward as you might expect. The correct approach is to use the KQL (Keyword Query Language) wildcard syntax.

  2. Updated Query Template:

    Here's how you can modify your query to include the email domain filter:

    {searchTerms} (Department:"Accounting" OR Department:"Finance") AND mail:*@abcholding.com
  3. Ensure Correct Field Name:

    Make sure that the field name mail is correct. Sometimes, it might be different depending on your SharePoint setup. It might be Email or WorkEmail.

  4. Test the Query:

    Test your query to ensure it filters the emails correctly. You can use the SharePoint search interface or any search debugging tools provided in SharePoint to verify the results.

Example in Context:

Here's the full query you should place in the Query Template:

{searchTerms} (Department:"Accounting" OR Department:"Finance") AND mail:*@abcholding.com

If mail doesn't work, try using Email or WorkEmail instead:

{searchTerms} (Department:"Accounting" OR Department:"Finance") AND Email:*@abcholding.com


{searchTerms} (Department:"Accounting" OR Department:"Finance") AND WorkEmail:*@abcholding.com

This should properly filter out the emails based on the domain. If you face any issues, double-check the field names in your SharePoint user profile properties.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.