Arun Krish
Arun Krish

Reputation: 21

Groupby/faceting by multiple fields in azure search

I want to groupby/faceting by multiple fields, say by "name" and "type" fields in the search index. Is it possible in Azure search. If so how can it be done?

Upvotes: 1

Views: 1259

Answers (1)

Bruce Johnston
Bruce Johnston

Reputation: 8634

It is not possible to facet by the combined values of multiple fields. You'd have to denormalize the fields yourself when you populate the index, then facet by the denormalized field. For example, if you have 'name' and 'type' fields, you'd have to create a combined 'nametype' field containing the combination of 'name' and 'type'. Then you would refer to the 'nametype' field in the 'facet' parameter of the Search request.

If before you had a document like this:

{ "id": "1", "name": "John", "type": "Customer" }

Now you will have a document like this: { "id": "1", "name": "John", "type": "Customer", "nametype": "John; Customer" } (You can use whatever separator you like between the name part and type part of nametype.)

Now, when you search, include facet=nametype in the request, and you'll get a count of all combinations of 'name' and 'type' that exist in the index.

Upvotes: 1

Related Questions