Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn more

View all

Sign in to view all badges

SOLVED

AEM - Adding date range in QuerybuilderAPI

P_Vishnu
Level 2
Level 2

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

 

AEM querybuilder
1 Accepted Solution
Vijayalakshmi_S
Correct answer by
Community Advisor
Community Advisor

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

View solution in original post

6 Replies
berliant
Employee
Employee

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

P_Vishnu
Level 2
Level 2

@berliantI added the below to my query

 

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

 

But it is not giving me any results

berliant
Employee
Employee
you are challenging a custom property registrationCompletedDate, it is "Date" Type or is it a "String" Type?
berliant
Employee
Employee

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

 

 

berliant_0-1598301950572.png

 

berliant_1-1598302015327.png

 

 

Vijayalakshmi_S
Correct answer by
Community Advisor
Community Advisor

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

View solution in original post