Select distinct value from multiple indexes

Hello, how can I add a aggregation to get data based on unique field of multiple indexes. Let's say I have three different indexes in which they have a unique code but one unique code can be exists in different field of different index for say: I have unique code 10001 it can be exists as gtin in one index and barcode in another index. I want to get unique data base on gtin and barcode. So far after searching I am able to come up with a query but it didn't work.

{
    "query": {
        "bool": {
            "must": [
                {
                    "bool": {
                        "should": [
                            {
                                "query_string": {
                                    "query": "8809263701127"
                                }
                            },
                            {
                                "nested": {
                                    "path": "attributes",
                                    "query": {
                                        "bool": {
                                            "must": [
                                                {
                                                    "term": {
                                                        "attributes.value": "8809263701127"
                                                    }
                                                }
                                            ]
                                        }
                                    },
                                    "score_mode": "max",
                                    "ignore_unmapped": true
                                }
                            }
                        ],
                        "minimum_should_match": 1
                    }
                }
            ],
            "filter": [
                {
                    "bool": {
                        "should": [
                            {
                                "bool": {
                                    "must_not": {
                                        "term": {
                                            "_index": "custom-products"
                                        }
                                    }
                                }
                            },
                            {
                                "bool": {
                                    "must": [
                                        {
                                            "term": {
                                                "merchant.bvid": "b9daa4b4-9f89-4240-9892-c7df70774c18"
                                            }
                                        }
                                    ]
                                }
                            }
                        ]
                    }
                }
            ]
        }
    },
    "aggs": {
        "unique_set_1": {
            "terms": {
                "field": "gtin"
            },
            "aggregations": {
                "unique_set_2": {
                    "terms": {
                        "field": "barcode"
                    }
                }
            }
        }
    }
}

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.