Using xmlstarlet as shell commands, in 2 calls of this utility:
#!/bin/sh
xmlstarlet sel -t -v '//table/search/query/text()' file.xml > /tmp/temp.txt
grep 'index=restricted_security' /tmp/temp.txt || exit 0
xmlstarlet ed -u '//table/search/query' -v "index=NEW_NAME
$(awk 'NR>1' /tmp/temp.txt)" file.xml
You can add the -L switch to xmlstarlet ed if you need to edit in place.
You can even edit the /tmp/temp.txt file with sed if needed:
(this is not XML but text after the first execution of xmlstarlet)
#!/bin/sh
xmlstarlet sel -t -v '//table/search/query/text()' file.xml > /tmp/temp.txt
sed -i 's/index=restricted_security/index=NEW_NAME/' /tmp/temp.txt
xmlstarlet ed -u '//table/search/query' -v "$(</tmp/temp.txt)" file.xml