Try our conversational search powered by Generative AI!

How to do distinct in Find Query


Something similar to this below
var query = people.DistinctBy(p => new { p.Id, p.Name });

Is there a way to do this in Episerver Find? Or override any method to make this work?

Feb 09, 2015 23:50

Why do you need to do distinct? Sounds like your index has duplicates.

Is your p.Id property decorated with [Id]?

Try that and then you won't get duplicates.

Feb 10, 2015 9:07

I think the requirement is that We have one to many relationship between product to variant. We want to search through all the variants but then display only the parent product on the results page. 


A product is a vaialable in red, green and yellow color. The color information is stored in the variant object. But if someone searches for yellow, result will be retruning the product object of yellow variantion. 

Any help in this regard would be approcaiated. 

Feb 10, 2015 19:26

I would include the variants on a product property.

You can target searching on enumerable properties as described here:

You could also assemble the variants' text you want searchable on a product string property.

Feb 11, 2015 8:41

Thanks for your input Johan,

Nice approach. How do we use the enumerable properties in .For("").InFields(....)? 



Feb 11, 2015 16:05

Not sure but I recall Elasticsearch uses a dot syntax so something like this could work:
InFields(x => "product.variants.title", x => "product.variants.title")

I'd recommend creating a suitable property to get better control and shorter queries.

Feb 11, 2015 16:43

This syntax does not work with Find. I feel like there has to be a typed search available through the collection of objects if EPI server Find supports indexing the collections. 

Any help in this regard would be highly approciated. 

Feb 18, 2015 23:08
* 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.