What is the Microsoft Search KQL query field limits for a verticals? Is there limited number of characters or lines?
You know what is Microsoft 365 Search Vertical and what is KQL query in vertical configuration, right?

Under Microsoft 365 admin center Search and intelligence you can configure search verticals. There are some out-of-the-box verticals – like All, Files, Sites, People and you can configure custom one.
As a part of vertical configuration – you can specify KQL query – if you want e.g. limit search with some sites or content types etc.
The question is – how many sites I can specify in this query field? E.g. can I specify 1000 sites? 10k sites?
And the answer is: It does not matter, because the limit is not in number of characters or lines.
In my dev environment I was able to save 50,000 lines (~3M characters). But attempt to save 100K lines (6M symbols) has failed (due to timeout, I believe:

Again, as I said the problem is not here.
The problem is time required for search to apply query. I.e. when you ask search to bring you something – after it gets results from index and before display results to you it applies KQL query configured for the vertical. And this time is the bottleneck.
Here is what I got measuring search response time depending on query size:
Search | response time, seconds | KQL query # of lines | KQL query size, # of symbols |
works | 1 | 500 | 28,000 |
works | 5 | 1000 | 59,000 |
works | 9 | 2000 | 120,000 |
works | 25 | 3000 | 180,000 |
works/fails | 30 | 3500 | 208,000 |
fails | 35 | 3600 | 214,000 |
fails | 35 | 50,000 | 3,000,000 |
n/a | n/a | 100,000 (can’t save KQL query | 6,000,000 (can’t save KQL query) |
Which means that after ~ 1000 lines (50,000 characters) KQL query size – query becomes too slow, and after ~3000 lines (180k chars) – can fail (due to timeout I’d say).
DepartmentIdÂ
If your sites are organized in hierarchy under Hub site – you can use DepartmentId managed property to significantly decrease number of lines in query,
as you can cover all sites under the hub with
DepartmentId=<HubSiteId>
Pingback: DepartmentId for Enterprise Intranet Portal – Home Site and Search Scope and Relevance ⋆ m365 SharePoint Engineer