Skip to main content
Nov 27, 2023 10:22 PM UTC

GraphQL filter on _metadata

We have a requirement for filtering content fragment by created date and last modified date, which are stored in the _metadata. Since it's an out of the box field, we are unable to apply any filters against it. Is there a workaround for this? Our other option is to filter dates after querying the entire data, but we'd like to avoid this if possible.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

18 replies

krati_garg
Adobe Employee
Adobe Employee
Dec 1, 2023 3:36 PM UTC

@dsong12 Can you please share the Filter query you are using?

Translate
Level 2
Dec 12, 2023 9:17 AM UTC

dear, krati,  We have a requirement for filtering content fragment by  start date and end date, also OR title, content, but it is not work, colud you help to suggest for me ? 

 

Translate
Level 2
Dec 12, 2023 9:18 AM UTC

@krati_garg 

Translate
varun_m1
Level 2
Jan 10, 2024 11:43 AM UTC

Hi @dsong12 ,

From what I understand working on the GraphQL query editor in AEM is that the _metadata is only available in the ModelResults Type and not the ModelFilter Type, this means that you would not be able to filter your content fragments based on the 'created by' and 'last modified' date since they are a part of _metadata. 

You can also check and confirm this in the Docs section in your GraphQL query editor.

Translate
Level 2
Jan 11, 2024 2:26 AM UTC

hi, @varun_m1  may i use  'last modified' date to order  in graphql ?

Translate
varun_m1
Level 2
Jan 12, 2024 7:06 AM UTC

Hi @onech, after doing some hands-on on this one, I noticed that the sort takes up String value of a model attribute, but the problem now arises that there's no way to exactly target the last modified date because the query and json response pair as follows,

_metadata{ calendarMetadata{ name value }"_metadata": { "calendarMetadata": [ { "name": "jcr:created", "value": "2023-09-25T12:39:11.047+05:30" }, { "name": "cq:lastPublished", "value": "2023-09-26T11:55:04.939Z" }, { "name": "cq:lastModified", "value": "2023-09-26T11:55:04.486Z" } ]

and if I try to sort it based on this sort in the query,

sort:"_metadata.calendarMetadata.name"

it actually sorts the content fragments based on the jcr:created property. 

 

Translate
kautuk_sahni
Level 9
Feb 21, 2024 11:47 AM UTC

@dsong12 Did you find the suggestions from users helpful? Please let us know if more information is required. Otherwise, please mark the answer as correct for posterity. If you have found out solution yourself, please share it with the community.

Translate
Kautuk Sahni
New Member
May 20, 2024 1:43 PM UTC

Hello! Did you find any workaround for your problem? I have same issues here

Translate