Skip to main content
Question

Java SDK metadata search files available not found

  • May 22, 2025
  • 2 replies
  • 21 views

Forum|alt.badge.img

Hi,

We have a problem searching files by metadata.
In the java SDK I get 4 files returned, I expected to find 14. These 10 files are available complete with the correct template and metadata in the Box web app. We have also a .NET application with the Box .NET SDK implemented and there the files are found and downloaded. 
The files that are "skipped" in the search are from 8 and 9 december 2021.
Very strange situation, what can be wrong? 

Kind regards,

Marcel

2 replies

Forum|alt.badge.img

Hello, 

Hmm. That is very odd. Can you send me the code you are running for both .net and java? I'm interested in comparing them. 

Thanks, 

Alex, Box Developer Advocate


Forum|alt.badge.img

Hello Alex,

The code is simple:

Java version

BoxSearch boxSearch = new BoxSearch(this.api);
BoxSearchParameters boxSearchParameters = new BoxSearchParameters();
PartialCollection<BoxItem.Info> totaalResultaat = new PartialCollection<BoxItem.Info>(0, 200, 200);

// metadata filter opbouwen
BoxMetadataFilter metaDataFilter = new BoxMetadataFilter();
boxSearchParameters.clearParameters();
boxSearchParameters.setType("file");

// Voeg de criteria toe aan het filter
metaDataFilter.setScope("enterprise");
metaDataFilter.setTemplateKey(template);

metaDataObject.keySet().forEach(keyStr ->
{

Object keyValue = metaDataObject.get(keyStr);
String filterItem = BoxMetadataHashtable.getMetadataVeldSleutel(DMGStringLib.naarCamelCase(keyStr.toString())).getKey();

metaDataFilter.addFilter(filterItem, keyValue.toString());
});
boxSearchParameters.setMetadataFilter(metaDataFilter);

zoekResultaat = boxSearch.searchRange(offsetValue, limitValue, boxSearchParameters);


.NET version


public async Task<BoxCollection<BoxItem>> searchFilesByMetaData(BoxClient boxClient, Dictionary<string, object> searchCriteria, string templateName)
{

var mdFilter = new BoxMetadataFilterRequest()
{
TemplateKey = templateName,
Scope = "enterprise",
Filters = searchCriteria
};

// Initiate search
return await boxClient.SearchManager.QueryAsync("", mdFilters: new List<BoxMetadataFilterRequest>() { mdFilter }, type: "file");
}

Regards,

Marcel