Google Datastore Use Select Query by ID using API in GAS - google-app-engine

I wish the Google API documentation was a little more newbie-proof.
I've worked my way through Selecting all entities, Updating an entity, inserting, and deleting. Now I would like to start selecting specific entities by criteria. The API https://datastore.googleapis.com/v1/projects/project-id-5200707080506492774:runQuery is for this purpose, and if I provide the payload of "query: {}" I get all entities. I can also filter by Kind. But I cannot figure out how to filter by a property. I try to get an entity by name with this JSON stringified payload:
var payload =
{
"query": {
"kind": [
{
"name": "Test"
}
],
"filter": {
"propertyFilter": {
"property": {
"name": "id"
},
"op": "EQUAL",
"value": {
"stringValue": "5634472569470976"
}
}
}
}
}
But I get the 200 results batch:
{
"batch": {
"entityResultType": "FULL",
"endCursor": "CgA=",
"moreResults": "NO_MORE_RESULTS"
}
}
AKA: Nothing was found.
Could someone enlighten me with regards to how to select by the entity's name/id or other field of data?
EDIT:
Here is the file structure of my entities. They are organized under the kind Test:
{
"batch": {
"entityResultType": "FULL",
"entityResults": [
{
"entity": {
"key": {
"partitionId": {
"projectId": "project-id-5200707080506492774"
},
"path": [
{
"kind": "Test",
"id": "5634472569470976"
}
]
},
"properties": {
"test": {
"stringValue": "Hi it is me"
}
}
},
"cursor": "CjsSNWogc35wcm9qZWN0LWlkLTUyMDA3MDcwODA1
MDY0OTI3NzRyEQsSBFRlc3QYgICAgN6QgQoMGAAgAA==",
"version": "1503343869436000"
},
{
"entity": {
"key": {
"partitionId": {
"projectId": "project-id-5200707080506492774"
},
"path": [
{
"kind": "Test",
"id": "5639445604728832"
}
]
},
"properties": {
"test": {
"stringValue": "testtesttest"
}
}
},
"cursor": "CjsSNWogc35wcm9qZWN0LWlkLTUyMDA3MDcwODA1MDY0OTI3NzRyEQsSBFRlc3QYgICAgLyhggoMGAAgAA==",
"version": "1503343008992000"
},
{
"entity": {
"key": {
"partitionId": {
"projectId": "project-id-5200707080506492774"
},
"path": [
{
"kind": "Test",
"id": "5649391675244544"
}
]
},
"properties": {
"test": {
"stringValue": "testtest"
}
}
},
"cursor": "CjsSNWogc35wcm9qZWN0LWlkLTUyMDA3MDcwODA1MDY0OTI3NzRyEQsSBFRlc3QYgICAgPjChAoMGAAgAA==",
"version": "1503342946693000"
},
{
"entity": {
"key": {
"partitionId": {
"projectId": "project-id-5200707080506492774"
},
"path": [
{
"kind": "Test",
"id": "5659313586569216"
}
]
},
"properties": {
"test": {
"stringValue": "testtesttest"
}
}
},
"cursor": "CjsSNWogc35wcm9qZWN0LWlkLTUyMDA3MDcwODA1MDY0OTI3NzRyEQsSBFRlc3QYgICAgNrjhgoMGAAgAA==",
"version": "1503343059530000"
},
{
"entity": {
"key": {
"partitionId": {
"projectId": "project-id-5200707080506492774"
},
"path": [
{
"kind": "Test",
"id": "5715999101812736"
}
]
},
"properties": {
"test": {
"stringValue": "hello world"
}
}
},
"cursor": "CjsSNWogc35wcm9qZWN0LWlkLTUyMDA3MDcwODA1MDY0OTI3NzRyEQsSBFRlc3QYgICAgLzVkwoMGAAgAA==",
"version": "1503343819165000"
}
],
"endCursor": "CjsSNWogc35wcm9qZWN0LWlkLTUyMDA3MDcwODA1MDY0OTI3NzRyEQsSBFRlc3QYgICAgLzVkwoMGAAgAA==",
"moreResults": "NO_MORE_RESULTS"
}
}
Edit:
I completed a filter query to check against my test field, as requested, and got the below 200 response:
{
"batch": {
"entityResultType": "FULL",
"entityResults": [
{
"entity": {
"key": {
"partitionId": {
"projectId": "project-id-5200707080506492774"
},
"path": [
{
"kind": "Test",
"id": "5715999101812736"
}
]
},
"properties": {
"test": {
"stringValue": "hello world"
}
}
},
"cursor":
"CjsSNWogc35wcm9qZWN0LWlkLTUyMDA3MDcwODA
1MDY0OTI3NzRyEQsSBFRlc3QYgICAgLzVkwoMGAAgAA==",
"version": "1503343819165000"
}
],
"endCursor": "CjsSNWogc35wcm9qZWN0LWlkLTUyMDA3MDcwODA1MDY0OTI3NzRyEQsSBFRlc3QYgICAgLzVkwoMGAAgAA==",
"moreResults": "NO_MORE_RESULTS"
}
}

