How to remove childNode in AEM

Avatar

Avatar
Boost 1
Level 1
drumilk92707948
Level 1

Like

1 like

Total Posts

2 posts

Correct reply

0 solutions
Top badges earned
Boost 1
View profile

Avatar
Boost 1
Level 1
drumilk92707948
Level 1

Like

1 like

Total Posts

2 posts

Correct reply

0 solutions
Top badges earned
Boost 1
View profile
drumilk92707948
Level 1

06-08-2019

I would like to remove the child node by keeping the parent node hierarchy as is. can someone help how to achieve this.

For e.g.

/content

     /person

          /name

          /age

I would like to remove only child node "/name" here

Replies

Avatar

Avatar
Give Back 5
Level 3
anujg3325839
Level 3

Likes

27 likes

Total Posts

26 posts

Correct reply

8 solutions
Top badges earned
Give Back 5
Give Back 3
Give Back
Boost 5
Boost 3
View profile

Avatar
Give Back 5
Level 3
anujg3325839
Level 3

Likes

27 likes

Total Posts

26 posts

Correct reply

8 solutions
Top badges earned
Give Back 5
Give Back 3
Give Back
Boost 5
Boost 3
View profile
anujg3325839
Level 3

06-08-2019

you can use various ways via code using java JCR  API

----

Node root = getJcrSession().getRootNode();
 
String path = getFacetPath( repositoryId, facetId, name );
 
if ( root.hasNode( path ) )
 
{
 
Node node = root.getNode( path );
 
do
 
{
 
// also remove empty container nodes
 
Node parent = node.getParent();
  node
.remove();
  node
= parent;
 
}
 
while ( !node.hasNodes() );
 
}
 
}
 
catch ( RepositoryException e )
 
{
 
throw new MetadataRepositoryException( e.getMessage(), e );
 
}

---------------

Avatar

Avatar
Boost 1
Level 1
drumilk92707948
Level 1

Like

1 like

Total Posts

2 posts

Correct reply

0 solutions
Top badges earned
Boost 1
View profile

Avatar
Boost 1
Level 1
drumilk92707948
Level 1

Like

1 like

Total Posts

2 posts

Correct reply

0 solutions
Top badges earned
Boost 1
View profile
drumilk92707948
Level 1

06-08-2019

I would like to retain the parent structure for e.g.

/content

     /person

          /name

          /age

/content/person should retain while "name" is removed only

Avatar

Avatar
Coach
Employee
jbrar
Employee

Likes

389 likes

Total Posts

869 posts

Correct reply

283 solutions
Top badges earned
Coach
Establish
Give Back 50
Give Back 5
Give Back 3
View profile

Avatar
Coach
Employee
jbrar
Employee

Likes

389 likes

Total Posts

869 posts

Correct reply

283 solutions
Top badges earned
Coach
Establish
Give Back 50
Give Back 5
Give Back 3
View profile
jbrar
Employee

06-08-2019

Another way would be to run the groovy script to remove a node from a specific path. check [1] and "Remove corrupted nodes manually" at [2] on how to use it.

This should only remove the child node

[1] Groovy script to remove a node at a given path · GitHub

[2] Offline Compaction fails with SegmentNotFoundException & IllegalArgumentException