How can I use the jsonb query functions to get matching TrackingDetails from the whole table, when the jsonb field in my table contains json in this format? For example, I have an order_events table, with a column called event_data, that will contain this json:
{
"Responses": [
{
"Response": {
"TrackingDetails": {
"IntegrationId": "IntegrationId",
"MessagePart": 0,
"MessageTotal": 0,
"MessageGroupId": "MessageGroupId",
"SequenceNumber": "SequenceNumber",
"InterfaceRecordId": "InterfaceRecordId",
"SalesOrderNumber": "SalesOrderNumber",
"SalesOrderReference": "SalesOrderReference",
"DispatchNumber": "DispatchNumber",
"Courier": "Courier",
"TrackingNumber": "TrackingNumber",
"TrackingUrl": "TrackingUrl"
}
}
}
]
}
I would like to get the TrackingDeatils as a Json node, by TrackingNumber, across all rows in the table. It would include multiple rows matched. Thanks for any help.
Related
We have a scenario in a service that accepts multiple types of data and we want to store in ElasticSearch so we can benefit from its search capabilities.
Data could be a String, Number, Object or an Array of objects as the following:
POST my-index/_doc/1
{
"additionalData": [
{
"values": {
"some-field": "some-value",
"some-other-field": "some-value"
}
}
]
}
POST my-index/_doc/1
{
"additionalData": [
{
"values": [12345, 9875]
}
]
}
POST my-index/_doc/1
{
"additionalData": [
{
"values": "Some text"
}
]
}
Is there a way to store that in elasticSearch? or better to store in other NoSQL Databases like Mongodb?
PS: we are using Es 7.x, and would like to keep using ES.
If you don't need to search on those values, it's possible with a disabled field (i.e. not indexed, not stored)
However, if you want to search on those value, it's not possible. Each field must have a specific type (object, numeric, text, etc) and then you can only store values of that type in the field.
I have a cluster with documents, with one field being an array of long types. Below is an example value of this field:
"request_categories": [
150848602323501540,
150847029425938900
],
When I query the field, it does not return anything. Below is the query.
GET service_alias/service/_search
{
"query": {
"term": {
"request_categories" : 150848602323501540
}
}
}
This data field is indexed. I have no problems querying other data fields. Anything that I may have missed? Thanks!
hi i'm using spring data in My project and I'm trying group by two fields, heres the request:
#Query( "SELECT obj from Agence obj GROUP BY obj.secteur.nomSecteur,obj.nomAgence" )
Iterable<Agence> getSecteurAgenceByPc();
but it doesnt work for me..what i want is this result:
-Safi
-CTM
CZC1448YZN
2UA13817KT
-Rabat
-CTM
CZC1349G1B
2UA0490SVR
-Agdal
G3M4NOJ
-Essaouira
-CTM
CZC1221B85
-Gare Routiere Municipale
CZC145YL3
What I get is
{
"status": 0,
"data":
[
{
"secteur": "Safi",
"agence": "CTM"
},
{
"secteur": "Safi",
"agence": "Dep"
},
{
"secteur": "Rabat",
"agence": "Agdal"
},
{
"secteur": "Rabat",
"agence": "CTM"
},
{
"secteur": "Essaouira",
"agence": "CTM"
},
{
"secteur": "Essaouira",
"agence": "Gare Routiere Municipale"
}
]
}
What you want is not possible with JPQL.
What does Group By do?
It combines all rows that are identical in the columns in the group by clause in to one row. Since it combines multiple rows into one, data in other columns can only be present in some combined fashion. For example, you can include MIN/MAX or AVG values, but never the orginal values.
Also the result with always be a table, never a tree.
Also note: there is no duplicated data. Every combination of secteur and agence appears exactly once.
If you want a tree structure, you have to write some java code for that.
What exactly I wanna do is, I want to make dynamic query in laravel 5.3 based on requested parameters , so in request i will get column names then filters for that query and I don't know tables from which I want to process the data.
So, my question is how to decide the tables for that query ?
or should I store table and respective columns in one database's table and match the requested parameters with that table so that I will get table name and will able to put in that query?
But I thought this will cost my processing ? so that's why I post this question. please help me with best scenario that will fit with my requirment for dynamic query?
Update
the request will be like this
{
"col": ['fname', 'lname'],
"offset": 1,
"limit": 25,
"order": [ASC, fname, lname],
"filter": [
{
"col": "id",
"op": "=",
"val": 8
}
]
}
so this is my request and table name and related columns are in one table.
Just use query builders.
$query = DB::table($tableName);
// ...some logic...
foreach ($filters as $filter) {
$query->where($filter['col'], $filter['op'], $filter['val']);
}
// ...more logic...
if (isset($limit)) {
$query->limit($limit);
}
if (isset($columns)) {
// get desired columns
$records = $query->get($columns);
} else {
$records = $query->get();
}
This is a sample row in my RethinkDB table.
{
"a1": "val1" ,
"a2": "val2" ,
"a3": "val3" ,
"a4": "val4" ,
"part": [
{
"id": "reql" ,
"position": "student"
} ,
{
"id": "sdsadda" ,
"position": "officer"
}
] ,
"a5": "val5"
}
I want to access a nested json object but I get the error e: Cannot perform bracket on a non-object non-sequence "string"
I need the entire row in the output for rows matching id to "reql"
This is my query
r.db('dbname').table('tablename').filter(r.row('part').contains(function(product) {
return product('id').eq("reql");
}))
This query worked before .It doesn't right now.
You'd get that error if you'd somehow ended up with an element in your part array that's a string instead of an object. Try running .filter(r.row('part').contains(function(product) { return product.typeOf().ne('OBJECT'); }), that should return all the rows that have a string in the part array.
Regarding your comment #Puja, I think this should do it for you:
r.db('dbname').table('tablename').filter(function(d){
d("part").typeOf().eq("ARRAY");
}).filter(r.row('part').contains(function(d) {
return d('id').eq("reql");
}))
Although, this is less efficient than #mlucy's answer, and you should definitely just do the one pass over your dataset to clean it up by fixing all the documents where part: STRING.