Search for PortalItem by Date Created or Modified

487
0
02-28-2019 07:20 AM
JoeHershman
MVP Regular Contributor

Hi, I asked this in the ArcGIS Enterprise group Search by Date Created or Modified because I think it is really a syntax issue with search, but I am trying to do from a Runtime application so checking here.  I want to run a search for PortalItems in a group using the Date Modified of the item.  But I cannot seem to get this correct because it never returns results.

The code in Runtime is pretty straightforward:

//Portal uses time in Unix time > milliseconds
DateTimeOffset offset = new DateTimeOffset(new DateTime(2018, 1, 1));
long unixTime = offset.ToUnixTimeMilliseconds();
long unix2Time = new DateTimeOffset(DateTime.Now).ToUnixTimeMilliseconds();

//Query by group and pass in query string
parameters = 
       PortalQueryParameters.CreateForItemsOfTypeInGroup(PortalItemType.CodeSample,
            group.GroupId, $"modified:[{unixTime} TO {unix2Time}]");

parameters.Limit = 50;

PortalQueryResultSet<PortalItem> itemResultSet = await portal.FindItemsAsync(parameters);‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

In the sample I am using a date range from before I setup portal to today, I know the items are in that range.  I have also tried to use created instead of modified just to see if it is an issue with modified, and used 0 as a start date.  Based on the the API search reference this is the format to use Search reference—ArcGIS REST API: Users, groups, and content | ArcGIS for Developers.

Using this example the Find return no results.  If I remove the date query piece I get all the CodeSample items in the group as expected just not filtered by date.  Looking at the PortalQueryParameters you can see the query is:

type:"Code Sample" AND group:"006591a762ce4705827561768866d03c" AND (modified:"[1259692864000 TO 1551311005864]")

If I go into Portal and run the search directly no results, run without date component and it works fine.  I have tried just running queries in Portal using the date component without anything else and I can never get any results to return.  So it would seem to me the documented syntax for running these queries is incorrect.

Has anyone done anything to query for portal items based on date modified/created and would know the proper syntax for doing this?

 

Thanks

-Joe

Thanks,
-Joe
0 Kudos
0 Replies