SOLR, SQL how to present nested JSON data? - json

I would like to understand how to work and present a nested JSON data.
If I have a JSON like :
{
"name": "John"
,"address":
{
"street" : "st. Yanica"
,"city" : "Moscow"
}
}
How I can configure the JSON in schema.xml in order to integrate it in SOLR and in order to obtain a response having the same presentation.
The data are coming from database and I would like to present them as the JSON here above so that when a search is done, the response contain the adress with the fields street and city nested under address :
{
"name": "John"
,"address":
{
"street" : "st. Yanica"
,"city" : "Moscow"
}
}
Thanks

Related

How to make model from two requests Flutter

How to make model to post Json made from two Json files?
I make first request and get this Json
{
"id": 123123,
"materials" : {
"meta" : {
"href" : "https://products-link.com/materials",
"size" : 1,
},
}
}
Then using link "href" : "https://products-link.com/materials" from first Json i'm making second request and get second Json
{
"name": "assembling",
"product" : "product name"
}
Then i need to replace data in "materials" in first Json with second Json and get this
{
"id": 123123,
"materials" : {
"name": "assembling",
"product" : "product name"
}
}
Hello ,multi-way to create JSON to dart model
1: Using this https://jsontodart.com/ converter, this converter converts JSON to dart model file with the class
2: Using this package https://pub.dev/packages/json_to_model
Thank you

How to configure the path in LookupRecord NiFi

I have a Json file in my database, the structure is like this:
{
"employeeId": "ref-123",
"name": "Danie",
"manager": {
"employeeId": "ref-456",
"name": "John"
}
}
I want to do a lookup in the lookupRecord to let it find the manager name based on the manager Id. Here is the configuration of the lookupRecord.
I added a customer property which is employeeId, and the path is /manager/employeeId. But I cannot get the the name (which is John).
So how can I configure the path, because the value I want to find is embedded in the "manager".
Assuming you are using mongoDB, for the lookupService.
I reproduced your flow:
generateFlowFile : { "manager": { "employeeId": "ref-123" } }
LookupRecord
ResultRecord Path, where you want to put the lookup result in your flowfile.
employeeid, what to look for in your flowFile and send it to the lookup service.
On mongodb side, I have the following document :
{ "_id" : { "$oid" : "5fb6932c01e6ef0027e0af5b" },
"employeeId" : "ref-123",
"name" : "Danie",
"manager" :
{ "employeeId" : "ref-456", "name" : "John" } }
Lookup service is configured as the following (if you use mongodb):
Finally I have this output :
[{"manager":{"employeeId":"ref-123","name":"Danie"}}]
Tell me if it helps you.

Reading JSON data from BLOB

Edit - oracle version 19c
I am uploading a json file using Browse file type in APEX and then storing it in a table as BLOB.
The Table looks like this -
File_ID Filename Mime_type created_on blob_content
1 file_new.json application/json 9/1/2020 (BLOB)
Now i want to parse this and read the contents of blob as a table in oracle. How can i do it?
The Json file looks like this but has hundred of rows.
[{"Id":"50021","eName":"random123", "Type":"static","Startdate":"07/03/2020","Enddate":"08/02/2020,"nominations":[{"nominationId":"152","nominationMaxCount":7500,"offer":[{"Id":"131","Type":"MONEY","clientId":41,
"stateExclusions":[],"divisionInclusions":["111","116","126","129"]]}]
Step One - add an IS JSON check constraint to your BLOB_CONTENT column.
ALTER TABLE CLOBS
ADD CONSTRAINT CLOB_JSON CHECK
(CLOBS IS JSON)
ENABLE; -- yes my table name and my column are both named CLOBS
Step Two - Add some data.
The database provides native SQL calls to parse/query JSON content in your BLOB.
My data, a single row. This JSON document has a couple of simple arrays.
{
"results" : [
{
"columns" : [
{
"name" : "REGION_ID",
"type" : "NUMBER"
},
{
"name" : "REGION_NAME",
"type" : "VARCHAR2"
}
],
"items" : [
{
"region_id" : 1,
"region_name" : "Europe"
},
{
"region_id" : 2,
"region_name" : "Americas"
},
{
"region_id" : 3,
"region_name" : "Asia"
},
{
"region_id" : 4,
"region_name" : "Middle East and Africa"
}
]
}
]
}
I can use the jsonv_value() function if I want to pull a single attribute out, and I can reference those using $. notation. I reference arrays as you'd expect.
select json_value(CLOBS,'$.results.columns[0].name') FIRST_COLUMN,
json_value(CLOBS,'$.results.columns[1].name') SECOND_COLUMN
from CLOBS
where ID = 1;
The results -
Our product architect (Beda) has a great blog series with much better examples than this.

