I'm running Queries on Couchbase Server Query on Complex JSON,
{
"fname": "saksham",
"lname": "handu",
"dateOfBirth": {
"day": 30,
"month": 11,
"year": 1996
}
}
I'm running
`SELECT * from `bucket-name` where fname="saksham";
But it's not showing above JSON as a result. If I remove dateOfBirth from JSON, then fire the same query, it's showing the JSON then. Can someone help here?
Moreover, how to write Queries on year in dateOfBirth?
Related
First time post, so please pardon my format. Will try to provide as much detail as I can. I'm using CF 2018 and receiving a JSON file with data around employees. I can handle the API call to get it, but need some advice on how to best process it.
Here's the JSON file:
{
"Report_Entry": [
{
"Account_Group": "HEALTH GROUP",
"Group": "SERVICES GROUP",
"Employee_ID": "111111",
"Legal_Name_-_First_Name": "Ted",
"Worker_Skills_as_Text": "Programmer",
"Certification": "ICAgile Certified Professional (ICP) - The International Consortium for Agile",
"primaryWorkEmail": "ted_smith#abc.com"
},
{
"Account_Group": "FINANCE GROUP",
"Group": "INNOVATION TEAM",
"Employee_ID": "222222",
"Legal_Name_-_First_Name": "Mary",
"Worker_Skills_as_Text": "Analyst",
"Certification": "PMP; Writing Master",
"primaryWorkEmail": "mary_smith#abc.com"
},
{
"Account_Group": "ENERGY GROUP",
"Group": "BUSINESS DEVELOPMENT TEAM",
"Employee_ID": "333333",
"Legal_Name_-_First_Name": "John",
"Worker_Skills_as_Text": "Developer",
"Certification": "Certified Scrum Master (CSM) - Scrum Alliance; Certified Scrum Product Owner (CSPO) - Scrum Alliance",
"primaryWorkEmail": "john_smith#abc.com"
}
]
}
When I deserialize it returns as as:
I need to be able to loop through the structure, arrays, and the structure to capture the values then process them (i.e., insert into a table, compare to existing data, etc.). I know I need to loop through the entire thing but can't come up with the right syntax with error.
Any help or examples would be greatly appreciated.
Thanks
Jim
Here is what I've been using for dealing with something similar:
Based on your dump, you have a struct with an array of structs.
the following is a snippet that should return the first element of the array, which is a struct:
myStruct = Report_entry[1];
for (currentKey in myStruct) {
writedump(currentKey);
writedump(myStruct[currentKey]);
writeoutput('<hr>');
}
you want to get the syntax of looping over arrays and looping over structs.
CFDUMP is your friend.
I'd be happy to help with syntax. I recognize I did not provide a complete solution, but you are a little closer.
I just trained my LUIS application and published it to production. If I test it on an utterance, I can see how that result compares to the published version and look at the JSON result. The problem is I'm getting a completely different JSON result there than I get when I query the API via its URL. Here is the test result JSON:
{
"query": "please show me *johnson*",
"prediction": {
"normalizedQuery": "please show me *johnson*",
"topIntent": "Show",
"intents": {
"Show": {
"score": 0.985523641
}
},
"entities": {
"ShowObject": [
"*johnson*"
],
"$instance": {
"ShowObject": [
{
"type": "ShowObject",
"text": "*johnson*",
"startIndex": 15,
"length": 9,
"score": 0.8382344,
"modelTypeId": 1,
"modelType": "Entity Extractor",
"recognitionSources": [
"model"
]
}
]
}
}
}
}
and here is the API query result:
{
"query": "please show me *johnson*",
"topScoringIntent": {
"intent": "Show",
"score": 0.985523641
},
"intents": [
{
"intent": "Show",
"score": 0.985523641
}
],
"entities": [
{
"entity": "* johnson *",
"type": "ShowObject",
"startIndex": 15,
"endIndex": 23,
"score": 0.8382344
}
]
}
The problem with the API query result is that it doesn't return enough information about the entity, and it returns a different entity than the test result. Note above that the test result returns *johnson* with no spaces near the asterisks, which is how the original query is, but the API query result returns * johnson * with spaces near the asterisks. I don't want it to put the spaces in, so I prefer the test result over the API query result.
Why are they different, and how do I get the API query to return a result like the test, i.e. with no modification of the input string to add spaces near the asterisks.
Here is the API query URL including parameters:
https://westus.api.cognitive.microsoft.com/luis/v2.0/apps/[app ID removed]?q=please+show+me+*johnson*&timezoneOffset=0&verbose=true&spellCheck=false&staging=false
Oh, I see now - this is probably to represent a wildcard search, right? If so, I'm not personally aware of a way to strip this out of a LUIS response, and I've seen similar, I think, when there's an #mention in there as well. However, if this is to facilitate searches, such that you know there's a good chance to have a * before and/or after the "ShowObject" entity, then it should be easy enough to test for this and replace, either string or regex (replace the "star-plus-space" with a space, I mean - I realise you need the star itself). Basically, you'd replace "[start][space]" with "[start]", and same at the end. Not pretty, but workable and simple to implement...
Just out of interest, do you anticipate * in the middle of a string as well?
I have a CouchDB database, which uses a query language Mango - which seems to be the same as Cloudant's query language.
I'm trying to search and compare two fields to each other and only return the relevant results when they're equal.
For example:
{
"_id": "ACCEPT0",
"_rev": "1-92ea4e727271aefd0a2befed0d4bb736",
"OfferID": "OFFER0"
}
{
"_id": "ACCEPT1",
"_rev": "3-986ca6e717b225ac909d644de54d5f7d",
"OfferID": "OFFER3"
}
{
"_id": "OFFER0",
"_rev": "1-2af5f5c7b1c59dd3f0997f748a367cb2",
"From": "merchant1",
"To": "customer1"
}
{
"_id": "OFFER1",
"_rev": "6-f0927c5d4f9fd8a2d2b602f1c265d6d5",
"From": "merchant1",
"To": "customer2"
}
I trying to come up with a query which will, in this example, return "OFFER0" - since OFFER0 exists in an "OfferID"
EDIT (clarification): The query needs to be able to select all the _id's which begin with OFFER and which exist in an OfferID field.
I know I can set this up with a view (as seen from: Cloudant query to return records where 2 fields are equal), but I need this in a Mango query as it'll be running over Hyperledger
You can easily return documents whose _id field starts with "OFFER" with the following query:
{
"selector": {
"_id": {
"$regex": "^OFFER"
}
}
}
but this is likely to be inefficient because Cloudant has to scan the whole database, testing each documents _id field with that regular expression.
A better way to design your data may be to have a type field which distinguishes between the document types in your database e.g.
{
"_id": "OFFER0",
"_rev": "1-2af5f5c7b1c59dd3f0997f748a367cb2",
"type": "offer",
"From": "merchant1",
"To": "customer1"
}
and then a query to return all documents where type = 'offer' becomes:
{
"selector": {
"type": "offer"
}
}
I don't fully understand the part of the question where you say "which exist in an OfferID field." but it's important to note that Cloudant Query & Mango can only query single documents - you can't say "get me all the documents which are offers, where another document has a certain property". Include all the data you need in each document and then you'll be able to query it cleanly.
I know this is complex but please bear with me..........
I am building a Restful application. I have a specific requirement where there is a column named handle in my database. I need to store values like*(1,2,3,4)* in that column.
I am using spring mvc ,hibernate and eclipse as my IDE. I am also using PostMan Client. I read about hibernate spatial data type and i decided to go with that however i am not being able to store the data in database.
I have been sending a json request containing data to my application through postman client in order to save those data to database .However i am not being able to do this?? What is the problem??..
This is my Json
{
"operations": [
{
"operationType": 0,
"objectType": 2,
"data": {
"idNum": 212632034672,
"data": {
"radius": 80.11865321153431,
"strokeWidth": 5,
"stroke": "green"
},
"handle": {
"x": 223,
"y": 102
},
"parentId": 1
}
}
],
"projectGuid": "ff8081814521f6ce014521f7756f0000"
}
I know the problem lies in handle part but i have not been able to solve it.......
Following is part of my model:-
#Column(name = "handle",columnDefinition="Geometry")
#Type(type = "org.hibernate.spatial.GeometryType")
private Point handle;
P.S. I am using org.hibernatespatial.mysql.MySQLSpatialInnoDBDialect in my jpaContext.xml file and i already have hibernate-spatial-4.0.jar in my class path already
I am new to using Mule and having a problem with outputting nested Json. I am using mule 3.3 and the GUI interface. I add the database component to my flow and run some simple SQL including a 'one to many' join. After this I added an 'Oject to Json' component, the problem is the resulting JSON is flat it does not nest the 'one to many' elements. For example I expect:
{
"firstName": "John",
"phoneNumber": [
{
"type": "home",
"number": "212 555-1234"
},
{
"type": "fax",
"number": "646 555-4567"
}
]
}
I actually get:
{
"firstName": "John",
"type": "home",
"number": "212 555-1234"
}
Can anyone give me any direction on what I am missing?
Since you haven't posted your configuration, it's hard to tell exactly what you're doing. Anyways...
The select query returns a flat view of the users data. If you want to create a structured representation of it, you'll have to create a transformer to do so, prior to serializing to JSON.
Alternatively, you can use an ORM to map your data to objects then serialize these objects to JSON.