AEM - Adding date range in QuerybuilderAPI | Community
Skip to main content
Level 2
August 24, 2020
Solved

AEM - Adding date range in QuerybuilderAPI

  • August 24, 2020
  • 3 replies
  • 4338 views

I have the below query I am using in /libs/cq/search/content/querydebug.html to check the results

 

1_property=test 1_property.value=active 2_property=status 2_property.value=worked p.hits=selective p.limit=-1 path=/home/users type=rep:User

 

This is working and i am getting results .Now I need the records who has a property registrationCompletedDate = 2020-08-09 to know the users registered on 9th.

Can someone help how I can add this date range in my query?

I tried this, but did not work

 

daterange.upperBound=2020-08-10
daterange.lowerBound=2020-08-9
daterange.property=registrationCompletedDate

 

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

Hi @p_vishnu,

Given that we are looking for exact match on a Date property, we can bring in the search results with "property" predicate itself instead of Date related predicates like daterange/relativedaterange/dateComparsion where first two works on range and last works on comparison of two Date type properties.

Try the below sample query and let know if it works

To bring in all pages which has property of type "Date" + name "registrationCompletionDate" + value like 2020-08-09 (in jcr:content of page)

path=/content/we-retail
type=cq:Page
property=@jcr:content/registrationCompletionDate
property.value=2020-08-09% // assuming Time is different and date is 2020-08-09
property.operation=like

3 replies

Adobe Employee
August 24, 2020

Check this sample:

path=/content
type=cq:PageContent
group.p.or=true
group.1_daterange.property=cq:lastModified
group.1_daterange.upperBound=2017-04-21T23:59:59.000-04:00
group.1_daterange.lowerBound=2017-04-21T00:00:00.000-04:00

group.2_daterange.property=jcr:created
group.2_daterange.upperBound=2017-04-21T23:59:59.000-04:00
group.2_daterange.lowerBound=2017-04-21T00:00:00.000-04:00
p.limit=-1

Adobe Employee
August 24, 2020
you are challenging a custom property registrationCompletedDate, it is "Date" Type or is it a "String" Type?
Adobe Employee
August 24, 2020

Assuming that the property "registrationCompletedDate' in with rep:User node, the query should be similar to 

path=/home/users
type=rep:User

daterange.property=registrationCompletedDate
daterange.upperBound=2020-08-19T23:59:59.000-04:00
daterange.lowerBound=2020-08-19T00:00:00.000-04:00

p.limit=-1

 

Now, you need to have an index for registrationCompletedDate, it should be similar to

- compatVersion = 2
- async = "async"
- jcr:primaryType = oak:QueryIndexDefinition
- evaluatePathRestrictions = true
- type = "lucene"
+ indexRules
+ rep:User
+ properties
+ registrationCompletedDate
- name = "registrationCompletedDate"
- propertyIndex = true

 

 

 

 

 

Vijayalakshmi_S
Vijayalakshmi_SAccepted solution
Level 10
August 25, 2020

Hi @p_vishnu,

Given that we are looking for exact match on a Date property, we can bring in the search results with "property" predicate itself instead of Date related predicates like daterange/relativedaterange/dateComparsion where first two works on range and last works on comparison of two Date type properties.

Try the below sample query and let know if it works

To bring in all pages which has property of type "Date" + name "registrationCompletionDate" + value like 2020-08-09 (in jcr:content of page)

path=/content/we-retail
type=cq:Page
property=@jcr:content/registrationCompletionDate
property.value=2020-08-09% // assuming Time is different and date is 2020-08-09
property.operation=like