Quick Tips: Power Apps & Azure Search
I built a Power App as a front-end to Azure Cognitive Search using a custom Power Platform connector and I wanted to share some of my learnings from that (on-going) experience.
There is at least one great example in the official Microsoft documentation about how to build a Power App on top of Azure Cognitive Search and before you use anything from this post, please make sure you read that tutorial. This post will share a few tips based on my learnings.
I built my entire solution based on the guidance in the example, but I still had a few questions as I tried to implement more features. Some of these questions were the result of my lack of depth on building custom connectors for Power Apps.
Required vs. optional parameters in the Azure Cognitive Search custom connector call
My first issue came up when setting the parameters for the query call to the connector.
The tutorial shares the following syntax for calling the custom connector:
However, based on the Open API configuration, there is one missing, required parameter and it threw me for a loop.
Here is my call to the connector:
My connector is called “YelpBusinessSearch” because I used a different data set
ClearCollect(searchResults, YelpBusinessSearch.Query(“2020–06–30”,{search:SearchTerms,’$select’:”Business_Id,Name,Description,City,State,Latitude,Longitude,categories”}).value)
Here is what I found about the arguments submitted to Azure Cognitive Search through the connector:
- The first argument is the api-version. Despite defining it as required with a default value, you still must provide a value in the call to the connector. The alternative would be to make this parameter not required in the connector definition with a valid default value.
- For the second argument, we need to define a dynamic JSON object providing the optional parameters we wish to specify. Any query parameter that is not required would land in this JSON object. This is really a lesson about custom API connectors for Power Platform — not really an Azure Cognitive Search thing. In my example, I provide the
search
parameter, the$select
parameter and later added the$filter
parameter. None of these parameters are required and all of them have default values.
Default $filter
parameter
You cannot submit an empty value to the Azure Cognitive Search API for the $filter
parameter. So, if you’re trying to stuff all parameters into a single connector function, you need to provide a default value that won’t interfere with the rest of your query parameters. For example, I used Business_Id ne null,
where Business_Id
is the key field on my index and can therefore never be null meaning this filter will return the entire result set.
Processing the results
Regardless of what you specify in the $select
portion of your call to the connector, if you haven’t defined a field as part of the connector definition, the app won’t recognize it — at least not as part of the autocomplete. I would recommend including any index fields marked as retrievable in your connector definition. Once you have that, it’s no different than handling any result set.
I’m continuing to encounter some challenges and will share any findings in subsequent posts…
References
Tutorial: Query an Azure Cognitive Search index from Power Apps