vamshi9666
5 years agoGuide
time constraint in v2 json query
i am trying to get occasions with ```end_time``` constraint using "GET" /search/2.0 query as follows:
<code>
var liql = "SELECT body, cover_image, subject,occasion_data.rsvp.user, occasion_data.location FROM messages where occasion_data.end_time >= " + currentDate
$http({
url: '/api/2.0/search?q=' + liql,
dataType: 'json',
method: 'GET',
contentType: "application/json",
}).then(function(response) {
</code>
with this way, i am able to get data but nested queries can't be achieved.
To do so , i tried json based query as follows :
<code>
var jsonQuery = [{
messages: {
fields: ["occasion_data", "body", "cover_image", "subject"],
constraints: [{
"occasion_data.end_time": {
">=": new Date().toISOString()
}
}]
}
}]
</code>
but this time time constraints wont work and throw error.
I solved this by using converting time value into unix timestrap format by Date.now().
updated query looks like :
<code>
var currentDate = Date.now()var liql = "SELECT body, cover_image, subject,occasion_data.rsvp.user, occasion_data.location FROM messages where occasion_data.end_time >= " + currentDatevar jsonQuery = [{messages: {fields: ["occasion_data", "body", "cover_image", "subject", "occasion_data.rsvp"],constraints: [{"occasion_data.end_time": {">=": currentDate}}]}}]</code>