<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Trying to iterate through all my feature services - issue with advanced_search? in ArcGIS API for Python Questions</title>
    <link>https://community.esri.com/t5/arcgis-api-for-python-questions/trying-to-iterate-through-all-my-feature-services/m-p/1063308#M6152</link>
    <description>&lt;P&gt;Just tried it on my organization, and while we don't have 10,000 items, I was getting a similar discrepancy between the standard search and advanced_search methods.&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, I altered the syntax of the advanced_search query parameter from:&lt;/P&gt;&lt;P&gt;query = "orgid:&amp;lt;OrgID&amp;gt; and type:'Feature Service'"&lt;/P&gt;&lt;P&gt;to&amp;nbsp;&lt;/P&gt;&lt;P&gt;query = "orgid:&amp;lt;OrgID&amp;gt; AND type:'Feature Service'"&lt;/P&gt;&lt;P&gt;Changing the logical operator to uppercase in the query worked on my end and caused the two search methods to agree with each other.&lt;/P&gt;</description>
    <pubDate>Mon, 31 May 2021 15:25:38 GMT</pubDate>
    <dc:creator>Kevin_McIntyre</dc:creator>
    <dc:date>2021-05-31T15:25:38Z</dc:date>
    <item>
      <title>Trying to iterate through all my feature services - issue with advanced_search?</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/trying-to-iterate-through-all-my-feature-services/m-p/1063145#M6147</link>
      <description>&lt;P&gt;As an admin for ArcGIS Online, I want to iterate through all of my hosted feature services so that I can check a few things.&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Organisation has over 10,000 items&lt;/LI&gt;&lt;LI&gt;Having issues between the count of records returned from what appears to be the same query with search and advanced_search&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;from arcgis.gis import GIS

# connect to the portal
gis = GIS(profile='my_prof', expiration=9999)  #PROD

# Create two lists to store results in
adv_S_list = []
search_list = []

# Count with standard search, maxes out at 10000 
search_items = gis.content.search(query="*", item_type="Feature Service", max_items = 10000)  

for i in search_items:
    search_list.append((i.title, i.type))

# Count from regular search
print("#FS Items found using search: " + str(len(search_items)))  #returns 3993, this seems correct from looking at items in search_list

# get a count using advanced_search
count_items = gis.content.advanced_search(
    query = "orgid:vHnIGBHHqDR6y0CR and type:'Feature Service'",
    max_items = 70000,
    return_count = True    
    )

# Count from advanced_search
print("#FS Items found using advanced_search: " + str(count_items)) # returns 481
      

# paginate through using advanced_search and get a count
start = 0
len_sr = 100



while len_sr == 100:
    all_items = gis.content.advanced_search(
        query = "orgid:vHnIGBHHqDR6y0CR and type:'Feature Service'",
        start = start,
        max_items = 100
        )
    
    list_items = all_items.get('results')
    len_sr = len(list_items)
    start = start + 100
    for i in list_items:
        adv_S_list.append((i.title, i.type))