At least in the ndb python datastore library id is not allowed as a property name. Which might be the reason your query is not working (as you expect) either.
After all you don't see any property named id within the properties structures of your entities, it is actually part of the key -> path structure.
Just to confirm, try using a valid property (i.e. one listed inside properties), for example:
"filter": {
"propertyFilter": {
"property": {
"name": "test"
},
"op": "EQUAL",
"value": {
"stringValue": "hello world"
}
}
}
If you have the entity key ids you don't need to perform queries to get the entities (you might not even be allowed to do that inside transactions), you can directly pull the entities by keys, using the projects.lookup method. I think something along these lines:
{
"keys": [
{
"path": [
{
"kind": "Test",
"id": "5634472569470976"
}
]
}
],
}

Related

Add and update child arrays value in Mongo db

I want to add value in array of the following json structure in mongo db collection "Scdtls".
I need to add value only where "Type": "Fees" and "IsCurrentVersion": true.
{
"_id": ObjectId("60e71243b484cf3ec22a6845"),
"Item": "School",
"Text": "School Details",
"Types": [
{
"Type": "Library",
"Values": [
{
"IsCurrentVersion": false,
"KeyWords": [
{
"_id": ObjectId("611a4f113800d6af3fc4814f"),
"Value": "Physics"
}
]
}
]
},
{
"Type": "Fees",
"Values": [
{
"IsCurrentVersion": false,
"KeyWords": [
{
"_id": ObjectId("611a4f113800d6af3fc4814f"),
"Value": "Admission"
},
{
"_id": ObjectId("611a4f113800d6af3fc4814k"),
"Value": "Canteen"
}
]
},
{
"IsCurrentVersion": true,
"KeyWords": [
{
"_id": ObjectId("611a4f113800d6af3fc4814g"),
"Value": "Tution"
}
]
}
]
}
]
}
This is how I am trying
db.Scdtls.update({
"Item": "School",
"Types.Type": "Fees",
"Types.Values.IsCurrentVersion": true
},
{
"$push": {
"Types.1.Values.$[].KeyWords": {
"_id": ObjectId(),
"Value": "Sports"
}
}
})
But it is also adding "Value": "Sports" in "Type" : "Fees" where "IsCurrentVersion": false.
Not able to understand the reason.
If I understand correctly, you can do the update you want using "arrayFilters", like this:
db.Scdtls.update({
"Item": "School",
"Types.Type": "Fees",
"Types.Values.IsCurrentVersion": true
},
{
"$push": {
"Types.$[x].Values.$[y].KeyWords": {
"_id": ObjectId("deadbeafcafebabec0deface"),
"Value": "Sports"
}
}
},
{
"arrayFilters": [
{ "x.Type": "Fees" },
{ "y.IsCurrentVersion": true }
]
})
Try it on mongoplayground.net.

During Alexa Discovery tower fan not showing up

