diff --git a/core/persistence-jpa/src/test/resources/domains/MasterContent.xml b/core/persistence-jpa/src/test/resources/domains/MasterContent.xml
index 4b3244d439..76c056f9b1 100644
--- a/core/persistence-jpa/src/test/resources/domains/MasterContent.xml
+++ b/core/persistence-jpa/src/test/resources/domains/MasterContent.xml
@@ -384,6 +384,9 @@ under the License.
realm_id="e4c28e7a-9dbf-4ee7-9441-93812a0d4a28"
creator="admin" lastModifier="admin"
creationDate="2010-10-20 11:00:00" lastChangeDate="2010-10-20 11:00:00"/>
+
+
+
+
diff --git a/ext/elasticsearch/client-elasticsearch/src/main/java/org/apache/syncope/ext/elasticsearch/client/ElasticsearchUtils.java b/ext/elasticsearch/client-elasticsearch/src/main/java/org/apache/syncope/ext/elasticsearch/client/ElasticsearchUtils.java
index 31ea96b55f..621f0723ac 100644
--- a/ext/elasticsearch/client-elasticsearch/src/main/java/org/apache/syncope/ext/elasticsearch/client/ElasticsearchUtils.java
+++ b/ext/elasticsearch/client-elasticsearch/src/main/java/org/apache/syncope/ext/elasticsearch/client/ElasticsearchUtils.java
@@ -20,6 +20,7 @@
import java.io.IOException;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
@@ -35,10 +36,14 @@
import org.apache.syncope.core.persistence.api.entity.Any;
import org.apache.syncope.core.persistence.api.entity.AnyTypeClass;
import org.apache.syncope.core.persistence.api.entity.AuditEvent;
+import org.apache.syncope.core.persistence.api.entity.GroupablePlainAttr;
+import org.apache.syncope.core.persistence.api.entity.GroupableRelatable;
+import org.apache.syncope.core.persistence.api.entity.Membership;
import org.apache.syncope.core.persistence.api.entity.PlainAttr;
import org.apache.syncope.core.persistence.api.entity.PlainAttrValue;
import org.apache.syncope.core.persistence.api.entity.Privilege;
import org.apache.syncope.core.persistence.api.entity.Realm;
+import org.apache.syncope.core.persistence.api.entity.Relationship;
import org.apache.syncope.core.persistence.api.entity.anyobject.AnyObject;
import org.apache.syncope.core.persistence.api.entity.group.Group;
import org.apache.syncope.core.persistence.api.entity.user.User;
@@ -98,6 +103,7 @@ public ElasticsearchUtils(
* @param any user, group or any object to index
* @return document specialized with content from the provided any
*/
+ @SuppressWarnings("unchecked")
@Transactional
public Map document(final Any> any) {
Map builder = new HashMap<>();
@@ -200,6 +206,27 @@ public Map document(final Any> any) {
builder.put(plainAttr.getSchema().getKey(), values.size() == 1 ? values.get(0) : values);
}
+ // add also flattened membership attributes
+ if (any instanceof GroupableRelatable) {
+ GroupableRelatable extends Any, ? extends Membership, ? extends GroupablePlainAttr, ? extends Any, ?
+ extends Relationship> entity = GroupableRelatable.class.cast(any);
+ entity.getMemberships().forEach(m -> entity.getPlainAttrs(m).forEach(mAttr -> {
+ List