How to configure the path in LookupRecord NiFi - json

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.

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

Setting a value into a json using jsonPath in karate

I have the below Json File(Test.json) read into a variable in karate
TestInput.json:
{
"firstName": "John",
"lastName" : "doe",
"age" : 26,
"address" : {
"streetAddress": "naist street",
"city" : "Nara",
"postalCode" : "630-0192"
},
"phoneNumbers": [
{
"type" : "Mobile",
"number": "0123-4567-8888"
},
{
"type" : "home",
"number": "0123-4567-8910"
}
]
}
I intend to change the value of Mobile number within my karate code and use the Json as my request with the following lines
Karate Code:
* def reqJson = read('TestInput.json')
* karate.set('reqJson','$.phoneNumbers[?(#.type=="Mobile")].number',"999999999")
Then print reqJson
The output of the print statement doesn't have the json updated with the number for Mobile.
Alternatively, I've also used the below line to set the variable, but this hasn't worked either:
* set reqJson.phoneNumbers[?(#.type=="Mobile")].number = "99999999"
Is this possible via Karate? If Yes can someone please point me to the place where I'm going wrong or an alternative approach to achieve my scenario.
Thanks.
You can't use JsonPath to mutate. Directly access the path or use a map() operation: https://github.com/karatelabs/karate#json-transforms
This is just one example assuming the JSON is in a variable called body. Take some time to get used to JSON transforms.
* body.phoneNumbers = body.phoneNumbers.map(x => { x.number = '999'; return x })

Importing CSV File in Elasticsearch

I am new to elasticsearch. Trying to import CSV file by following the guide
And successfully imported the file and it has created an index with the documents also.
But what I found that in every docs _id contains random unique id as a value. I want to have value of _id from the CSV file field (the CSV file which I'm importing contains a field with unique id for every row) using query or any other ways. And I do not know how to do that.
Even in docs it is not explained. A sample example of document of elasticsearch index is shown below
{
"_index" : "sample_index",
"_type" : "_doc",
"_id" : "nGHXgngBpB_Kjkqcxfj",
"_score" : 1.0,
"_source" : {
"categoryid" : "34128b58-9148-11eb-a8b3-0242ac130003",
"categoryname" : "Blogs",
"isdeleted" : "False"
}
while adding ingest pipeline with the following query
{
"set": {
"field": "_id",
"value": "{{categoryid}}"
}
}
it throwing an error with this message
You can achieve this by modifying the ingest pipeline used to ingest your CSV file.
In the Ingest pipeline area (Advanced section), simply add the following processor at the end of the pipeline and the document ID will be set accordingly:
...
{
"set": {
"field": "_id",
"value": "{{categoryid}}"
}
}
It should look like this:
Added following processor in ingest pipeline section and it works..
{
"processors": [
{
"set": {
"field": "_id",
"value": "{{categoryid}}"
}
}
]
}

JPath for partial query match

I'm trying to learn json jpath query. I have successfully been able to return data based on exact searches.
For example at the site: https://jsonpath.com/ I can successfully retrieve the type of phone based on phone number:
JSON
{
"firstName": "John",
"lastName" : "doe",
"age" : 26,
"address" : {
"streetAddress": "naist street",
"city" : "Nara",
"postalCode" : "630-0192"
},
"phoneNumbers": [
{
"type" : "iPhone",
"number": "0123-4567-8888"
},
{
"type" : "home",
"number": "0123-4567-8910"
}
]
}
Query
$.[?(#.number== '0123-4567-8888')].type
However I can't find any examples that show me how to match a partial search result. I'm trying to write a query where I provide just "0123" and hence get back both "home" and "iPhone" returned as results.How can I do this?
You can use =~ match filter operator which allows providing a regular expression instead of strict value so given you amend your query like:
$.phoneNumbers[?(#.number=~/.*0123.*/)].type
you will get both types as the result:
More information: JMeter's JSON Path Extractor Plugin - Advanced Usage Scenarios

SOLR, SQL how to present nested JSON data?

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