fixes #5836 Duplicate keys creating for key/value field

Fixed the issue and pushed the code for review, please check it.