How to avoid duplicate values in ealstic search 5.6.4

Please stop cross-posting. You already asked there How to remove duplicate values in ealstic search about the same topic.

Although it's in a bit different way this time.