How to get Distinct results using Search API

I have a "customer" index with fields "FirstName" and "LastName".

My index contains data as follows:
First Name | LastName
Richard | Lockwood
Richard | Lockwood 2
Richard | Lockwood 3
Richard | Lockwood 4
Richard | Lockwood 5
Richard | Lockwood 6

https://192.1.2.3:9200/customer/_search?pretty&q=FirstName:Richard

Will return 6 records, I want to return distinct records based on FirstName, which will return only one record. How can I do this?

Advance thanks for the response!

Are they all not distinct?
If you want only one record then probably you need to also search for last name along with first name .

@DineshNaik Thank you so much for the reply.

I have found the solution and correct approach to achieve this is using aggregations

In future please don't open multiple topics on the same question @asimelastic :slight_smile:

@warkolm Yep, sure. Actually I was not sure about the category that is why posted same question in multiple categories.