Query unique documents after my query

Hey stack overflow I have an Elasticsearch document that looks like below. I'm only interested in the 'tags' key.

 "_index": "graph_20211025t0909",
                "_type": "_doc",
                "_id": "E12201A5-CC50-40AF-97AE-C54A2CA303F7",
                "_score": null,
                "_source": {
                    "entity_id": "E12201A5-CC50-40AF-97AE-C54A2CA303F7",
                    "properties": {
                        "external": {
                            "facebook": {
                                "id": "muji.jp"
                            },
                            "instagram": {
                                "id": "muji_global"
                            },
                            "twitter": {
                                "id": "muji_net"
                            },
                            "wikidata": {
                                "id": "Q708789"
                            }
                        },
                        "akas": [
                            {
                                "value": "Muji",
                                "language": "zh"
                            },
                            {
                                "value": "multinacional japonesa",
                                "language": "es"
                            },
                        ]
                    },
                    "data_source": {
                        "data_pull_date": "202109",
                        "source_id": "muji_global",
                        "dataset": "brand"
                    },
                    "scoring_entity_data_size": 5306,
                    "population_percentile": 0.9855572298745676,
                    "type_synonyms": [],
                    "@version": "1",
                    "@timestamp": "2021-10-25T16:28:24.892Z",
                    "name": "Muji",
                    "types": [
                        "urn:entity:brand"
                    ],
                    "tags": [
                        {
                            "tag_id": "D24DE9CF-C778-4468-8433-5A0E8AA2BA9D",
                            "name": "Wikipedia articles with GND identifiers",
                            "type": "urn:tag:wikipedia_category"
                        },
                        {
                            "tag_id": "67A608CC-2DA3-4C78-B7F6-6DD419744FFC",
                            "name": "Clothing brands of Japan",
                            "type": "urn:tag:wikipedia_category"
                        },
]
}

My Elasticsearch query is

{
    "size": 20,
    "_source": ["tags"],
	"sort": [
		{ "@timestamp": { "order": "desc" } }
	],
    "query": {
        "nested" : {
            "path" : "tags",
                "query" : {
                    "bool" : {
                        "must" : [
                          { "match_phrase" : {"tags.name" : "thriller"} }
                        ]    
                }
            }
        }
    }
}

My question is with my query how do I return unique documents given my Elasticsearch query? I'm searching through "tags.name" in the "tags" field. I want my "tags" field to return a unique set of items so for example I'm currently getting back

tags: [
{
                        {
                            "name": "Male actors",
                            "tag_id": "A2A18D57-24B5-4578-B0D3-2A9190EEAD7C",
                            "type": "urn:tag:wikipedia_category"
                        },
                        {
                            "name": "some tag name",
                            "tag_id": "0CB4BE42-026F-4B14-A59A-C5A331E8A56F",
                            "type": "urn:tag:wikipedia_category"
                        },
    },
                        {
                            "name": "Male actors",
                            "tag_id": "A2A18D57-24B5-4578-B0D3-2A9190EEAD7C",
                            "type": "urn:tag:wikipedia_category"
                        },
                        {
                            "name": "another tag name",
                            "tag_id": "0CB4BE42-026F-4B14-A59A-C5A331E8A56F",
                            "type": "urn:tag:wikipedia_category"
                        },
}

]

I want something my results to not repeat "name": "Male actors"

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