Reputation: 123
Using Azure Search service I need to be able to group by or use distinct by a field in the query.
Use case: My business model has the concept of "resources" which have >=1 revisions. 1 revision is 1 document in an Azure index. I need to simulate something like "select the most recently changed resources from the index while also allowing pagination", therefore I need something like an ability to group the documents from the index into resources and search by them
Upvotes: 5
Views: 2824
Reputation: 8634
Azure Search does not support operators like distinct or group-by directly in the query language. However, there are potentially other ways to achieve what you want.
One way would be to make each document in your index a resource instead of a revision of a resource. Then you could have a complex collection field to represent the revisions of each resource. There are a few potential caveats to this approach:
Another approach would be to add a Boolean field like IsLatestVersion
, but then you'd need to set the flag to false on the previous revision whenever you add a new revision to your index. The approach above using complex types would probably be more straightforward.
Upvotes: 3