Content Manager hosted table search gives no result

269
5
Jump to solution
05-12-2021 12:20 PM
JaredPilbeam2
MVP Regular Contributor

Is there a way to search your Enterprise Portal for a hosted table using the content manager search()? I've tried a few different ways using the item_type= parameter, but I get nothing. And there is no obvious mention of tables in the Items and item types API help page?

 

table = gis.content.search(query="title:csvtest", item_type='table')

 

I've also tried these:

 

item_type='hosted table'
item_type='Table'
item_type='Table Layer'

 

They all give me this

 

[]

 

 

There is, however, a table in my content. I can find it with the required query parameter alone. The item type will come back as Table Layer, which, as you see above, I have tried.

 

table = gis.content.search(query="title:csvtest")

###result
<Item title:"csvtest" type:Table Layer owner:admin>

 

0 Kudos
1 Solution

Accepted Solutions
jcarlson
MVP Regular Contributor

When you call Item.type on a table, you get 'Feature Service'. Specifying that in the item_type parameter will return table layers, too.

However, there does seem to be some separate attribute being stored somewhere that identifies the service as a table, but where? If you look at the service JSON, you'll see something like this:

 

{
...
  "type" : "Feature Service", 
  "typeKeywords" : [
    "ArcGIS Server", 
    "Data", 
    "Feature Access", 
    "Feature Service", 
    "Service", 
    "Table", 
    "Hosted Service"
  ],
...
}

 

 

Refer to the search reference page, and you'll see that 'typekeywords' is its own search parameter, and goes in the query string.

 

# This works
gis.content.search('table')

# This is more specific, and probably better
gis.content.search('typekeywords:table')

 

 

Both  commands return:

[<Item title:"Join_Features_to_GISFIPSMG" type:Table Layer owner:carlsonj9>,
<Item title:"date test" type:Table Layer owner:carlsonj9>,
<Item title:"GISFIPSMG" type:Table Layer owner:carlsonj9>]

 EDIT: It looks like the items and item types page does not reference tables in type or typekeyword, so you'd be forgiven for not being able to find this information. I've sent feedback for the page to get updated.

- Josh Carlson
Kendall County GIS

View solution in original post

0 Kudos
5 Replies
jcarlson
MVP Regular Contributor

When you call Item.type on a table, you get 'Feature Service'. Specifying that in the item_type parameter will return table layers, too.

However, there does seem to be some separate attribute being stored somewhere that identifies the service as a table, but where? If you look at the service JSON, you'll see something like this:

 

{
...
  "type" : "Feature Service", 
  "typeKeywords" : [
    "ArcGIS Server", 
    "Data", 
    "Feature Access", 
    "Feature Service", 
    "Service", 
    "Table", 
    "Hosted Service"
  ],
...
}

 

 

Refer to the search reference page, and you'll see that 'typekeywords' is its own search parameter, and goes in the query string.

 

# This works
gis.content.search('table')

# This is more specific, and probably better
gis.content.search('typekeywords:table')

 

 

Both  commands return:

[<Item title:"Join_Features_to_GISFIPSMG" type:Table Layer owner:carlsonj9>,
<Item title:"date test" type:Table Layer owner:carlsonj9>,
<Item title:"GISFIPSMG" type:Table Layer owner:carlsonj9>]

 EDIT: It looks like the items and item types page does not reference tables in type or typekeyword, so you'd be forgiven for not being able to find this information. I've sent feedback for the page to get updated.

- Josh Carlson
Kendall County GIS

View solution in original post

0 Kudos
JaredPilbeam2
MVP Regular Contributor

Josh,

Thanks for the reply. I was able to get back the table I was searching for:

 

 

table = gis.content.search("typekeywords:table")
table

#out[]: <Item title:"csvtest" type:Table Layer owner:admin
...

#this also worked
table = gis.content.search(query="typekeywords:table")

 

 

 

However, that also returns every other table owned by admin. There are seven.

tab.png

 

I want to single out my table. And using the other parameters doesn't seem to do anything. For example, this will return all the tables under admin.

 

table = gis.content.search("typekeywords:table", sort_field='csvtest')

 

 

I've considered using an index number [0] to find the item, but that can be slippery as my colleagues also add content to the Portal with the admin sign-in. So, it might be [0] one day but not the next.

0 Kudos
JaredPilbeam2
MVP Regular Contributor

This isn't very encouraging:

"Care should be taken when using ArcGIS REST API search operations... The Portal uses a powerful search engine to index information and to allow full text searching on it. This search engine uses many different inputs to find the appropriate results and rank them. This often makes search 'fuzzy', making it ideal for human interaction, but not necessarily ideal for looking for specific records programmatically. Developers should avoid using search to find specific items (e.g. by title) as the results of these types of queries might change as the search engine evolves."

0 Kudos
jcarlson
MVP Regular Contributor

Ay caramba. I try to stick with "gis.content.get('itemid')" for that reason.

- Josh Carlson
Kendall County GIS
jcarlson
MVP Regular Contributor

Owner is also a query string parameter.

gis.content.search('typekeywords:table owner:carlsonj9')

 

- Josh Carlson
Kendall County GIS
0 Kudos