def RangeScanOnHashIndex(client, database_id):
    """When a range index is not available (i.e. Only hash or no index found on the path), comparisons queries can still 
       be performed as scans using Allow scan request headers passed through options

       This method demonstrates how to force a scan when only hash indexes exist on the path

       ===== Warning=====
       This was made an opt-in model by design. 
       Scanning is an expensive operation and doing this will have a large impact 
       on RequstUnits charged for an operation and will likely result in queries being throttled sooner.
    """
    try:
        DeleteContainerIfExists(client, database_id, COLLECTION_ID)
        database_link = GetDatabaseLink(database_id)
        # collections = Query_Entities(client, 'collection', parent_link = database_link)
        # print(collections)

        # Force a range scan operation on a hash indexed path
        collection_to_create = { "id" : COLLECTION_ID ,
                                "indexingPolicy" : 
                                { 
                                    "includedPaths" : [ {'path' : "/"} ],
                                    "excludedPaths" : [ {'path' : "/length/*"} ] # exclude length
                                    } 
                                }
        created_Container = client.CreateContainer(database_link, collection_to_create)
        print(created_Container)
        print("\n" + "-" * 25 + "\n5. Collection created with index policy")
        print_dictionary_items(created_Container["indexingPolicy"])

        collection_link = GetContainerLink(database_id, COLLECTION_ID)
        doc1 = client.CreateItem(collection_link, { "id" : "dyn1", "length" : 10, "width" : 5, "height" : 15 })
        doc2 = client.CreateItem(collection_link, { "id" : "dyn2", "length" : 7, "width" : 15 })
        doc3 = client.CreateItem(collection_link, { "id" : "dyn3", "length" : 2 })
        print("Three docs created with ids : ", doc1["id"], doc2["id"], doc3["id"])

        # Query for length > 5 - fail, this is a range based query on a Hash index only document
        query = { "query": "SELECT * FROM r WHERE r.length > 5" }
        QueryDocumentsWithCustomQuery(client, collection_link, query)

        # Now add IndexingDirective and repeat query
        # expect 200 OK because now we are explicitly allowing scans in a query
        # using the enableScanInQuery directive
        QueryDocumentsWithCustomQuery(client, collection_link, query)
        results = list(client.QueryItems(collection_link, query, {"enableScanInQuery" : True}))
        print("Printing documents queried by range by providing enableScanInQuery = True")
        for doc in results: print(doc["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
def RangeScanOnHashIndex ( client , database_id ) : try : DeleteContainerIfExists ( client , database_id , COLLECTION_ID ) database_link = GetDatabaseLink ( database_id ) collection_to_create = { "id" : COLLECTION_ID , "indexingPolicy" : { "includedPaths" : [ { 'path' : "/" } ] , "excludedPaths" : [ { 'path' : "/length/*" } ] } } created_Container = client . CreateContainer ( database_link , collection_to_create ) print ( created_Container ) print ( "\n" + "-" * 25 + "\n5. Collection created with index policy" ) print_dictionary_items ( created_Container [ "indexingPolicy" ] ) collection_link = GetContainerLink ( database_id , COLLECTION_ID ) doc1 = client . CreateItem ( collection_link , { "id" : "dyn1" , "length" : 10 , "width" : 5 , "height" : 15 } ) doc2 = client . CreateItem ( collection_link , { "id" : "dyn2" , "length" : 7 , "width" : 15 } ) doc3 = client . CreateItem ( collection_link , { "id" : "dyn3" , "length" : 2 } ) print ( "Three docs created with ids : " , doc1 [ "id" ] , doc2 [ "id" ] , doc3 [ "id" ] ) query = { "query" : "SELECT * FROM r WHERE r.length > 5" } QueryDocumentsWithCustomQuery ( client , collection_link , query ) QueryDocumentsWithCustomQuery ( client , collection_link , query ) results = list ( client . QueryItems ( collection_link , query , { "enableScanInQuery" : True } ) ) print ( "Printing documents queried by range by providing enableScanInQuery = True" ) for doc in results : print ( doc [ "id" ] ) 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
When a range index is not available (i.e. Only hash or no index found on the path), comparisons queries can still 
       be performed as scans using Allow scan request headers passed through options

       This method demonstrates how to force a scan when only hash indexes exist on the path

       ===== Warning=====
       This was made an opt-in model by design. 
       Scanning is an expensive operation and doing this will have a large impact 
       on RequstUnits charged for an operation and will likely result in queries being throttled sooner.