Get all `Facets` from azure search without item result

北慕城南 提交于 2020-07-19 18:10:33

问题


Hi all I'm facing performance issues with azure cognitive search currently I have 956 Facets filed.

When I load Documents from Azure server it's taking almost 30 to 35 seconds.

But when I remove Facets from Azure search request Documents load in 2 to 3 seconds.

So for this, I have created 2 API's

  1. First API load Document result from the azure server.
  2. Second API load all Facets from the azure server.

Is there any way to load only Facets?

Code get the document from the azure server.

DocumentSearchResult<AzureSearchItem> results = null;
ISearchFilterResult searchResult = DependencyResolver.Current.GetService<ISearchFilterResult>();
WriteToFile("Initiate request call for search result ProcessAzureSearch {0}");
results = searchServiceClient.Documents.Search<AzureSearchItem>(searchWord, parameters);
WriteToFile("Response received for search result {0}");


回答1:


SearchParameters has a property called Top which instructs the Search Service to return those number of documents.

Gets or sets the number of search results to retrieve. This can be used in conjunction with $skip to implement client-side paging of search results. If results are truncated due to server-side paging, the response will include a continuation token that can be used to issue another Search request for the next page of results.

One possible solution would be to set this value to 0 in your Facets API and in that case no documents will be returned by the Search Service.

I am not sure about the performance implication of this approach though. I just tried it with a very small set of data and it worked just fine for me.




回答2:


Faceting is an aggregation operation that's performed over the matching results and is quite intensive when there are a lot of distinct buckets. I can't comment on the specific increase in latency but adding facets to the query definitely has a performance impact.

Since faceting computes aggregation on matching documents, it has to run the query in the backend but as Gaurav mentioned, specifying top = 0 will prevent the actual retrieval as it doesn't need to be included in the response. This could improve the performance especially if the individual docs are large.

Another possibility is to run just the query first and then use a identifier field to filter the docs with facets. Since filtering is faster than querying, the overall latency should improve. This only works if you're able to identify the id groups for the resultant docs from the 1st API call.

In general I'd recommend using facets judiciously and re-evaluate the design if there is a need to run faceting queries on a field with high cardinality. Here's a document on optimizing search performance that you can take a look at - https://docs.microsoft.com/en-us/azure/search/search-performance-optimization



来源:https://stackoverflow.com/questions/62512956/get-all-facets-from-azure-search-without-item-result

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!