如何从Elasticsearch获取不同的记录

I am working on Elasticsearch (ES) for last couple of weeks. There are millions of records currently present in different search indices in ES.

I have noticed that in different search indices, there is duplication of records and it is creating problem.

We can search for duplicate records via code and remove those records. May be this can be applicable, but I have more than 100 million records so it will take lot of time.

My requirement is, while we fetch records from ES, we can apply different filters. Is there any filter or way we can only fetch distinct records? I am currently using REST API using PHP.

Here is the code that I am currently using and filters are working perfectly.

$params = [
    'index' => 'MyIndex',
    'type' => 'MyType',
    'from' => 0,
    'size' => 10,
    'body' => [
        'query' => [
            'bool' => [
                'must' => [
                    [ 'match' => [ 'image' => true ] ],
                    [ 'simple_query_string' => [ 'query' => 'MyQuery' ] ]
                ]
            ]
        ]
    ]
];

I also tried looking something from "Aggregations", but couldn't find something related to my requirement.

Quick help will be highly appreciated.

Thanks in advance.

I think what you are looking for is "collapsing".

Elasticsearch supports it from 6.x:

https://www.elastic.co/guide/en/elasticsearch/reference/6.x/search-request-collapse.html