Search code examples
azure-cognitive-search

How to capture datasource name when using Azure Search indexer


I have a multi-tenant index in azure search and I want to populate it with several indexers, each uploading data from one specific tenant.

I want the search to be filtered by a field "tenantid". Each database that an indexer uses as a data source has the "tenantid" as it's name, but there is no function or option I found that enables adding a custom field mapping the name of the database to a field in the search results.

The naive solution to the problem is to add a field in each document in the DB containing the field "tenantid", but I would rather take this info from the database name and reduce my object size.

Any ideas? Thanks a lot.


Solution

  • There's currently no such field mapping function available. Please add this suggestion on Azure Search UserVoice.

    To workaround, instead of adding the database name to each document, you can just include it by specifying a datasource query as follows:

    SELECT c.id, c._ts, 'my_database' AS database FROM collection c WHERE c._ts >= @HighWaterMark