Don't miss out Virtual Happy Hour today (April 26).

Try our conversational search powered by Generative AI!

Commerce - find variants with no prices

Vote:
 

I would like to use Episerver Search & Navigation -- Find -- to search for all variants that does have any prices. I am not sure how to build the correct filter to do this.

Code so far:

var itemsWithNoPrices = _client.Search<VariationContent>()
  .Filter(x => x.Prices() ????? )  // <-- how to construct?
  .Select(x => x.Code)
  .GetResult();

"Prices" are added by default via "nested conventions", and are of type IEnumerable<Price>. When a price exists I can see that the json in Find contains:


  "Prices$$nested": [
    {
      "MinQuantity$$number": 0,
      "CustomerPricing": {
        "PriceCode$$string": "",
        "PriceTypeId": 0,
        "$type": "Mediachase.Commerce.Pricing.CustomerPricing, Mediachase.Commerce"
      },
      "UnitPrice": {
        "Currency": {
        "CurrencyCode$$string": "USD"
      },
      "Amount$$number": "316.000000000",
      "$type": "Mediachase.Commerce.Money, Mediachase.Commerce"
      },


And when no prices exists it looks like this:

  "Prices$$nested": [],

How should my filter be constructed? Or phrased differently: how do I build a filter for nested queries as "Prices$$nested"?

--

The reason I want to use Find and not using traversing is, that the catalog contains more than 200.000 variants and Elastic search is quite fast for this.

#246576
Edited, Jan 09, 2021 20:26
Vote:
 

Have you tried creating a NestedFilter?

#246625
Jan 11, 2021 9:10
Robert Runge - Jan 12, 2021 8:30
Thanks for answering. Not quite sure what you mean by a nested filter, or maybe it is the same as nested queries you refer to?!
Vote:
 

https://world.episerver.com/documentation/developer-guides/search-navigation/NET-Client-API/searching/nested-queries/

I haven't tried it, but perhaps

 .Filter(x => x.Prices(), p => p.Amount > 0 ))

might work

#246627
Jan 11, 2021 9:24
Robert Runge - Jan 12, 2021 8:33
Thanks. I did write similar code to what you suggest.
Vote:
 

The code I wrote is following the path Quan Mai suggest:

.Filter(x => !x.Prices().MatchItem(p => p.MatchTypeHierarchy(typeof(Price))))

The thing is, that is "pure" Elasticsearch query, it is possible to test the "array" and not by querying a sub-item.

#246673
Jan 12, 2021 8:35
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.