Kevin
Kevin

Reputation: 53

Filter and collections in OData

This is related to Azure's recently launched search service that is currently in preview form. I'm trying to figure out how to use OData's filter with collections. I know that I can do this:

$filter=Products/any(p: p eq 'WidgetA')

which will filter the Products collection by WidgetA. What I am trying to figure out is how to specify WidgetA OR WidgetB. I know that I can do this:

$filter=Products/any(p: p eq 'WidgetA') or Products/any(p: p eq 'WidgetB')

but thought there must be a more elegant or shorter way of doing this.

Upvotes: 3

Views: 7401

Answers (3)

user_5
user_5

Reputation: 576

It's recommended by Microsoft Azure to use "search.in" for matching values. It's similar to "in" command in OData, but currently "in" is not supported by Azure. You can find more info here.

For example:

group_ids/any(g: g eq '123' or g eq '456' or g eq '789')

Can change to:

group_ids/any(g: search.in(g, '123, 456, 789', ','))

Make sure to specify the delimiter. The default delimiter is space.

Upvotes: 0

Xavier John
Xavier John

Reputation: 9437

IN operator is supported in OData v4.01

https://docs.oasis-open.org/odata/odata/v4.01/odata-v4.01-part1-protocol.html#sec_BuiltinFilterOperations

Address/City in ('Redmond', 'London')

Upvotes: 1

Tan Jinfu
Tan Jinfu

Reputation: 3347

Unfortunately, there is no as far as I know. The operator that addresses your requirement is 'in' but there is no in the protocol: http://docs.oasis-open.org/odata/odata/v4.0/os/part2-url-conventions/odata-v4.0-os-part2-url-conventions.html

One more thing: there should be a property follows the range variable:

http://host/service/Orders?$filter=Items/any(d:d/Quantity gt 100) 

in your case it should be "p/Name eq 'WidgetA'" or some other properties.

Upvotes: 3

Related Questions