achint
May 18, 2018, 10:42am
1
Hi,
I am trying to access inner object with the below written query but i am not able to understand what i am doing wrong.
query = QueryBuilder.select(SelectResult.all()).from(DataSource.database(database))
.where(ArrayExpression.any(ArrayExpression.variable("SYNONYMS")).in(Expression.property("synonymsTest"))
.satisfies(Function.lower(ArrayExpression.variable("SYNONYMS.synonyms")).like(Expression.string(term + "%")))
.or(Function.lower(Expression.property("labtest_name")).like(Expression.string(term + "%")))).limit(Expression.intValue(30));
Please let me know what is wrong above written query. I am trying to query below written document.
{
"components": [
{
"component_name": "lactate dehydrogenase"
}
],
"labtest_name": "Serum lactate dehydrogenase",
"synonymsTest": [
{
"synonyms": "serum ldh"
},
{
"synonyms": "lactate dehydrogenase, serum or plasma"
}
],
"timestamp": 1515069417,
"type": "labtest",
"uid": "0072a140-c95b-40bd-8d0e-1aff1e6b7897"
}
Couple of things
I think your variable definition isn’t correct. For clarity, I would recommend declaring the variables separately and then using it within your Query .
VAR_SYNONYMSENTRY = ArrayExpression.variable("synonymsEnry")
VAR_SYNONYMS = ArrayExpression.variable("synonymsEnry.synonyms")
query = QueryBuilder.select(SelectResult.all()).from(DataSource.database(database))
.where(ArrayExpression.any(VAR_SYNONYMSENTRY).in(Expression.property("synonymsTest"))
.satisfies(Function.lower(VAR_SYNONYMS )).like(Expression.string(term + "%")))
.or(Function.lower(Expression.property("labtest_name")).like(Expression.string(term + "%")))).limit(Expression.intValue(30));
Also, for starters, I would start simple instead of having many conditionals w/ pattern matching. So try something a bit more straightforward and see if you get results.
query = QueryBuilder.select(SelectResult.all()).from(DataSource.database(database))
.where(ArrayExpression.any(VAR_SYNONYMSENTRY).in(Expression.property("synonymsTest"))
.satisfies(VAR_SYNONYMS .equalTo(Expression.string("serum ldh")))
@priya.rajagopal thanks for your help. Thanks alot.
i got the same issue, i proceed exactly like priya said but i didn’t got any result. Please what is the problem
Please provide details of your query, an example of document that you are querying against , the expected results and the results you observe
@priya.rajagopal This is what I am looking so far. thanks a lot for your solutions.
Here I have one more requirement.
If json look like below
{
"components": [
{
"component_name": "lactate dehydrogenase"
}
],
"labtest_name": "Serum lactate dehydrogenase",
"synonymsTest": [
{
"synonyms": "serum ldh",
"createdate" : ""2018-11-12T10:15:57.568Z""
},
{
"synonyms": "lactate dehydrogenase, serum or plasma"
"createdate" : ""2018-11-13T11:15:57.568Z""
}
],
"timestamp": 1515069417,
"type": "labtest",
"uid": "0072a140-c95b-40bd-8d0e-1aff1e6b7897"
}
On above query, i want to check “synonyms”: “serum ldh”, On which is recently created under synonymsTest array. I mean first, we need to sort synonymsTest array based on createddate key and then check our condition on the first record of the array.