You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/search/search-traffic-analytics.md
+59-20Lines changed: 59 additions & 20 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -19,44 +19,43 @@ Search traffic analytics is a pattern for implementing a feedback loop for your
19
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
20
21
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 [Collect and analyze log data](search-monitor-logs.md).
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, see [Collect and analyze log data](search-monitor-logs.md).
23
23
24
24
## Identify relevant search data
25
25
26
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.
27
27
28
28
Two signals are needed for search traffic analytics:
29
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.
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
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.
32
+
+ User-generated click events: On a search results page, a click event generally means that a document is a relevant result for a specific search query.
33
33
34
-
By linking search and click events with a correlation ID, you'll gain more insights into how your applicationperforming.
34
+
By linking search and click events with a correlation ID, you'll gain a deeper understanding of how well your application's search functionality is performing.
35
35
36
36
## Add search traffic analytics
37
37
38
-
The signals mentioned in the preceding section must be gathered from the search application as the user interacts with it.
39
-
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.
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.
40
39
41
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.
42
41
43
42

44
43
45
44
## 1 - Select a resource
46
45
47
-
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.
46
+
Select an existing Application Insights resource or [create one](https://docs.microsoft.com/azure/azure-monitor/app/create-new-resource) if you don't have one already.
48
47
49
-
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.
48
+
After you create the resource on Azure, [add Application Insights](https://docs.microsoft.com/azure/azure-monitor/app/platforms) to your code.
50
49
51
-
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.
50
+
You need the instrumentation key for creating the telemetry client for your application. You can find it in the portal, or from the Search Traffic Analytics page when you select an existing resource.
52
51
53
52
## 2 - Add instrumentation
54
53
55
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:
56
55
57
56
**Step 1: Create a telemetry client**
58
57
59
-
This is the object that sends events to the Application Insights Resource.
58
+
Create an object that sends events to Application Insights.
60
59
61
60
*C#*
62
61
@@ -72,7 +71,7 @@ This is the object that sends events to the Application Insights Resource.
72
71
window.appInsights=appInsights;
73
72
</script>
74
73
75
-
For other languages and platforms, see the complete [list](https://docs.microsoft.com/azure/application-insights/app-insights-platforms).
74
+
For other languages, see the complete list of [supported platforms and frameworks](https://docs.microsoft.com/azure/application-insights/app-insights-platforms).
76
75
77
76
**Step 2: Request a Search ID for correlation**
78
77
@@ -91,15 +90,15 @@ To correlate search requests with clicks, it's necessary to have a correlation I
var searchId = request.getResponseHeader('x-ms-azs-searchid');
99
98
100
99
**Step 3: Log Search events**
101
100
102
-
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:
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. Remember to log only user-generated search queries.
103
102
104
103
**SearchServiceName**: (string) search service name
105
104
**SearchId**: (guid) unique identifier of the search query (comes in the search response)
@@ -109,11 +108,7 @@ Every time that a search request is issued by a user, you should log that as a s
109
108
**ScoringProfile**: (string) name of the scoring profile used, if any
110
109
111
110
> [!NOTE]
112
-
> Request count on user generated queries by adding $count=true to your search query. See more information [here](/rest/api/searchservice/search-documents#counttrue--false).
113
-
>
114
-
115
-
> [!NOTE]
116
-
> Remember to only log search queries that are generated by users.
111
+
> Request the count of user generated queries by adding $count=true to your search query. For more information, see [Search Documents (REST)](/rest/api/searchservice/search-documents#counttrue--false).
117
112
>
118
113
119
114
*C#*
@@ -126,7 +121,7 @@ Every time that a search request is issued by a user, you should log that as a s
@@ -160,7 +155,7 @@ Every time that a user clicks on a document, that's a signal that must be logged
160
155
{"ClickedDocId", <clicked document id>},
161
156
{"Rank", <clicked document position>}
162
157
};
163
-
telemetryClient.TrackEvent("Click", properties);
158
+
_telemetryClient.TrackEvent("Click", properties);
164
159
165
160
*JavaScript*
166
161
@@ -200,6 +195,50 @@ The following screenshot shows the built-in reports and charts for analyzing sea
200
195
201
196

202
197
198
+
## Example
199
+
200
+
**Create your first search app in C#** is an ASP.NET Core solution that you can use to practice adding instrumentation code.
201
+
202
+
Use the sample code from the last lesson, [5 - Order results](https://docs.microsoft.com/en-us/azure/search/tutorial-csharp-orders), so that you can leverage search rank and more click behaviors. For this lesson, the [sample code](https://github.com/Azure-Samples/azure-search-dotnet-samples/tree/master/create-first-app/5-order-results) is located on GitHub.
203
+
204
+
1. Before adding Application Insights and instrumentation code, run the program to make sure there are no build errors.
205
+
206
+
1. In Visual Studio, select **Project** > **Add Application Insights Telemetry**. For more information, see [Enable Application Insights server-side telemetry](https://docs.microsoft.com/azure/azure-monitor/app/asp-net-core#enable-application-insights-server-side-telemetry-visual-studio).
207
+
208
+
1. Click **Get Started**.
209
+
210
+
1. Select your subscription, account, resource, and click **Register***.
211
+
212
+
At this point, your application is set up for application monitoring, which means all page loads are tracked with default metrics.
213
+
214
+
1. Open **HomeController.cs**.
215
+
216
+
1. On line 52, add `private static TelemetryClient _telemetryClient;` and when prompted, add `using Microsoft.ApplicationInsights;` as an assembly reference.
217
+
218
+
1. On line 20, add a constructor that accepts a telemetry client:
219
+
220
+
```csharp
221
+
publicHomeController(TelemetryClienttelemetry)
222
+
{
223
+
_telemetryClient=telemetry;
224
+
}
225
+
```
226
+
227
+
1. Correlate search and clicks events logged to Application Insights using the search ID. On line 79, add the following lines. When prompted, add `using System.Collections.Generic;` as an assembly reference.
0 commit comments