Skip to content

Commit ff10678

Browse files
authored
Merge pull request #97670 from HeidiSteen/heidist-traffic
Azure Cognitive Search: search traffic analytics
2 parents ae2c7ff + 719bbcb commit ff10678

9 files changed

+219
-5
lines changed

.openpublishing.redirection.json

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1942,11 +1942,6 @@
19421942
"redirect_url": "/azure/cosmos-db/sql-api-get-started",
19431943
"redirect_document_id": false
19441944
},
1945-
{
1946-
"source_path": "articles/search/search-traffic-analytics.md",
1947-
"redirect_url": "/azure/search/search-monitor-usage",
1948-
"redirect_document_id": false
1949-
},
19501945
{
19511946
"source_path": "articles/search/knowledge-store-howto.md",
19521947
"redirect_url": "/azure/search/knowledge-store-create-rest",

articles/search/TOC.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,8 @@
305305
href: search-manage-powershell.md
306306
- name: Monitor activity and logging
307307
href: search-monitor-usage.md
308+
- name: Search traffic analytics
309+
href: search-traffic-analytics.md
308310
- name: Troubleshoot
309311
items:
310312
- name: Indexer issues
12.7 KB
Loading
11.7 KB
Loading
127 KB
Loading
110 KB
Loading
13.1 KB
Loading
13.6 KB
Loading
Lines changed: 217 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,217 @@
1+
---
2+
title: Report on search traffic analysis data
3+
titleSuffix: Azure Cognitive Search
4+
description: Enable search traffic analytics for Azure Cognitive Search, collect telemetry and user-initiated events using Application Insights, and then analyze findings in a Power BI report.
5+
6+
author: HeidiSteen
7+
manager: nitinme
8+
ms.author: heidist
9+
10+
ms.service: cognitive-search
11+
ms.topic: conceptual
12+
ms.date: 12/05/2019
13+
---
14+
15+
# Implement search traffic analytics in Azure Cognitive Search
16+
17+
Search traffic analytics is a pattern for implementing a feedback loop for your search service. The objective is to collect telemetry on user-initiated click events and keyboard inputs. Using this information, you can determine the effectiveness of your search solution, including popular search terms, clickthrough rate, and which query inputs yield zero results.
18+
19+
This pattern takes a dependency on [Application Insights](https://docs.microsoft.com/azure/azure-monitor/app/app-insights-overview) (a feature of [Azure Monitor](https://docs.microsoft.com/azure/azure-monitor/)) to collect user data. You will also need to add instrumentation to your client code, as described in this article. Finally, you will need a reporting mechanism to analyze the data. We recommend Power BI but you can use any tool that connects to Application Insights.
20+
21+
> [!NOTE]
22+
> The pattern described in this article is for advanced scenarios and clickstream data generated by your client. Alternatively, you can report on log information generated by your search service. For more information about service log reports, see [Monitor resource consumption and query activity](search-monitor-usage.md).
23+
24+
## Identify relevant search data
25+
26+
To have useful search metrics, it's necessary to log some signals from the users of the search application. These signals signify content that users are interested in and that they consider relevant to their needs.
27+
28+
There are two signals Search Traffic Analytics needs:
29+
30+
+ User-generated search events: only search queries initiated by a user are interesting. Search requests used to populate facets, additional content or any internal information, are not important and they skew and bias your results.
31+
32+
+ User-generated click events: By clicks in this document, we refer to a user selecting a particular search result returned from a search query. A click generally means that a document is a relevant result for a specific search query.
33+
34+
By linking search and click events with a correlation ID, it's possible to analyze the behaviors of users on your application. These search insights are impossible to obtain with only search traffic logs.
35+
36+
## Add search traffic analytics
37+
38+
The signals mentioned in the preceding section must be gathered from the search application as the user interacts with it. Application Insights is an extensible monitoring solution, available for multiple platforms, with flexible instrumentation options. Usage of Application Insights lets you take advantage of the Power BI search reports created by Azure Cognitive Search to make the analysis of data easier.
39+
40+
In the [portal](https://portal.azure.com) page for your Azure Cognitive Search service, the Search Traffic Analytics page contains a cheat sheet for following this telemetry pattern. You can also select or create an Application Insights resource, and see the necessary data, all in one place.
41+
42+
![Search Traffic Analytics instructions][1]
43+
44+
## 1 - Select a resource
45+
46+
You need to select an Application Insights resource to use or create one if you don't have one already. You can use a resource that's already in use to log the required custom events.
47+
48+
When creating a new Application Insights resource, all application types are valid for this scenario. Select the one that best fits the platform you are using.
49+
50+
You need the instrumentation key for creating the telemetry client for your application. You can get it from the Application Insights portal dashboard, or you can get it from the Search Traffic Analytics page, selecting the instance you want to use.
51+
52+
## 2 - Add instrumentation
53+
54+
This step is where you instrument your own search application, using the Application Insights resource your created in the step above. There are four steps to this process:
55+
56+
**Step 1: Create a telemetry client**
57+
58+
This is the object that sends events to the Application Insights Resource.
59+
60+
*C#*
61+
62+
private TelemetryClient telemetryClient = new TelemetryClient();
63+
telemetryClient.InstrumentationKey = "<YOUR INSTRUMENTATION KEY>";
64+
65+
*JavaScript*
66+
67+
<script type="text/javascript">var appInsights=window.appInsights||function(config){function r(config){t[config]=function(){var i=arguments;t.queue.push(function(){t[config].apply(t,i)})}}var t={config:config},u=document,e=window,o="script",s=u.createElement(o),i,f;s.src=config.url||"//az416426.vo.msecnd.net/scripts/a/ai.0.js";u.getElementsByTagName(o)[0].parentNode.appendChild(s);try{t.cookie=u.cookie}catch(h){}for(t.queue=[],i=["Event","Exception","Metric","PageView","Trace","Dependency"];i.length;)r("track"+i.pop());return r("setAuthenticatedUserContext"),r("clearAuthenticatedUserContext"),config.disableExceptionTracking||(i="onerror",r("_"+i),f=e[i],e[i]=function(config,r,u,e,o){var s=f&&f(config,r,u,e,o);return s!==!0&&t["_"+i](config,r,u,e,o),s}),t}
68+
({
69+
instrumentationKey: "<YOUR INSTRUMENTATION KEY>"
70+
});
71+
window.appInsights=appInsights;
72+
</script>
73+
74+
For other languages and platforms, see the complete [list](https://docs.microsoft.com/azure/application-insights/app-insights-platforms).
75+
76+
**Step 2: Request a Search ID for correlation**
77+
78+
To correlate search requests with clicks, it's necessary to have a correlation ID that relates these two distinct events. Azure Cognitive Search provides you with a Search ID when you request it with a header:
79+
80+
*C#*
81+
82+
// This sample uses the .NET SDK https://www.nuget.org/packages/Microsoft.Azure.Search
83+
84+
var client = new SearchIndexClient(<SearchServiceName>, <IndexName>, new SearchCredentials(<QueryKey>)
85+
var headers = new Dictionary<string, List<string>>() { { "x-ms-azs-return-searchid", new List<string>() { "true" } } };
86+
var response = await client.Documents.SearchWithHttpMessagesAsync(searchText: searchText, searchParameters: parameters, customHeaders: headers);
87+
IEnumerable<string> headerValues;
88+
string searchId = string.Empty;
89+
if (response.Response.Headers.TryGetValues("x-ms-azs-searchid", out headerValues)){
90+
searchId = headerValues.FirstOrDefault();
91+
}
92+
93+
*JavaScript*
94+
95+
request.setRequestHeader("x-ms-azs-return-searchid", "true");
96+
request.setRequestHeader("Access-Control-Expose-Headers", "x-ms-azs-searchid");
97+
var searchId = request.getResponseHeader('x-ms-azs-searchid');
98+
99+
**Step 3: Log Search events**
100+
101+
Every time that a search request is issued by a user, you should log that as a search event with the following schema on an Application Insights custom event:
102+
103+
**SearchServiceName**: (string) search service name
104+
**SearchId**: (guid) unique identifier of the search query (comes in the search response)
105+
**IndexName**: (string) search service index to be queried
106+
**QueryTerms**: (string) search terms entered by the user
107+
**ResultCount**: (int) number of documents that were returned (comes in the search response)
108+
**ScoringProfile**: (string) name of the scoring profile used, if any
109+
110+
> [!NOTE]
111+
> Request count on user generated queries by adding $count=true to your search query. See more information [here](https://docs.microsoft.com/rest/api/searchservice/search-documents#request)
112+
>
113+
114+
> [!NOTE]
115+
> Remember to only log search queries that are generated by users.
116+
>
117+
118+
*C#*
119+
120+
var properties = new Dictionary <string, string> {
121+
{"SearchServiceName", <service name>},
122+
{"SearchId", <search Id>},
123+
{"IndexName", <index name>},
124+
{"QueryTerms", <search terms>},
125+
{"ResultCount", <results count>},
126+
{"ScoringProfile", <scoring profile used>}
127+
};
128+
telemetryClient.TrackEvent("Search", properties);
129+
130+
*JavaScript*
131+
132+
appInsights.trackEvent("Search", {
133+
SearchServiceName: <service name>,
134+
SearchId: <search id>,
135+
IndexName: <index name>,
136+
QueryTerms: <search terms>,
137+
ResultCount: <results count>,
138+
ScoringProfile: <scoring profile used>
139+
});
140+
141+
**Step 4: Log Click events**
142+
143+
Every time that a user clicks on a document, that's a signal that must be logged for search analysis purposes. Use Application Insights custom events to log these events with the following schema:
144+
145+
**ServiceName**: (string) search service name
146+
**SearchId**: (guid) unique identifier of the related search query
147+
**DocId**: (string) document identifier
148+
**Position**: (int) rank of the document in the search results page
149+
150+
> [!NOTE]
151+
> Position refers to the cardinal order in your application. You are free to set this number, as long as it's always the same, to allow for comparison.
152+
>
153+
154+
*C#*
155+
156+
var properties = new Dictionary <string, string> {
157+
{"SearchServiceName", <service name>},
158+
{"SearchId", <search id>},
159+
{"ClickedDocId", <clicked document id>},
160+
{"Rank", <clicked document position>}
161+
};
162+
telemetryClient.TrackEvent("Click", properties);
163+
164+
*JavaScript*
165+
166+
appInsights.trackEvent("Click", {
167+
SearchServiceName: <service name>,
168+
SearchId: <search id>,
169+
ClickedDocId: <clicked document id>,
170+
Rank: <clicked document position>
171+
});
172+
173+
## 3 - Analyze in Power BI
174+
175+
After you have instrumented your app and verified your application is correctly connected to Application Insights, you can use a predefined template created by Azure Cognitive Search for Power BI desktop.
176+
177+
Azure Cognitive search provides a monitoring [Power BI Content Pack](https://app.powerbi.com/getdata/services/azure-search) so that you can analyze log data. T The content pack adds predefined charts and tables useful for analyzing the additional data captured for search traffic analytics. For more information, see the [content pack help page](https://powerbi.microsoft.com/documentation/powerbi-content-pack-azure-search/).
178+
179+
1. In the Azure Cognitive Search dashboard left-navigation pane, under **Settings**, click **Search traffic analytics**.
180+
181+
2. On the **Search traffic analytics** page, in step 3, click **Get Power BI Desktop** to install Power BI.
182+
183+
![Get Power BI reports](./media/search-traffic-analytics/get-use-power-bi.png "Get Power BI reports")
184+
185+
2. On the same page, click **Download Power BI report**.
186+
187+
3. The report opens in Power BI Desktop, and you are prompted to connect to Application Insights. You can find this information in the Azure portal pages for your Application Insights resource.
188+
189+
![Connect to Application Insights](./media/search-traffic-analytics/connect-to-app-insights.png "Connect to Application Insights")
190+
191+
4. Click **Load**.
192+
193+
The report contains charts and tables that help you make more informed decisions to improve your search performance and relevance.
194+
195+
Metrics included the following items:
196+
197+
* Click through Rate (CTR): ratio of users who click on a specific document to the number of total searches.
198+
* Searches without clicks: terms for top queries that register no clicks
199+
* Most clicked documents: most clicked documents by ID in the last 24 hours, 7 days, and 30 days.
200+
* Popular term-document pairs: terms that result in the same document clicked, ordered by clicks.
201+
* Time to click: clicks bucketed by time since the search query
202+
203+
The following screenshot shows the built-in reports and charts for analyzing search traffic analytics.
204+
205+
![Power BI dashboard for Azure Cognitive Search](./media/search-traffic-analytics/azuresearch-powerbi-dashboard.png "Power BI dashboard for Azure Cognitive Search")
206+
207+
## Next steps
208+
Instrument your search application to get powerful and insightful data about your search service.
209+
210+
You can find more information on [Application Insights](https://docs.microsoft.com/azure/azure-monitor/app/app-insights-overview) and visit the [pricing page](https://azure.microsoft.com/pricing/details/application-insights/) to learn more about their different service tiers.
211+
212+
Learn more about creating amazing reports. See [Getting started with Power BI Desktop](https://powerbi.microsoft.com/documentation/powerbi-desktop-getting-started/) for details.
213+
214+
<!--Image references-->
215+
[1]: ./media/search-traffic-analytics/azuresearch-trafficanalytics.png
216+
[2]: ./media/search-traffic-analytics/azuresearch-appinsightsdata.png
217+
[3]: ./media/search-traffic-analytics/azuresearch-pbitemplate.png

0 commit comments

Comments
 (0)