How to group by a field in Azure Search
Asked Answered
H

1

7

I need to query an index with paging and the index contains huge amount of documents. The query should also group by one of the fields. Is it possible to group by a field in Azure Search?

Thanks!

Huonghupeh answered 19/2, 2015 at 13:0 Comment(0)
C
2

For the grouping of fields, I would suggest that you leverage the faceting capability that allows you to retrieve the count of values within a field. There are some good examples of how to do faceting here: https://msdn.microsoft.com/en-us/library/azure/dn798927.aspx?f=255&MSPPError=-2147217396

Also, I am not sure if you are asking if it is possible to do paging with Azure Search, but the answer is yes, and you can do so using the $skip and $top parameters. There are also examples of this in the above link.

Liam

Chokebore answered 19/2, 2015 at 16:30 Comment(6)
Hi @Liam, my use case is that I am querying an index with paging and this works fine. I am trying to retrieve a list of distinct documents for specific field. Therefore I was hoping there was a distinct or a group by feature in Azure Search. I am not sure how I can use faceting for this use case?Huonghupeh
I see, so what you are asking for is a list of documents where say field1, field2 and field3 are all the same? If so, there is not a great way to do this (that I can think of) other than to create a new field that concatenates field1, field2, field3 and then you facet over that concatenated field to find the group counts.Chokebore
Hi @Liam, actually I realized that I am just looking for an equavalent of the distinct feature in SQL and I don't need to count anything. I am trying to query with one of the fields distinct. Is this possible?Huonghupeh
That sounds like a $filter. If you are looking for a specific set of documents with a distinct set of fields, then you could use $filter to limit the results. For example $filter=field1 eq 'foo'. Could you look at this page for more details on $filter to see if that might accomplish what you need? msdn.microsoft.com/en-us/library/azure/dn798927.aspxChokebore
Hi @Liam thanks for your feedback. I will have a better look at it.Huonghupeh
@Liam What about SUMS? There are a number of group operators beyond just count, is there no actual aggregate or grouping capabilities? Elastic Search can do these things.Costa

© 2022 - 2024 — McMap. All rights reserved.