# Count from advanced_search pagination approach:    
print("#FS Items found using advanced_search + pagination: " + str(len(adv_S_list)))  # returns 482&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="SimonGIS_0-1622358214051.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/14581i50645A65A45174B1/image-size/medium?v=v2&amp;amp;px=400" role="button" title="SimonGIS_0-1622358214051.png" alt="SimonGIS_0-1622358214051.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;What is the right approach to correctly loop through all the reocds from a feature service?&lt;/P&gt;</description>
      <pubDate>Mon, 31 May 2021 14:20:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/trying-to-iterate-through-all-my-feature-services/m-p/1063145#M6147</guid>
      <dc:creator>SimonGIS</dc:creator>
      <dc:date>2021-05-31T14:20:49Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to iterate through all my feature services - issue with advanced_search?</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/trying-to-iterate-through-all-my-feature-services/m-p/1063290#M6150</link>
      <description>&lt;P&gt;Are you querying Feature Layers or Feature Services or both? Your code originally searches for Feature Layers but then searches for Feature Services. You're going to get different counts because you're searching for different items essentially.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 31 May 2021 13:48:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/trying-to-iterate-through-all-my-feature-services/m-p/1063290#M6150</guid>
      <dc:creator>Kevin_McIntyre</dc:creator>
      <dc:date>2021-05-31T13:48:41Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to iterate through all my feature services - issue with advanced_search?</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/trying-to-iterate-through-all-my-feature-services/m-p/1063291#M6151</link>
      <description>&lt;P&gt;Hey&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/206205"&gt;@Kevin_McIntyre&lt;/a&gt;&amp;nbsp;- good spot.&amp;nbsp;&lt;/P&gt;&lt;P&gt;End goal: Return all hosted feature services in ArcGIS Online.&lt;/P&gt;&lt;P&gt;With advanced_search I believe I am limited to the REST Search reference which lists feature service as a type.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have edited and re-run my code above&amp;nbsp; to match the standard search type to the advanced_search type:&lt;/P&gt;&lt;P&gt;search_items = gis.content.search(query="*", item_type="Feature Service", max_items = 10000)&lt;/P&gt;&lt;P&gt;The counts are similar (suspect some people have deleted items since last running code):&lt;/P&gt;&lt;P&gt;&lt;EM&gt;#FS Items found using search: &lt;STRONG&gt;3993&lt;/STRONG&gt;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;#FS Items found using advanced_search: &lt;STRONG&gt;480&lt;/STRONG&gt;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;#FS Items found using advanced_search + pagination: &lt;STRONG&gt;481&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;Are you able to run this code against an organisation at your end with a large number of items?&lt;/P&gt;</description>
      <pubDate>Mon, 31 May 2021 14:24:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/trying-to-iterate-through-all-my-feature-services/m-p/1063291#M6151</guid>
      <dc:creator>SimonGIS</dc:creator>
      <dc:date>2021-05-31T14:24:12Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to iterate through all my feature services - issue with advanced_search?</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/trying-to-iterate-through-all-my-feature-services/m-p/1063308#M6152</link>
      <description>&lt;P&gt;Just tried it on my organization, and while we don't have 10,000 items, I was getting a similar discrepancy between the standard search and advanced_search methods.&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, I altered the syntax of the advanced_search query parameter from:&lt;/P&gt;&lt;P&gt;query = "orgid:&amp;lt;OrgID&amp;gt; and type:'Feature Service'"&lt;/P&gt;&lt;P&gt;to&amp;nbsp;&lt;/P&gt;&lt;P&gt;query = "orgid:&amp;lt;OrgID&amp;gt; AND type:'Feature Service'"&lt;/P&gt;&lt;P&gt;Changing the logical operator to uppercase in the query worked on my end and caused the two search methods to agree with each other.&lt;/P&gt;</description>
      <pubDate>Mon, 31 May 2021 15:25:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/trying-to-iterate-through-all-my-feature-services/m-p/1063308#M6152</guid>
      <dc:creator>Kevin_McIntyre</dc:creator>
      <dc:date>2021-05-31T15:25:38Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to iterate through all my feature services - issue with advanced_search?</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/trying-to-iterate-through-all-my-feature-services/m-p/1063393#M6155</link>
      <description>&lt;P&gt;Yes!&amp;nbsp; Thanks for spotting and testing that&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/206205"&gt;@Kevin_McIntyre&lt;/a&gt;&amp;nbsp;- I had a feeling it would be something fairly trivial.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;I still have some discrepancy, but I can work with that.&amp;nbsp; Case closed. Thank you&lt;/P&gt;&lt;P&gt;#FS Items found using search: 3993&lt;BR /&gt;#FS Items found using advanced_search: 480&lt;BR /&gt;#FS Items found using advanced_search + pagination: 3999&lt;/P&gt;</description>
      <pubDate>Mon, 31 May 2021 23:44:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/trying-to-iterate-through-all-my-feature-services/m-p/1063393#M6155</guid>
      <dc:creator>SimonGIS</dc:creator>
      <dc:date>2021-05-31T23:44:19Z</dc:date>
    </item>
  </channel>
</rss>

