In [ ]:
import requests

url = 'http://10.35.30.231:9200/releases/_search'

payload = {
    "aggs": {
        "duplicates": {
            "terms": {
                "script": "doc['name.raw'].value + ' ' + doc['artist_display.raw'].value",
                "size": 10000,
                "min_doc_count": 2
            },
            "aggs": {
                "duplicates": {
                    "top_hits": {
                        "_source": {
                            "includes": [
                                "id",
                                "name",
                                "artist_display"
                            ]
                        },
                        "size": 20
                    }
                }
            }
        }
    }
}


r = requests.post(url, json=payload)

data = r.json()

limit_ids = []

for entry in data['aggregations']['duplicates']['buckets']:
    #print(entry['key'])
    #print(entry['doc_count'])
    for hit in entry['duplicates']['hits']['hits']:
        #print(hit['_id'])
        #print(hit['_source'])
        limit_ids.append(int(hit['_id']))
        
        

print(len(limit_ids))

In [ ]:
limit_ids

In [ ]:
[i for i in Release.objects.values_list('id', flat=True)]

In [65]:
c = Collection.objects.get(pk=2)

print(c.items.filter(content_type__id=108))

#for ct in ContentType.objects.all():
#    print(ct, ct.pk)


[<CollectionItem: <Release> The Album of the Soundtrack of the Trailer of the Film of Monty Python and the Holy Grail: Executive Version>, <CollectionItem: <Release> The Ultimate Monty Python Rip Off>, <CollectionItem: <Release> Monty Python Sings>, <CollectionItem: <Release> Monty Python's Contractual Obligation Album>, <CollectionItem: <Release> Flash>, <CollectionItem: <Release> Wild Thing>, <CollectionItem: <Release> Beckology>, <CollectionItem: <Release> Another Monty Python CD>, <CollectionItem: <Release> Monty Python's Previous Record>, <CollectionItem: <Release> Monty Python Live at Drury Lane>, <CollectionItem: <Release> Dice>, <CollectionItem: <Release> The Instant Monty Python CD Collection>, <CollectionItem: <Release> Give Me Convenience or Give Me Death>, <CollectionItem: <Release> Monty Python's Life of Brian>, <CollectionItem: <Release> Fresh Fruit for Rotting Vegetables>, <CollectionItem: <Release> George & James>, <CollectionItem: <Release> Monty Python's Flying Circus>, <CollectionItem: <Release> In the Flat Field>, <CollectionItem: <Release> New York City, NY 11.11.05>, <CollectionItem: <Release> Fear and Loathing in Las Vegas>, '...(remaining elements truncated)...']