{
"_id": ObjectId("5efb3d1a9ed984485c1a0d25"),
"monthlyVideoStatistics": [
{
"likes": 60,
"_id": ObjectId("5efc5aa1f232f87f944501e1"),
"startDateRange": ISODate("2020-03-01T00:00:00.000Z"),
"endDateRange": ISODate("2020-03-31T23:59:59.999Z"),
"month": 3,
"year": 2020
},
{
"likes": 80,
"_id": ObjectId("5efc5a7eaeded6697c688049"),
"startDateRange": ISODate("2020-04-01T00:00:00.000Z"),
"endDateRange": ISODate("2020-04-30T23:59:59.999Z"),
"month": 4,
"year": 2020
},
{
"likes": 75,
"_id": ObjectId("5efcac3c6f91307578019717"),
"startDateRange": ISODate("2020-05-01T00:00:00.000Z"),
"endDateRange": ISODate("2020-05-31T23:59:59.999Z"),
"month": 5,
"year": 2020
}
]
}
I am having a JSON object like this.
Here I need to compare the likes in month 4(April) were greater or less than in month 3(march)
Is it possible to get the particular array object id or like greater true or false something like that?
here a month, likes are referred to as the field name.
so if need to compare likes in month 3 with month 4, if it will be greater then return the document data or some value like greater
Related
Input is as follows:
[
{
"sid": 101,
"sname": "Rahul",
"sem": 1,
"marks": 9
},
{
"sid": 102,
"sname": "Rahul",
"sem": 2,
"marks": 9.5
},
{
"sid": 102,
"sname": "Rahul",
"sem": 3,
"marks": 8
},
{
"sid": 101,
"sname": "Rahul",
"sem": 4,
"marks": 7
}
]
I need to get the total number of marks based on the sid attribute.
You can group by the sid then for each sid sum all the marks.
%dw 2.0
output application/json
---
payload
groupBy ($.sid)
mapObject ($$): sum($.*marks)
Output:
{
"101": 16,
"102": 17.5
}
Note that if you are going to use this information for further processing it will be more efficient to output to application/java instead of JSON.
Alternatively if you prefer to have a list with one element per sid you can use pluck().
%dw 2.0
output application/json
---
payload
groupBy ($.sid)
pluck { sid: ($$), marksTotal: sum($.*marks) }
Output:
[
{
"sid": "101",
"marksTotal": 16
},
{
"sid": "102",
"marksTotal": 17.5
}
]
I am working with a CosmosDB setup by one of my colleagues and connecting to it using a connection string. The database contains several JSON documents with the following schema:
{
"period": "Raw",
"source": "Traffic",
"batchId": "ee737270-0b72-49b7-a2f1-201f642e9c81",
"periodName": "Raw",
"sourceName": "Traffic",
"groupKey": "gc4151_a",
"partitionKey": "traffic-gc4151_a-raw-raw",
"time": "2021-08-05T23:55:10",
"minute": 55,
"hour": 23,
"day": 05,
"month": 08,
"quarter": 3,
"year": 2021,
"minEventTime": "2021-08-05T23:55:09",
"maxEventTime": "2021-08-05T23:55:11",
"meta": {
"siteId": "GC4151_A",
"from": {
"lat": "55.860894822588506",
"long": "-4.284365958508686"
},
"to": {
"lat": "55.86038667864348",
"long": "-4.2826901232101795"
}
},
"measurements": {
"flow": [
{
"calculation": "Raw",
"name": "flow",
"calculationName": "Raw",
"value": 0
}
],
"concentration": [
{
"calculation": "Raw",
"name": "concentration",
"calculationName": "Raw",
"value": 0
}
]
},
"added": "2021-08-05T12:21:32.000819Z",
"updated": "2021-08-05T12:21:32.000819Z",
"id": "d4346f50-543e-4c4d-82cf-835b480914c2",
"_rid": "4RRTAIYVA1AIAAAAAAAAAA==",
"_self": "dbs/4RRTAA==/colls/4RRTAIYVA1A=/docs/4RRTAIYVA1AIAAAAAAAAAA==/",
"_etag": "\"1c0015a1-0000-1100-0000-5f3fbc4c0000\"",
"_attachments": "attachments/",
"_ts": 1598012492
}
I am trying to write a SQL query to select all the records that fall between the current date-time and one week earlier, so I can use these to perform future calculations.
I have attempted to use both of the following:
SELECT *
FROM c
WHERE c.time > date_sub(now(), interval 1 week);
and
SELECT *
FROM c
WHERE c.time >= DATE_ADD(CURDATE(), INTERVAL -7 DAY);
However, both of these return the following error:
Gateway Failed to Retrieve Query Plan: Message: {"errors":[{"severity":"Error","location":{"start":124,"end":125},"code":"SC1001","message":"Syntax error, incorrect syntax near '1'."}]}
ActivityId: 51c3b6f7-e760-4062-bd80-8cc9f8de5352, Microsoft.Azure.Documents.Common/2.14.0, Microsoft.Azure.Documents.Common/2.14.0
My question is what is the issue with my code, and how can I fix it?
You may use DateTimeAdd and GetCurrentDateTime() to achieve this. Eg.
SELECT *
FROM c
WHERE c.time > DateTimeAdd("day",-7,GetCurrentDateTime() )
Let me know if this works for you.
I have been working on Jolt transformation from yesterday and unable to find a solution to achieve following output.
I would like to insert "year","month","day" into each map (dictionary) of "records" list.
Input
[{"root":
{"body":
{"year":2019,
"month":8,
"day":9,
"records":[
{"user":"a",
"item":"x",
"price":300,
"count":1},
{"user":"b",
"item":"y",
"price":100,
"count":3}]
}
}
}]
Desired Output
[{"user":"a",
"item":"x",
"price":300,
"count":1,
"year":2019,
"month":8,
"day":9},
{"user":"b",
"item":"y",
"price":100,
"count":3,
"year":2019,
"month":8,
"day":9}
]
I could insert value of "year", "month","day" into outside of each map as list like {"record":[[2019,8,9],{map1},{map2}]}, but this is not what I want.
I appreciate for any help or advice. And thank you in advance.
This should do what you want:
Solution (Explanation inline):
[
{
"operation": "shift",
"spec": {
"*": {
"root": {
"body": {
"records": {
//match records array
"*": {
//copy object user, item etc. to current position
"#": "[&1]",
//go up two levels and get year and place it in current array position
"#(2,year)": "[&1].year",
"#(2,month)": "[&1].month",
"#(2,day)": "[&1].day"
}
}
}
}
}
}
}
]
Output:
[
{
"user": "a",
"item": "x",
"price": 300,
"count": 1,
"year": 2019,
"month": 8,
"day": 9
},
{
"user": "b",
"item": "y",
"price": 100,
"count": 3,
"year": 2019,
"month": 8,
"day": 9
}
]
I am using the Azure index for an index search. My objective behind the Index search is to retrieve the Unique records depend upon some unique parameter say System_ID and I started using facets feature for this, but when using it I am unable to retrieve more than 10 unique facets despite providing a count value to 20 in the query.
Below is the summary:
I am able to retrieve only 10 unique records even though more than 10 unique records are there in Index.
When i modify the count property of facet to 20 Still I am getting only 10 records
Can you please help with me to modify it in such a way that I will get more than 10 records.
Any help will be appreciable.
Default query:
$filter=(systemID ne null) and (ownerSalesforceRecordID eq 'a0h5B000000gJKfQAM')&facet=machineTagSystemID,sort:value&queryType=full
Default Results:
{"machineTagSystemID": [
{
"count": 9,
"value": "ABCS test machines-111-test - change|*1XA78RUGV23PVPN"
},
{
"count": 6,
"value": "Ajit Machine testing1jjcdxxxxxxxxxxxxxx|*1L693D439H5ZNG9"
},
{
"count": 19,
"value": "Anvesh test111dsaa|*13SSNP5AJ3L96C5"
},
{
"count": 3,
"value": "Dead End cross 2|*1NK7KNNLFVTM4QC"
},
{
"count": 3,
"value": "hehehe|*1NDC32TDNXT5RAH"
},
{
"count": 14,
"value": "high2 Machine12345678ppjk fvrf|*1T2F3VQEJ58ZLQL"
},
{
"count": 31,
"value": "prashant dev machine 213|*12L343TZTFGH3M6"
},
{
"count": 1,
"value": "ryansjcilaptop465986543|*1E2PG9V3BMEYDM7"
},
{
"count": 12,
"value": "snehali DEV June|*1QXEDL8E2V8MGBY"
},
{
"count": 27,
"value": "tarun Machine-dev|*1YRPHS3J7NGUVA8"
}
]}
Facet with count:
$filter=(systemID ne null) and (ownerSalesforceRecordID eq 'a0h5B000000gJKfQAM')&facet=machineTagSystemID,sort:value,count:20&queryType=full
But same results:
{"machineTagSystemID": [
{
"count": 9,
"value": "ABCS test machines-111-test - change|*1XA78RUGV23PVPN"
},
{
"count": 6,
"value": "Ajit Machine testing1jjcdxxxxxxxxxxxxxx|*1L693D439H5ZNG9"
},
{
"count": 19,
"value": "Anvesh test111dsaa|*13SSNP5AJ3L96C5"
},
{
"count": 3,
"value": "Dead End cross 2|*1NK7KNNLFVTM4QC"
},
{
"count": 3,
"value": "hehehe|*1NDC32TDNXT5RAH"
},
{
"count": 14,
"value": "high2 Machine12345678ppjk fvrf|*1T2F3VQEJ58ZLQL"
},
{
"count": 30,
"value": "prashant dev machine 213|*12L343TZTFGH3M6"
},
{
"count": 1,
"value": "ryansjcilaptop465986543|*1E2PG9V3BMEYDM7"
},
{
"count": 12,
"value": "snehali DEV June|*1QXEDL8E2V8MGBY"
},
{
"count": 27,
"value": "tarun Machine-dev|*1YRPHS3J7NGUVA8"
}
]}
This is based on the documentation link: https://learn.microsoft.com/en-us/azure/search/search-faceted-navigation
Facets honor the filter specified in a query. It's possible this is why you are only seeing 10 unique facet value for this field. Generally speaking, your query looks fine. If there were more than 10 unique values in this field for the query specified, I would expect them to show up.
How many total results are returned by this query? I see 125 total values in the facets you provided and I'm wondering if the count aligns with your results.
Mike
This is old but I hit the same issue - there is a default limit of 10 values returned in a facet, you can extend this to return more facet values by adding a count to a given facet. E.g.:
facet=Month,count:12&search=something
This can also be done in the c# API by just adding the count to the facet name:
var options = new SearchOptions();
options.Facets.Add("Month,count:12");
I have this type of ouput genral
"docs": [
{
"id": "552e1acd5971b",
"product_id": "NOT05253",
"attribute_id": 0,
"attribute_name": "Brend",
"value_id": 12923,
"value_name": "ACER",
"category_id": 166,
"_version_": 1498504104368930800
},
{
"id": "552e1acd7d479",
"product_id": "NOT05604",
"attribute_id": 0,
"attribute_name": "Brend",
"value_id": 12923,
"value_name": "ACER",
"category_id": 166,
"_version_": 1498504104523071500
},
{
"id": "552e1acdc9c7c",
"product_id": "NOT05988",
"attribute_id": 0,
"attribute_name": "Brend",
"value_id": 12923,
"value_name": "ACER",
"category_id": 166,
"_version_": 1498504104851275800
},
{
"id": "552e1acdef261",
"product_id": "NOT06361",
"attribute_id": 0,
"attribute_name": "Brend",
"value_id": 12923,
"value_name": "ACER",
"category_id": 166,
"_version_": 1498504105011708000
}, .....
What I'm trying to do is getting results where product_id match at leas one product_id in another query...
category_id:166 AND value_id:12923
AND product_id:( _query_:"value_id:64 " )
I'm using this for making EAV product filtering faster, and this query particular has to shorten product_id count of ACER notebook in variation with 15.6" screen size :)
Another words - something like SQL query:
SELECT * FROM table WHERE value_id=12923 AND product_id IN (SELECT product_id FROM table WHERE value_id=64)
Any toughts? :D
Solr has some Join capabilities described here [1]. It could be what you're looking for.
About the other clauses: I would use a filter query (i.e. fq=value_id:12923)
[1] https://wiki.apache.org/solr/Join