GraphQL filter on _metadata | Community
Skip to main content
November 27, 2023

GraphQL filter on _metadata

  • November 27, 2023
  • 4 replies
  • 3475 views

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.

4 replies

krati_garg
Adobe Employee
Adobe Employee
December 1, 2023

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

Level 2
December 12, 2023

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 ? 

 

Level 2
December 12, 2023
varun_m1
Level 2
January 10, 2024

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.

Level 2
January 11, 2024

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

varun_m1
Level 2
January 12, 2024

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. 

 

kautuk_sahni
Community Manager
Community Manager
February 21, 2024

@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.

Kautuk Sahni
New Member
May 20, 2024

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