Simple search fails

38 views
Skip to first unread message

Elvis Valdes Ramirez

unread,
Nov 12, 2024, 4:01:09 PM11/12/24
to pyPreservica
Hi There,

I'm trying to run the following simple search and it fails with error code 400:

client = ContentAPI()
client.simple_search_csv("%", "everything.csv")

Output:
search failed with error code: 400
RuntimeError: (400, 'simple_search failed with error code: 400')

Any idea about this issue, I'll appreciate it, thank you.

James Carr

unread,
Nov 13, 2024, 8:36:57 AM11/13/24
to pyPreservica
Hi

Update the script and add the csv_file=  before the file name.



client = ContentAPI()
client.simple_search_csv("%", csv_file="everything.csv")


~
James

Elvis Valdes Ramirez

unread,
Nov 13, 2024, 3:39:30 PM11/13/24
to pyPreservica
Hi James,

Thank you, it works fine, however I've tried to run the following and I got a Positional argument error:

metadata_fields = ["xip.title", "xip.description", "xip.document_type", "xip.parent_ref"]
content.simple_search_csv("Webcrawling", csv_file="output.csv", metadata_fields)

I'm running some of the examples from the pyPreservica documentation, though my last aim would be to export csv files with metadata content from assets within folders.

James Carr

unread,
Nov 14, 2024, 4:04:17 AM11/14/24
to pyPreservica
Try this

metadata_fields = ["xip.title", "xip.description", "xip.document_type", "xip.parent_ref"]
content.simple_search_csv(query="Webcrawling", csv_file="output.csv", list_indexes=metadata_fields)

Elvis Valdes Ramirez

unread,
Nov 14, 2024, 5:07:35 PM11/14/24
to pyPreservica
Hi James,

That worked, and apologies I should have started with the one I really need, the following that fails. I've tried different options and all failed, you can see the errors below between square brackets. Also I'd like to get the results in the script and not in a csv file, for which I tried "content.search_index_filter_list" but it didn't work. I hope you can help.

if __name__ == '__main__':
    metadata_fields = {
        "xip.reference": "*", "xip.title": "", "xip.description": "", "xip.document_type": "*", "xip.parent_hierarchy": f"{folder.reference}",
        "xip.security_descriptor": "*",
        "xip.identifier": "", "xip.bitstream_names_r_Preservation": ""}

    content.search_callback(content.ReportProgressCallBack())
    content.search_index_filter_csv("%", "assets.csv", metadata_fields) [error code:400]
content.search_index_filter_csv("%", csv_file="assets.csv", metadata_fields) [SyntaxError: positional argument follows keyword argument]
content.search_index_filter_csv("%", csv_file="assets.csv", list_indexes=metadata_fields) [TypeError: ContentAPI.search_index_filter_csv() got an unexpected keyword argument 'list_indexes']

Thank you

James Carr

unread,
Nov 15, 2024, 5:31:14 AM11/15/24
to pyPreservica
Hi

If you want the results written to a csv use:

content.search_index_filter_csv(query="%", csv_file="assets.csv", filter_values=metadata_fields)

If you want to process the results in the script use:

    for hit in content.search_index_filter_list(query="%", filter_values=metadata_fields):
        print(hit)

Elvis Valdes Ramirez

unread,
Nov 15, 2024, 11:35:11 AM11/15/24
to pyPreservica
Thank you James, it works fine, I really appreciate it.

Regards

Reply all
Reply to author
Forward
0 new messages