I getting data in array like
[
{
"category_id": "Glass_Door_Handle",
"category_name": "Glass Door Handle",
"product_name": [
{
"product_id": "SP-001",
"name": "RENUALT-SOLID-MD",
"image": "http://127.0.0.1:8000/media/1-1_aIzfcnG.jpg",
"size": [
"http://127.0.0.1:8000/api/sizemattcp/7/"
],
"timestamp": "2016-01-14T05:33:44.107117Z",
"updated": "2016-01-14T05:33:44.107142Z"
}
]
}
]
I want to data in
{
"category_id": "Glass_Door_Handle",
"category_name": "Glass Door Handle",
"product_name": [
{
"product_id": "SP-001",
"name": "RENUALT-SOLID-MD",
}
]
}
I am using readonlyViewModel
It seems you are calling your api like:
/api/models/?filter=value
And it returns your a list of objects, which contains only one element. To get a single object, just append its primary key to the url:
/api/models/1234/
If you want to get models not by id but by some other field, use the ViewSet.lookup_field parameter to specify the name of that field.
Related
I am trying to execute a AWS api via step function. I need to pass the authorizationToken value in the header field.
{
"ApiEndpoint": "ccqk9ijm0h.execute-api.ap-southeast-2.amazonaws.com",
"Method": "POST",
"Headers": {
"authorizationToken.$": [
"$.InputToken"
]
},
"Stage": "test",
"Path": "/",
"RequestBody": {
"productType": [],
"xxx.$": "$.xxx",
"yyy.$": "$.yyy",
"zzz.$": "$.zzz"
},
"AuthType": "IAM_ROLE"
}
I am getting the following error -
The value for the field 'authorizationToken.$' must be a STRING that contains a JSONPath but was an ARRAY (at /States/GetDeclarations/Parameters)
This is the default syntax for the API invoke -
"Headers": {
"Header1": [
"HeaderValue1"
],
"Header2": [
"HeaderValue2",
"HeaderValue3"
]
}
When i modify this to
"Headers": {
"authorizationToken": [
"1234"
],
"Header2": [
"HeaderValue2",
"HeaderValue3"
]
}
It works fine.
I need to make the value of "authorizationToken" a variable that takes its value from the input.
My Input data looks like this
{
"xxx": "123",
"yyy": "123",
"zzz": "123",
"InputToken": "123",
"aaa": "123"
}
You need to use the States.Array Intrinsic Function as I've shown below. This allows you to inject an array into a node in your Parameters block. In this case, you just want a single item in the array, but you can include multiple items as well (e.g., States.Array($.item1,$.item2,$.item3)).
Check out the other Intrinsic Functions as well, as they are handy for overcoming challenges like this.
{
"ApiEndpoint": "ccqk9ijm0h.execute-api.ap-southeast-2.amazonaws.com",
"Method": "POST",
"Headers": {
"authorizationToken.$": "States.Array($.InputToken)"
},
"Stage": "test",
"Path": "/",
"RequestBody": {
"productType": [],
"xxx.$": "$.xxx",
"yyy.$": "$.yyy",
"zzz.$": "$.zzz"
},
"AuthType": "IAM_ROLE"
}
I used "https://localhost:9443/t/carbon.super/scim2/Bulk" to upload bulk users to WSO2IS. How to add organization,email and mobileno to following data set.
Here is my data object.
{
"failOnErrors": 1,
"schemas": [
"urn:ietf:params:scim:api:messages:2.0:BulkRequest"
],
"Operations": [
{
"method": "POST",
"path": "/Users",
"bulkId": "qwerty1",
"data": {
"schemas": [
"urn:ietf:params:scim:schemas:core:2.0:User",
"urn:ietf:params:scim:schemas:extension:enterprise:2.0:User"
],
"userName": "Alexwso26.com",
"password": "12345678",
"name": {
"givenName": "Alex26 ",
"familyName": "Silva26"
},
"emails": [
{
"type": "home",
"value": "Alex26#g.com",
"primary": true
}
]
}
}
]
}
It is working fine. But email didn't update.
From your user creation payload, it updates the user's home email. If you Navigate to the Management console -> Main menu -> Claims -> List -> "http://wso2.org/claims" -> Emails - Home Email-> Edit and tick Supported by Default, and view that created user's profile. You can see that the given value has been updated.
Change the email attribute like the following payload. Then you can update the Email attribute of the user. Also, the following payload contains the attribute format for mobile number and organization.
{
"failOnErrors": 1,
"schemas": [
"urn:ietf:params:scim:api:messages:2.0:BulkRequest"
],
"Operations": [
{
"method": "POST",
"path": "/Users",
"bulkId": "qwerty1",
"data": {
"schemas": [
"urn:ietf:params:scim:schemas:core:2.0:User",
"urn:ietf:params:scim:schemas:extension:enterprise:2.0:User"
],
"userName": "Alexwso26.com",
"password": "12345678",
"name": {
"givenName": "Alex26 ",
"familyName": "Silva26"
},
"emails": [
{
"value": "Alex26#g.com",
"primary": true
}
],
"phoneNumbers": [
{
"value": "0771234567",
"type": "mobile"
}
],
"urn:ietf:params:scim:schemas:extension:enterprise:2.0:User" : {
"organization": "abc"
}
}
}
]
}
Refer to the following documents when forming payload when creating or managing users/groups via SCIM endpoint.
https://anuradha-15.medium.com/how-to-add-scim-extended-attributes-in-wso2-identity-server-71621f62c5d3
https://www.rfc-editor.org/rfc/rfc7643
I'm getting JSON data from webservice and trying to make a table . Datadisk is presented as List and clicking into each item will navigate further down the hiearchy like denoted in screenshots below. I need to concatate storageAccountType for each item with | sign, so if there were 2 list items for Greg-VM and it had Standard_LRS for first one and Premium_LRS for second one then new column will list Standard_LRS | Premium_LRS for that row.
Input returned by function is below
[
{
"name": "rhazuremspdemo",
"disk": {
"id": "/subscriptions/24ba3e4c-45e3-4d55-8132-6731cf25547f/resourceGroups/AzureMSPDemo/providers/Microsoft.Compute/disks/rhazuremspdemo_OsDisk_1_346353b875794dd4a7a5c5938abfb7df",
"storageAccountType": "StandardSSD_LRS"
},
"datadisk": []
},
{
"name": "w12azuremspdemo",
"disk": {
"id": "/subscriptions/24ba3e4c-45e3-4d55-8132-6731cf25547f/resourceGroups/AzureMSPDemo/providers/Microsoft.Compute/disks/w12azuremspdemo_OsDisk_1_09788205f8eb429faa082866ffee0f18",
"storageAccountType": "Premium_LRS"
},
"datadisk": []
},
{
"name": "Greg-VM",
"disk": {
"id": "/subscriptions/24ba3e4c-45e3-4d55-8132-6731cf25547f/resourceGroups/GREG/providers/Microsoft.Compute/disks/Greg-VM_OsDisk_1_63ed471fef3e4f568314dfa56ebac5d2",
"storageAccountType": "Premium_LRS"
},
"datadisk": [
{
"name": "Data",
"createOption": "Attach",
"diskSizeGB": 10,
"managedDisk": {
"id": "/subscriptions/24ba3e4c-45e3-4d55-8132-6731cf25547f/resourceGroups/GREG/providers/Microsoft.Compute/disks/Data",
"storageAccountType": "Standard_LRS"
},
"caching": "None",
"toBeDetached": false,
"lun": 0
},
{
"name": "Disk2",
"createOption": "Attach",
"diskSizeGB": 10,
"managedDisk": {
"id": "/subscriptions/24ba3e4c-45e3-4d55-8132-6731cf25547f/resourceGroups/GREG/providers/Microsoft.Compute/disks/Disk2",
"storageAccountType": "Standard_LRS"
},
"caching": "None",
"toBeDetached": false,
"lun": 1
}
]
}
]
How do I do that?
Thanks,
G
This should help you. It steps through the process.
If you have a scenario like this
you can use Add custom Column and type the follwing expression:
=Table.Columns([TableName], "ColumnName")
to get it as list:
Now you can left click on the Custom column and chose Extract Values....
Choose Custom and your delimiter | and hit OK
This way the data who was in your list will now be in the same row with the delimiter
I would like to serve my visitors the best results possible when they use our search feature.
To achieve this I would like to interpret the search query.
For example a user searches for 'red beds for kids 120cm'
I would like to interpret it as following:
Category-Filter is "beds" AND "children"
Color-filter is red
Size-filter is 120cm
Are there ready to go tools for Elasticsearch?
Will I need NLP in front of Elasticsearch?
Elasticsearch is pretty powerful on its own and is very much capable of returning the most relevant results to full-text search queries, provided that data is indexed and queried adequately.
Under the hood it always performs text analysis for full-text searches (for fields of type text). A text analyzer consists of a character filter, tokenizer and a token filter.
For instance, synonym token filter can replace kids with children in the user query.
Above that search queries on modern websites are often facilitated via category selectors in the UI, which can easily be implemented with querying keyword fields of Elasticsearch.
It might be enough to model your data correctly and tune its indexing to implement the search you need - and if that is not enough, you can always add some extra layer of NLP-like logic on the client side, like #2ps suggested.
Now let me show a toy example of what you can achieve with a synonym token filter and copy_to feature.
Let's define the mapping
Let's pretend that our products are characterized by the following properties: Category, Color, and Size.LengthCM.
The mapping will look something like:
PUT /my_index
{
"mappings": {
"properties": {
"Category": {
"type": "keyword",
"copy_to": "DescriptionAuto"
},
"Color": {
"type": "keyword",
"copy_to": "DescriptionAuto"
},
"Size": {
"properties": {
"LengthCM": {
"type": "integer",
"copy_to": "DescriptionAuto"
}
}
},
"DescriptionAuto": {
"type": "text",
"analyzer": "MySynonymAnalyzer"
}
}
},
"settings": {
"index": {
"analysis": {
"analyzer": {
"MySynonymAnalyzer": {
"tokenizer": "standard",
"filter": [
"MySynonymFilter"
]
}
},
"filter": {
"MySynonymFilter": {
"type": "synonym",
"lenient": true,
"synonyms": [
"kid, kids => children"
]
}
}
}
}
}
}
Notice that we selected type keyword for the fields Category and Color.
Now, what about these copy_to and synonym?
What will copy_to do?
Every time we send an object for indexing into our index, value of the keyword field Category will be copied to a full-text field DescritpionAuto. This is what copy_to does.
What will synonym do?
To enable synonym we need to define a custom analyzer, see MySynonymAnalyzer which we defined under "settings" above.
Roughly, it will replace every token that matches something on the left of => with the token on the right.
How will the documents look like?
Let's insert a few example documents:
POST /my_index/_doc
{
"Category": [
"beds",
"adult"
],
"Color": "red",
"Size": {
"LengthCM": 150
}
}
POST /my_index/_doc
{
"Category": [
"beds",
"children"
],
"Color": "red",
"Size": {
"LengthCM": 120
}
}
POST /my_index/_doc
{
"Category": [
"couches",
"adult",
"family"
],
"Color": "blue",
"Size": {
"LengthCM": 200
}
}
POST /my_index/_doc
{
"Category": [
"couches",
"adult",
"family"
],
"Color": "red",
"Size": {
"LengthCM": 200
}
}
As you can see, DescriptionAuto is not present in the original documents - though due to copy_to we will be able to query it.
Let's see how.
Performing the search!
Now we can try out our index with a simple query_string query:
POST /my_index/_doc/_search
{
"query": {
"query_string": {
"query": "red beds for kids 120cm",
"default_field": "DescriptionAuto"
}
}
}
The results will look something like the following:
"hits": {
...
"max_score": 2.3611186,
"hits": [
{
...
"_score": 2.3611186,
"_source": {
"Category": [
"beds",
"children"
],
"Color": "red",
"Size": {
"LengthCM": 120
}
}
},
{
...
"_score": 1.0998137,
"_source": {
"Category": [
"beds",
"adult"
],
"Color": "red",
"Size": {
"LengthCM": 150
}
}
},
{
...
"_score": 0.34116736,
"_source": {
"Category": [
"couches",
"adult",
"family"
],
"Color": "red",
"Size": {
"LengthCM": 200
}
}
}
]
}
The document with categories beds and children and color red is on top. And its relevance score is twice bigger than of its follow-up!
How can I check how Elasticsearch interpreted the user's query?
It is easy to do via analyze API:
POST /my_index/_analyze
{
"text": "red bed for kids 120cm",
"analyzer": "MySynonymAnalyzer"
}
{
"tokens": [
{
"token": "red",
"start_offset": 0,
"end_offset": 3,
"type": "<ALPHANUM>",
"position": 0
},
{
"token": "bed",
"start_offset": 4,
"end_offset": 7,
"type": "<ALPHANUM>",
"position": 1
},
{
"token": "for",
"start_offset": 8,
"end_offset": 11,
"type": "<ALPHANUM>",
"position": 2
},
{
"token": "children",
"start_offset": 12,
"end_offset": 16,
"type": "SYNONYM",
"position": 3
},
{
"token": "120cm",
"start_offset": 17,
"end_offset": 22,
"type": "<ALPHANUM>",
"position": 4
}
]
}
As you can see, there is no token kids, but there is token children.
On a side note, in this example Elasticsearch wasn't able, though, to parse the size of the bed: token 120cm didn't match to anything, since all sizes are integers, like 120, 150, etc. Another layer of tweaking will be needed to extract 120 from 120cm token.
I hope this gives an idea of what can be achieved with Elasticsearch's built-in text analysis capabilities!
If an article has several comments (think thousands over time). Should data.relationships.comments return with a limit?
{
"data": [
{
"type": "articles",
"id": 1,
"attributes": {
"title": "Some title",
},
"relationships": {
"comments": {
"links": {
"related": "https://www.foo.com/api/v1/articles/1/comments"
},
"data": [
{ "type": "comment", "id": "1" }
...
{ "type": "comment", "id": "2000" }
]
}
}
}
],
"included": [
{
"type": "comments",
"id": 1,
"attributes": {
"body": "Lorem ipusm",
}
},
.....
{
"type": "comments",
"id": 2000,
"attributes": {
"body": "Lorem ipusm",
}
},
]
}
This starts to feel concerning, when you think of compound documents (http://jsonapi.org/format/#document-compound-documents). Which means, the included section will list all comments as well, making the JSON payload quite large.
If you want to limit the number of records you get at a time from a long list use pagination (JSON API spec).
I would load the comments separately with store.query (ember docs), like so -
store.query('comments', { author_id: <author_id>, page: 3 });
which will return the relevant subset of comments.
If you don't initially want to make two requests per author, you could include the first 'page' in the authors request as you're doing now.
You may also want to look into an addon like Ember Infinity (untested), which will provide an infinite scrolling list and automatically make pagination requests.