The default index policy on a DocumentContainer will AUTOMATICALLY index ALL documents added.
        There may be scenarios where you want to exclude a specific doc from the index even though all other 
        documents are being indexed automatically. 
        This method demonstrates how to use an index directive to control this

def ExplicitlyExcludeFromIndex(client, database_id):
    """ The default index policy on a DocumentContainer will AUTOMATICALLY index ALL documents added.
        There may be scenarios where you want to exclude a specific doc from the index even though all other 
        documents are being indexed automatically. 
        This method demonstrates how to use an index directive to control this

    """
    try:
        DeleteContainerIfExists(client, database_id, COLLECTION_ID)
        database_link = GetDatabaseLink(database_id)
        # collections = Query_Entities(client, 'collection', parent_link = database_link)
        # print(collections)

        # Create a collection with default index policy (i.e. automatic = true)
        created_Container = client.CreateContainer(database_link, {"id" : COLLECTION_ID})
        print(created_Container)

        print("\n" + "-" * 25 + "\n1. Collection created with index policy")
        print_dictionary_items(created_Container["indexingPolicy"])

        # Create a document and query on it immediately.
        # Will work as automatic indexing is still True
        collection_link = GetContainerLink(database_id, COLLECTION_ID)
        doc = client.CreateItem(collection_link, { "id" : "doc1", "orderId" : "order1" })
        print("\n" + "-" * 25 + "Document doc1 created with order1" +  "-" * 25)
        print(doc)

        query = {
                "query": "SELECT * FROM r WHERE r.orderId=@orderNo",
                "parameters": [ { "name":"@orderNo", "value": "order1" } ]
            }
        QueryDocumentsWithCustomQuery(client, collection_link, query)

        # Now, create a document but this time explictly exclude it from the collection using IndexingDirective
        # Then query for that document
        # Shoud NOT find it, because we excluded it from the index
        # BUT, the document is there and doing a ReadDocument by Id will prove it
        doc2 = client.CreateItem(collection_link, { "id" : "doc2", "orderId" : "order2" }, {'indexingDirective' : documents.IndexingDirective.Exclude})
        print("\n" + "-" * 25 + "Document doc2 created with order2" +  "-" * 25)
        print(doc2)

        query = {
                "query": "SELECT * FROM r WHERE r.orderId=@orderNo",
                "parameters": [ { "name":"@orderNo", "value": "order2" } ]
                }
        QueryDocumentsWithCustomQuery(client, collection_link, query)

        docRead = client.ReadItem(GetDocumentLink(database_id, COLLECTION_ID, "doc2"))
        print("Document read by ID: \n", docRead["id"])

        # Cleanup
        client.DeleteContainer(collection_link)
        print("\n")
    
    except errors.HTTPFailure as e:
        if e.status_code == 409:
            print("Entity already exists")
        elif e.status_code == 404:
            print("Entity doesn't exist")
        else:
            raise