Search code examples
azure-cognitive-searchazure-cognitive-services

Azure Cognitive Search query specific data source


I have a Azure Cognitive Search set up with two DataSources, two Indexers indexing those DataSources and one Index.

I'd like to be able to able to query/filter by DataSource. Is that possible?


Solution

  • Off of @Derek Legenzoff serve this is how I did it...

    1. Add all your datasources

    2. Create skillsets for each one data source with the following skill

      {
          "@odata.type": "#Microsoft.Skills.Util.ConditionalSkill",
          "name": "#1",
          "description": "",
          "context": "/document",
          "inputs": [
              {
                  "name": "condition",
                  "source": "= true"
              },
              {
                  "name": "whenTrue",
                  "source": "= 'Production'" //name of your environment
              },
              {
                  "name": "whenFalse",
                  "source": "= ''"
              }
         ],
         "outputs": [
             {
                 "name": "output",
                 "targetName": "Env"
             }
         ]
      }
      
    3. Create single index for your data model and add a Env field, and it's filterable and queryable

    4. Create indexers for each one of your data sources that point to the index from step 3 and datasource from step 1

    5. IMPORTANT: make sure you indexers have the following code in the definition.

       "outputFieldMappings": [
           {
               "sourceFieldName": "/document/Env",
               "targetFieldName": "Env"
           }
       ],
      

    This will connect the product of the skill to the index