<?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 Create Attribute Index using Python API in ArcGIS API for Python Questions</title>
    <link>https://community.esri.com/t5/arcgis-api-for-python-questions/create-attribute-index-using-python-api/m-p/1277071#M8591</link>
    <description>&lt;P&gt;If I view the properties of a layer or table within a hosted feature layer, I'm able to view the existing indexes as a dictionary object.&lt;/P&gt;&lt;P&gt;Is it possible to create an attribute index on a hosted feature layer using the Python API?&amp;nbsp; If so, are there any examples available?&amp;nbsp; I can't find any in the Python API docs.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 10 Apr 2023 20:33:07 GMT</pubDate>
    <dc:creator>mpboyle</dc:creator>
    <dc:date>2023-04-10T20:33:07Z</dc:date>
    <item>
      <title>Create Attribute Index using Python API</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/create-attribute-index-using-python-api/m-p/1277071#M8591</link>
      <description>&lt;P&gt;If I view the properties of a layer or table within a hosted feature layer, I'm able to view the existing indexes as a dictionary object.&lt;/P&gt;&lt;P&gt;Is it possible to create an attribute index on a hosted feature layer using the Python API?&amp;nbsp; If so, are there any examples available?&amp;nbsp; I can't find any in the Python API docs.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 10 Apr 2023 20:33:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/create-attribute-index-using-python-api/m-p/1277071#M8591</guid>
      <dc:creator>mpboyle</dc:creator>
      <dc:date>2023-04-10T20:33:07Z</dc:date>
    </item>
    <item>
      <title>Re: Create Attribute Index using Python API</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/create-attribute-index-using-python-api/m-p/1277322#M8596</link>
      <description>&lt;P&gt;After some testing, this does seem doable using the Python API.&amp;nbsp; Below is some sample code that others may find useful.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcgis

# connect to portal
portal = arcgis.GIS(...your authentication method...)

# set item
item = portal.content.get('...item id...')

# get layers and tables (in my case I was targeting a table)
layers = item.layers
tables = item.tables

# target layer or table
fl = tables['x']  # x is the index of the layer or table

# create attribute index json/dictionary
idx = {'name': '...name of index...',
       'fields': 'Field1, Field2, Field3, etc...',
       'isAscending': True,
       'isUnique': False,  # only set to True if layer or table has unique values
       'description': '...description of index...'}

# add index to layer/table definition --- seems that whether there is 1 or multiple indexes you are adding, the object must be a list
r = fl.manager.add_to_definition({"indexes": [idx]})

# check result
print(r)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 11 Apr 2023 14:46:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/create-attribute-index-using-python-api/m-p/1277322#M8596</guid>
      <dc:creator>mpboyle</dc:creator>
      <dc:date>2023-04-11T14:46:40Z</dc:date>
    </item>
  </channel>
</rss>