During Alexa discovery process, we need to send device details and their capabilities. I am sending light and fan details. Light gets showed up in Alexa App but not the fan. Can you please help me to find what I am doing wrong with the following response.
I used this Alexa documentation for creating response. https://developer.amazon.com/docs/smarthome/connect-a-tower-fan-to-alexa.html
{
"event": {
"header": {
"namespace": "Alexa.Discovery",
"name": "Discover.Response",
"payloadVersion": "3",
"messageId": "somd-id"
},
"payload": {
"endpoints": [
{
"endpointId": "fan-i",
"friendlyName": "Fan",
"description": "Fan",
"manufacturerName": "Fan",
"displayCategories": [
"OTHER"
],
"cookie": {},
"capabilities": [
{
"type": "AlexaInterface",
"interface": "Alexa.PowerController",
"version": "3",
"properties": {
"supported": [
{
"name": "powerState"
}
],
"proactivelyReported": true,
"retrievable": true
}
},
{
"type": "AlexaInterface",
"interface": "Alexa.RangeController",
"version": "3",
"instance": "speed",
"capabilityResources": {
"friendlyNames": [
{
"#type": "asset",
"value": {
"assetId": "Alexa.Setting.FanSpeed"
}
}
]
},
"properties": {
"supported": [
{
"name": "rangeValue"
}
],
"proactivelyReported": true,
"retrievable": true
},
"configuration": {
"supportedRange": {
"minimumValue": 1,
"maximumValue": 5,
"precision": 1
},
"presets": [
{
"rangeValue": 1,
"presetResources": {
"friendlyNames": [
{
"#type": "asset",
"value": {
"assetId": "Alexa.Value.Minimum"
}
},
{
"#type": "asset",
"value": {
"assetId": "Alexa.Value.Low"
}
}
]
}
},
{
"rangeValue": 5,
"presetResources": {
"friendlyNames": [
{
"#type": "asset",
"value": {
"assetId": "Alexa.Value.Maximum"
}
},
{
"#type": "asset",
"value": {
"assetId": "Alexa.Value.High"
}
}
]
}
},
{
"rangeValue": 3,
"presetResources": {
"friendlyNames": [
{
"#type": "asset",
"value": {
"assetId": "Alexa.Value.Medium"
}
}
]
}
}
]
}
},
{
"type": "AlexaInterface",
"interface": "Alexa",
"version": "3"
}
]
},
]
}
}
}
Note: I am just repeating above question below because StackOverflow doesn't allow so much code to be pasted with less description.
During Alexa discovery process, we need to send device details and their capabilities. I am sending light and fan details. Light gets showed up in Alexa App but not the fan. Can you please help me to find what I am doing wrong with the following response.
I think Alexa.RangeController is currently restricted to US region. So if you are trying to discover devices registered to account outside US, then it looks like that Alexa simply ignores the discovery response with RangeController interface. The way I got around this problem is by switching the user account to US and the device appeared immediately. Give it a try and if you a better solution then please do share.

Alexa Skill Not Calling Endpoint Under Certain Conditions

