Indexes: correctly translate partial filter expressions with automatic embedded entity indexes
If I have en entity FeedEvent with an index such as
@Index(fields = { @Field("actor.actorObject.userId"), @Field(value = "actor.actorType", type = DESC) },
options = @IndexOptions(disableValidation = true,
partialFilter = "{ 'actor.actorObject.userId': { $exists: true }, 'actor.actorType': { $exists: true } }")),
And also another entity InboxEvent that has a field called feedEvent, polymorphic, holding subtypes of FeedEvent as @Embedded.
Morphia automagically creates another index here like { feedEvent.actor.actorObject.userId, feedEvent.actor.actorType } which is nice...
BUT it doesn't seem to be handling the partial filter expression correctly, this is, it's creating this automatic index by prepending feedEvent to the fields of the original index but it's not doing the same for the field paths in the partial filter expression so the index is wrong.
If I try to set the index manually in InboxEvent Mongo will complain saying that there's already an index with the same keys but different options.
So the workaround is to remove the original index in FeedEvent and create both manually with the driver.
I'm going to try to recreate your problem based on what's here but if you could provide me with the index you think you should have, I'll try to get to the bottom of this. Thanks.
OK. I think i have recreated this sufficiently and see what you're talking about. I'm going to dig in to see what it'd take to correct this but, fair warning, i was planning on deprecating the index generation based on @Embedded types in 2.0. Finding nested index definitions and automatically creating indexes on the parent type is error prone and not always desirable. Indexes are about queryability and not all embedded types are meant to be queried. Better to explicitly declare on the top level types what indexes to used on those collections and not overallocate indexes that will never be used but still must be maintained by the server.
At any rate, I'll see if there's something that can be done in the meantime.