Searching by Aspect - Alfresco Content Services - 23.4 - 23.4 - Ready - Alfresco - external

Alfresco Content Services

Platform
Alfresco
Product
Alfresco Content Services
Release
23.4
License

Another common search requirement is to find files that have a certain aspect applied. We can do that by using the ASPECT keyword in a similar way to how we used the TYPE keyword, they could be combined too if needed. The following POST will match all files with the aspect acme:securityClassified applied (this aspect is part of the default content model that comes with the SDK template projects):

{
  "query": {
    "query": "+TYPE:\"cm:content\" AND +ASPECT:\"acme:securityClassified\"",
    "language": "afts"
  },
  "include": [
    "aspectNames"
  ],
  "paging": {
    "maxItems": "10",
    "skipCount": "0"
  },
  "sort": [{"type":"FIELD", "field":"cm:name", "ascending":"false"}]
}

Note also that we have requested to include the aspect names in the response. We can use the include JSON body parameter to return additional information. This works in the same way as in the /nodes/{id}/children method in the core API.

Here is how the call looks like, assuming that we have stored the query JSON data in a file called type-and-aspect-query.json:

$ curl -X POST -H 'Content-Type: application/json' -H 'Accept: application/json' --header 'Authorization: Basic VElDS0VUXzIxYzAzOWMxNjFjYzljMDNmNmNlMzAwYzAyMDY5YTQ2OTQwZmYzZmM=' --data-binary '@type-and-aspect-query.json' 'http://localhost:8080/alfresco/api/-default-/public/search/versions/1/search' | jq
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  1046    0   755  100   291  21571   8314 --:--:-- --:--:-- --:--:-- 29885
{
  "list": {
    "pagination": {
      "count": 1,
      "hasMoreItems": false,
      "totalItems": 1,
      "skipCount": 0,
      "maxItems": 10
    },
    "entries": [
      {
        "entry": {
          "isFile": true,
          "createdByUser": {
            "id": "admin",
            "displayName": "Administrator"
          },
          "modifiedAt": "2019-10-04T08:38:15.321+0000",
          "nodeType": "acme:document",
          "content": {
            "mimeType": "text/plain",
            "mimeTypeName": "Plain Text",
            "sizeInBytes": 61,
            "encoding": "ISO-8859-1"
          },
          "parentId": "3e59f24a-3a5b-4370-b98e-10e5514ac24e",
          "aspectNames": [
            "cm:versionable",
            "cm:titled",
            "cm:auditable",
            "acme:securityClassified",
            "cm:author"
          ],
          "createdAt": "2019-10-04T08:38:15.321+0000",
          "isFolder": false,
          "search": {
            "score": 1
          },
          "modifiedByUser": {
            "id": "admin",
            "displayName": "Administrator"
          },
          "name": "anotherfile.txt",
          "location": "nodes",
          "id": "9b045d17-1aa4-4296-80e1-d7a39e858585"
        }
      }
    ]
  }
}

We can see in the response JSON that the aspectNames array contains the aspect we were matching.