My documents have a "Comments" collection, and I'd like to index the "Last Commented Date". I have statically defined index already working for other fields, so there's nothing wrong with my index. But attempting to add this new field is not working. I simply cannot ever get any results when searching by it.
I've tried getting the max date with a Max() aggregation (note that I have to handle cases where there are no comments)
testlastcommented = doc.Comments.Count > 0 ? doc.Comments.Select(c => c.DateEntered).Max() : null
This complains that DynamicList does not support Max(). I could swear that I had an iteration of this using Max() that worked, but now I can't get that working. But regardless even when it wasn't throwing an error, I wasn't able to query on the field.
So then I tried by OrderByDescending/FirstOrDefault as an alternative to Max()
testlastcommented = doc.Comments.OrderByDescending(c => c.DateEntered).FirstOrDefault()
This indexes with no errors. But whatever I do, it's as if the field doesn't exist in the index. I can't get any results with known values.
I broke down and added a calculated "LastCommented" property to the document and indexed that. That obviously works, but I'd rather not have to store a calculated field in the document.