I am developing an Alexa skill and testing it in the Alexa Developer Console. I am having issues with certain questions I ask will trigger no response. On these occasions, my endpoint is not getting called, or the DefaultFallback intent being fired.
I can re-produce the error and it only happens on certain questions. The debug log shows the entries below. I have deployed the skill to a device and get the same response (i.e. nothing). The skill remains open as I can continue to ask other questions and get a response.
If I substitute the word 'sausage' for certain words it gives no response, but using a word such as 'free' will return a response.
Run out of ideas about what is going on...
Event: Text.TextMessage
{
"event": {
"header": {
"namespace": "Text",
"name": "TextMessage",
"messageId": "messageId",
"dialogRequestId": "ba1efffc-b29e-4cef-bcc0-3ceb418b89ec"
},
"payload": {
"textMessage": "do you have any sausage samples"
}
},
"context": [
{
"header": {
"namespace": "System",
"name": "SettingsState",
"payloadVersion": "1"
},
"payload": {
"settings": [
{
"key": "com.amazon.alexa.characteristics.viewport.experiences",
"value": "[{\"arcMinuteWidth\":\"246\",\"arcMinuteHeight\":\"144\",\"canRotate\":\"false\",\"canResize\":\"false\"}]"
},
{
"key": "com.amazon.alexa.characteristics.viewport.shape",
"value": "RECTANGLE"
},
{
"key": "com.amazon.alexa.characteristics.viewport.pixelWidth",
"value": "1024"
},
{
"key": "com.amazon.alexa.characteristics.viewport.pixelHeight",
"value": "600"
},
{
"key": "com.amazon.alexa.characteristics.viewport.dpi",
"value": "160"
},
{
"key": "com.amazon.alexa.characteristics.viewport.currentPixelWidth",
"value": "1024"
},
{
"key": "com.amazon.alexa.characteristics.viewport.currentPixelHeight",
"value": "600"
},
{
"key": "com.amazon.alexa.characteristics.viewport.touch",
"value": "[\"SINGLE\"]"
}
]
}
},
{
"header": {
"namespace": "SpeechSynthesizer",
"name": "SpeechState"
},
"payload": {
"token": "amzn1.as-ct.v1.ThirdPartySdkSpeechlet#ACRI#ValidatedSpeakDirective_amzn1.ask.skill.8f0abe6c-a5e8-4585-912f-4e21df999811_6bf05e00-bc3a-4b1e-8b40-9664b36c0378",
"offsetInMilliseconds": 1000,
"playerActivity": "FINISHED"
}
},
{
"header": {
"namespace": "AudioPlayer",
"name": "PlaybackState"
},
"payload": {
"token": "",
"offsetInMilliseconds": 0,
"playerActivity": "IDLE"
}
},
{
"header": {
"namespace": "Alerts",
"name": "AlertsState"
},
"payload": {
"activeAlerts": [],
"allAlerts": []
}
},
{
"header": {
"namespace": "VisualFocusManager",
"name": "VisualFocusState"
},
"payload": {
"inFocus": {
"component": "ListRenderer",
"idleTimeInMilliseconds": 0
}
}
},
{
"header": {
"namespace": "AudioFocusManager",
"name": "AudioFocusState"
},
"payload": {
"dialog": {
"component": "SpeechSynthesizer",
"idleTimeInMilliseconds": 0
}
}
},
{
"header": {
"namespace": "ListRenderer",
"name": "RenderedListState"
},
"payload": {
"listToken": "amzn1.as-lt.v1.ThirdPartySdkSpeechlet#LRID#amzn1.ask.skill.8f0abe6c-a5e8-4585-912f-4e21df999811::JTEXd",
"itemsVisibleOnScreen": [],
"selectedItems": [],
"focusedItem": {},
"renderedItemDetail": {
"listItemIdentifier": "amzn1.as-lt.v1.ThirdPartySdkSpeechlet#LRID#amzn1.ask.skill.8f0abe6c-a5e8-4585-912f-4e21df999811::JTEXd",
"ordinalNumber": 1
},
"highestOrdinalSeen": 1,
"lastItemOrdinal": 1
}
}
]
}
Directive: SpeechRecognizer.RequestProcessingCompleted
{
"header": {
"namespace": "SpeechRecognizer",
"name": "RequestProcessingCompleted",
"messageId": "77057f6b-8f91-4fb4-aab0-c86efc934adc",
"dialogRequestId": "ba1efffc-b29e-4cef-bcc0-3ceb418b89ec"
},
"payload": {}
}
Directive: SkillDebugger.CaptureDebuggingInfo
{
"header": {
"namespace": "SkillDebugger",
"name": "CaptureDebuggingInfo",
"messageId": "c3175e0f-3c0a-450c-8ef4-5246ce2e1a31"
},
"payload": {
"skillId": null,
"timestamp": "2019-01-21T10:25:31.211Z",
"dialogRequestId": "ba1efffc-b29e-4cef-bcc0-3ceb418b89ec",
"skillRequestId": null,
"type": "ConsideredIntents",
"content": {
"intents": [
{
"name": "General_MobileApp",
"confirmationStatus": "NONE",
"slots": {
"Deliverables": {
"name": "Deliverables",
"value": "samples",
"resolutions": {
"resolutionsPerAuthority": [
{
"authority": "amzn1.er-authority.echo-sdk.amzn1.ask.skill.8f0abe6c-a5e8-4585-912f-4e21df999811.MARSHALLS_Deliverables",
"status": {
"code": "ER_SUCCESS_MATCH"
},
"values": [
{
"value": {
"name": "samples",
"id": "6ef9161b900632671022358216c7dfe7"
}
}
]
}
]
},
"confirmationStatus": "NONE"
},
"Company": {
"name": "Company",
"value": "you",
"resolutions": {
"resolutionsPerAuthority": [
{
"authority": "amzn1.er-authority.echo-sdk.amzn1.ask.skill.8f0abe6c-a5e8-4585-912f-4e21df999811.MARSHALLS_Company",
"status": {
"code": "ER_SUCCESS_MATCH"
},
"values": [
{
"value": {
"name": "Marshalls",
"id": "abfd923a6acfc93e81ba94b0310b47b2"
}
}
]
}
]
},
"confirmationStatus": "NONE"
},
"Media": {
"name": "Media",
"value": null,
"confirmationStatus": "NONE"
},
"Contact": {
"name": "Contact",
"value": null,
"confirmationStatus": "NONE"
}
}
}
]
}
}
}
Edit:
I now think a certain confidence score is not being met causing the intent not to fire (but not then calling the default fallback intent). If I ask 'flag laying patterns' the intent fires correctly and I get a full debug trace:-
If I ask 'flag laying sausages' then I get a small debug trace together with the same considered intent, but no answer and no endpoint call:-

