[Archivesspace_Users_Group] Need help with API advanced query

Lora Woodford Lora.Woodford at lyrasis.org
Thu May 28 09:35:31 EDT 2020


Hi Andy,

When you're sending a search query along as your request using the search endpoints you're actually hitting the SOLR index and need to pass along the SOLR document fields.  This can be somewhat confusing, because what is returned to you is the JSON representation of the object(s) you queried for, but the query itself utilizes the field names in the index.

So, you'll likely want the following for your example:

    {
    	"query": {
    		"op": "AND",
    		"subqueries": [
    			{
    				"field": "primary_type",
    				"value": "top_container",
    				"comparator": "equals",
    				"jsonmodel_type": "field_query"
    			},
    			{
    				"field": "barcode_u_sstr",
    				"value": "BC98765",
    				"comparator": "equals",
    				"jsonmodel_type": "field_query"
    			}
    		],
    		"jsonmodel_type": "boolean_query"
    	},
    	"jsonmodel_type": "advanced_query"
    }

By looking in indexer_common.rb in the source code (https://github.com/archivesspace/archivesspace/blob/master/indexer/app/lib/indexer_common.rb#L631) , you can see where the top container "barcode" field becomes the "barcode_u_sstr" field in the resulting SOLR document.

Hope that helps, and happy to follow up with additional questions.

Lora

 
On 5/28/20, 3:20 AM, "archivesspace_users_group-bounces at lyralists.lyrasis.org on behalf of Andy Boze" <archivesspace_users_group-bounces at lyralists.lyrasis.org on behalf of boze.1 at nd.edu> wrote:

    Dear all,

    I'm using curl from the Windows 10 command line to retrieve JSON data 
    from our instance of AS. For the most part it's working well. I followed 
    some of the discussion from a few months ago which was very helpful in 
    figuring out how to use the advanced query, but I've reached a point 
    where I'm stuck.

    I can successfully send a query with the following string to get a 
    record for a resource with the identifier "ABC". I've formatted it here 
    so it's easier to read.

    {
    	"query": {
    		"op": "AND",
    		"subqueries": [
    			{
    				"field": "primary_type",
    				"value": "resource",
    				"comparator": "equals",
    				"jsonmodel_type": "field_query"
    			},
    			{
    				"field": "identifier",
    				"value": "ABC",
    				"comparator": "equals",
    				"jsonmodel_type": "field_query"
    			}
    		],
    		"jsonmodel_type": "boolean_query"
    	},
    	"jsonmodel_type": "advanced_query"
    }

    What I'm trying to do is get a record for a top_container with a barcode 
    of BC98765 by sending a query with this string.

    {
    	"query": {
    		"op": "AND",
    		"subqueries": [
    			{
    				"field": "jsonmodel_type",
    				"value": "top_container",
    				"comparator": "equals",
    				"jsonmodel_type": "field_query"
    			},
    			{
    				"field": "barcode",
    				"value": "BC98765",
    				"comparator": "equals",
    				"jsonmodel_type": "field_query"
    			}
    		],
    		"jsonmodel_type": "boolean_query"
    	},
    	"jsonmodel_type": "advanced_query"
    }

    When I send the above query, I get no response, not even an error 
    message. I'm thinking jsonmodel_type is not a field that I should query, 
    but when I requested the specific top_container record 
    (/repositories/2/top_containers/56484) there was no other field with a 
    value of top_container.

    I'd appreciate any advice how to request a record for a top_container by 
    barcode.

    Thanks.

    Andy

    -- 
    Andy Boze, Associate Librarian
    University of Notre Dame
    271H Hesburgh Library
    (574) 631-8708
    _______________________________________________
    Archivesspace_Users_Group mailing list
    Archivesspace_Users_Group at lyralists.lyrasis.org
    http://lyralists.lyrasis.org/mailman/listinfo/archivesspace_users_group



More information about the Archivesspace_Users_Group mailing list