I run three different N1QL query and it result look like below
First Result:
{
"clicks": 12688190,
"m": 2,
"revenue": 51668.07,
"y": 2016 }
Second Result :
{
"Signups": 45,
"m": 2,
"y": 2016 },
Third Result :
{
"Deposits": 1,
"m": 2,
"y": 2016 }
I want output like below
{
"Deposits": 1,
"clicks": 12688190,
"Signups": 45,
"m": 2,
"y": 2016 }
How can I join this Differen result in N1QL ??
You can combine subquery results with Couchbase 4.5.1.
SELECT OBJECT_CONCAT( (subquery1)[0], (subquery2)[0], (subquery3)[0] );
Related
"response": {
"numFound": 2,
"start": 0,
"docs": [
{
"total_amountA": 10,
"total_amountB": 5,
"id": "2"
},
{
"total_amountA": 10,
"total_amountB": 5,
"id": "1"
}
]
}
i want to get the sum of all tatal_amount.
like this -> total_amountA : 20, total_amountB : 10
how can i get the sum of all value..? plese help me
The Stats Component gives you a set of statistics for a given field for a given query.
http://localhost:8983/solr/corename/select?q=your:query&stats=true&stats.field=total_amount
Should give you an additional stats key in the response with sum among the values calculated.
i should take a JSON value, like
{
"cnt": 5
}
and create JSON object from JSONata, like
{
"1": 1,
"2": 4,
"3": 9,
"4": 16,
"5": 25,
}
I tried to do that, but i cant join two expressions correctly.
{
"" & [1..cnt] : [1..cnt].($*$)
}
and i get as a result:
{
"[1,2,3,4,5]": [
1,
4,
9,
16,
25
]
}
Can anybody help me with this(
Try [1..cnt]{$string($): $*$}
See https://try.jsonata.org/SVapg4fzt
{
"timeStamp": 1593664441878,
"timingRecords": [
{
"task": "extendedClean",
"time": 31,
"modules": [
"main"
]
},
{
"task": "clean",
"time": 35,
"modules": [
"lint"
]
},
{
"task": "compile",
"time": 35,
"modules": [
"test"
]
}
]
}
This is my json data in the table. I have multiple rows of similar records.
I am looking for a result as the sum of all times where task in (extendedClean, clean)
So my final expected result would look like
timestamp | sum(time)
1593664441878| 66
1593664741878| 22
It's a bit unclear how you need that in the context of a complete query. But given a single JSON value as shown in your question, you can do this:
select sum( (e ->> 'time')::int )
from the_table
cross join jsonb_array_elements(the_json_column -> 'timingRecords') as e
where e ->> 'task' in ('extendedClean', 'clean');
Online example
for example, I have six documents here there:
{"task_id": 1, "frame": 1, "job_id": 1},
{"task_id": 1, "frame": 1, "job_id": 1},
{"task_id": 1, "frame": 1, "job_id": 3},
{"task_id": 2, "frame": 1, "job_id": 2},
{"task_id": 2, "frame": 1, "job_id": 3},
{"task_id": 3, "frame": 1, "job_id": 3},
I want get the count of documents with the same task_id.
the expect result must be (the key is "task_id"):
[
{"key": 1, "doc_count": 2},
{"key": 2, "doc_count":2},
{"key": 3, "doc_count":1}
]
Note:the first document and the second document all value is same, so it only calculate once.
So how can I write query in elasticsearch? I can easy write it in SQL, but I puzzled in Elasticsearch.
my mysql query is:
select tmp.task_id, count(*) from (select distinct task_id,frame,job_id from mytable) as tmp group by tmp.task_id
You want to use a terms aggregation on the task_id + frame + job_id fields (using a script), and you'll get the doc_count you are expecting.
curl -XPOST localhost:9200/your_index/_search -d '{
"size" 0,
"aggs" : {
"tasks" : {
"terms" : { "script" : "[doc.task_id.value, doc.frame.value, doc.job_id.value].join(',')" }
}
}
}'
Note that in order to run this, you need to enable dynamic scripting.
I'm coding in C# for the .NET Framework 3.5.
I am trying to parse some Json to a JObject.
The Json is as follows:
{
"TBox": {
"Name": "SmallBox",
"Length": 1,
"Width": 1,
"Height": 2 },
"TBox": {
"Name": "MedBox",
"Length": 5,
"Width": 10,
"Height": 10 },
"TBox": {
"Name": "LargeBox",
"Length": 20,
"Width": 20,
"Height": 10 }
}
When I try to parse this Json to a JObject, the JObject only knows about LargeBox. The information for SmallBox and MedBox is lost. Obviously this is because it is interpreting "TBox" as a property, and that property is being overwritten.
I am receiving this Json from a service that's coded in Delphi. I'm trying to create a C# proxy for that service. On the Delphi-side of things, the "TBox" is understood as the type of the object being returned. The inner properties ("Name", "Length", "Width", "Height") are then understood as regular properties.
I can serialize and deserialize a custom 'TBox' object that has Name, Length, Width, and Height properties. That's fine.
What I want to do is step through all the TBox sections in such a way as to extract the following three Json strings.
First:
{
"Name": "SmallBox",
"Length": 1,
"Width": 1,
"Height": 2 }
Second:
{
"Name": "MedBox"
"Length": 5,
"Width": 10,
"Height": 10 }
Third:
{
"Name": "LargeBox"
"Length": 20,
"Width": 20,
"Height": 10 }
Once I have these strings, I can serialize and deserialize to my heart's content.
I'm finding Newtonsoft.Json to be very good. I really don't want to go messing about with other frameworks if I can avoid it.
Any help would be greatly appreciated.
I have very limited input as to changes that can be made to the server.
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
JsonTextReader jsonReader = new JsonTextReader(reader);
jsonReader.Read();
while(jsonReader.Read())
{
if(jsonReader.TokenType == JsonToken.StartObject)
{
JObject tbox = JObject.Load(jsonReader);
}
}
However, note that the RFC says, "The names within an object SHOULD be unique" so if you can, recommend the format be changed.
EDIT: Here's an alternate design that doesn't have duplicate keys:
[
{
"TBox": {
"Width": 1,
"Length": 1,
"Name": "SmallBox",
"Height": 2
}
},
{
"TBox": {
"Width": 10,
"Length": 5,
"Name": "MedBox",
"Height": 10
}
},
{
"TBox": {
"Width": 20,
"Length": 20,
"Name": "LargeBox",
"Height": 10
}
}
]
If I'm not mistaken, the correct answer to this is that your input is not actually JSON. So no, getting a JSON parser to parse it probably isn't going to work.
Maybe you don't have any control over the source of the input, so I'd use a Regex or something to pre-filter the string. Turn it into something like:
{"TBoxes":
[
{
"Name": "SmallBox",
"Length": 1,
"Width": 1,
"Height": 2
},
{
"Name": "MedBox",
"Length": 5,
"Width": 10,
"Height": 10
},
{
"Name": "LargeBox",
"Length": 20,
"Width": 20,
"Height": 10
}
]
}
And treat it like the array that it is.