Google Cloud Datastore JSON for an Array of Keys

I tried this JSON at the Google Datastore Console to create a property as an array of keys (one-to-many relationship) but it doesn't work:
{
"values": [
{
"keyValue": key(user, 1234567890123456)
},
{
"keyValue": key(user, 6544567890123456)
},
]
}
See JSON format: https://cloud.google.com/datastore/docs/reference/rest/v1/Key
The JSON will be like:
{
"values": [
{
"keyValue": {
"path": [
{
"kind": "user",
"id": "1234567890123456"
}
]
}
},
{
"keyValue": {
"path": [
{
"kind": "user",
"id": "6544567890123456"
}
]
}
}
]
}

ElasticSearch-Kibana : filter array by key

I have data with one parameter which is an array. I know that objects in array are not well supported in Kibana, however I would like to know if there is a way to filter that array with only one value for the key. I mean :
This is a json for exemple :
{
"_index": "index",
"_type": "data",
"_id": "8",
"_version": 2,
"_score": 1,
"_source": {
"envelope": {
"version": "0.0.1",
"submitter": "VF12RBU1D53087510",
"MetaData": {
"SpecificMetaData": [
{
"key": "key1",
"value": "94"
},
{
"key": "key2",
"value": "0"
}
]
}
}
}
}
And I would like to only have the data which contains key1 in my SpecificMetaData array in order to plot them. For now, when I plot SpecificMetaData.value it takes all the values of the array (value of key1 and key2) and doesn't propose SpecificMetaData.value1 and SpecificMetaData.value2.
If you need more information, tell me. Thank you.
you may need to map your data to mappings so as SpecificMetaData should act as nested_type and inner_hits of nested filter can supply you with objects which have key1.
PUT envelope_index
{
"mappings": {
"document_type": {
"properties": {
"envelope": {
"type": "object",
"properties": {
"version": {
"type": "text"
},
"submitter": {
"type": "text"
},
"MetaData": {
"type": "object",
"properties": {
"SpecificMetaData": {
"type": "nested"
}
}
}
}
}
}
}
}
}
POST envelope_index/document_type
{
"envelope": {
"version": "0.0.1",
"submitter": "VF12RBU1D53087510",
"MetaData": {
"SpecificMetaData": [{
"key": "key1",
"value": "94"
},
{
"key": "key2",
"value": "0"
}
]
}
}
}
POST envelope_index/_search
{
"query": {
"bool": {
"must": [
{
"nested": {
"inner_hits": {},
"path": "envelope.MetaData.SpecificMetaData",
"query": {
"bool": {
"must": [
{
"term": {
"envelope.MetaData.SpecificMetaData.key": {
"value": "key1"
}
}
}
]
}
}
}
}
]
}
}
}

Resources