How to Retrieve and Query JSON type fields in Apache Solr 6.5

My Goal is to retrieve JSON type fields in an Solr index and also perform search queries on such fields.
I have the following documents in Solr Index and using the auto generated schema utilizing schemaless feature in Solr.
POST http://localhost:8983/solr/test1/update?commitWithin=1000
[
{"id" : "1", "type_s":"book", "title_t" : "The Way of Kings", "author_s" : "Brandon Sanderson",
"miscinfo": {"provider": "orielly", "site": "US"}
},
{"id" : "2", "type_s":"book", "title_t" : "The Game of Thrones", "author_s" : "James Sanderson",
"miscinfo": {"provider": "pacman", "site": "US"}
}
]
I see the JSON types are stored as strings in the schemaField type as seen in the output for following
GET http://localhost:8983/solr/test1/schema/fields
{
"name":"miscinfo",
"type":"strings"}
I had tried using srcField as mentioned in this post. However, a query to retrieve json type returns empty response. Below are the GET request used for the same
GET http://localhost:8983/solr/test1/select?q=1&fl=miscinfo&wt=json
GET http://localhost:8983/solr/test1/select?q=1&fl=miscinfo,source_s:[json]&wt=json
Also, the search queries for values inside JSON type fields return empty response
http://localhost:8983/solr/test1/select?q=pacman&wt=json
{
"responseHeader": {
"status": 0,
"QTime": 0,
"params": {
"q": "pacman",
"json": "",
"wt": "json"
}
},
"response": {
"numFound": 0,
"start": 0,
"docs": []
}
}
Please help in searching object types in Solr.
Have you checked this: https://cwiki.apache.org/confluence/display/solr/Response+Writers
JSON Response Writer A very commonly used Response Writer is the
JsonResponseWriter, which formats output in JavaScript Object Notation
(JSON), a lightweight data interchange format specified in specified
in RFC 4627. Setting the wt parameter to json invokes this Response
Writer. Here is a sample response for a simple query like
q=id:VS1GB400C3&wt=json:

Express JS fetch proper JSON with Mysql

I am working on WebAPI on ExpressJS. I am fetching data from MySQL database by using node module mysql. I have a mater and a detail table let say
Countries(ID, Name, Code)
States (ID, Name, CountryId)
Now I want to query the data in JSON as following:
{
"country":{
"ID" : 1,
"Name" : "United States of America"
"Code" : "USA"
"Cities" :
[
{
"1",
"Alabama",
"AL"
},
{
"2",
"Alaska",
"AK"
},
{
"3",
"California",
"CA"
}
]
}
}
How can I query data in the above format?
Thanks and Regards.
How can I query data in the above format?
You can't because this is not a valid JSON. No matter what you do, you will never be able to represent your data in that format.
To represent data coming from a relational database as a JavaScript nested objects and arrays, it will be easiest to use an ORM like Sequelize, Bookshelf, ORM2 or Waterline. See:
http://docs.sequelizejs.com/
http://bookshelfjs.org/
https://github.com/dresende/node-orm2
http://sailsjs.com/documentation/reference/waterline-orm
ORM is an Object-Relational Mapper and lets you map the relational model to objects, which is exactly what you're trying to do here.