I'm using the library https://github.com/ex-aws/ex_aws_dynamo, and I'm having issues getting a working example of query-filter to work with query. I was hoping someone here has an example they could share.
Here's what I've tried, but it returns an error:
[
key_condition_expression: "highlight_request_id = :highlight_request_id",
expression_attribute_values: [
highlight_request_id: "c692e65e-618f-45a3-ac12-d8103e6444c8"
],
query_filter: %{
range_id: %{
attribute_value_list: ["9990-ORGANIZATION-Pampers"],
comparison_operator: "EQ"
}
}
]
and the error I get back:
{:error,
{"ValidationException",
"1 validation error detected: Value null at 'queryFilter.range_id.member.comparisonOperator' failed to satisfy constraint: Member must not be null"}}
I'm not sure what is considered to be null. Any thoughts?
Make sure your query is written like so (adapted from the ex_aws_dynamo tests):
ExAws.Dynamo.query("person", [
index_name: "email",
key_condition_expression: "#email = :email",
expression_attribute_names: %{"#email" => "email"},
expression_attribute_values: [email: "person#test.com", last_name: "Person"],
filter_expression: "last_name = :last_name"
]) |> ExAws.request()
I was able to run this successfully against my local table, you'll have to fill in the appropriate values for your model. In particular, you'll want to include the index_name, and use the filter_expression, rather than query_filter.
In your case, I believe you'd want something like
ExAws.Dynamo.query("person", [
index_name: "highlight_request_id", # assuming that's the name of the index
key_condition_expression: "#highlight_request_id = :highlight_request_id",
expression_attribute_names: %{"#highlight_request_id" => "highlight_request_id"},
expression_attribute_values: [highlight_request_id: "c692e65e-618f-45a3-ac12-d8103e6444c8", range_id: "9990-ORGANIZATION-Pampers"],
filter_expression: "range_id = :range_id"
]) |> ExAws.request()
Let me know if this gets you any closer - again, worked for me, using the latest version of ex_aws_dynamo (2.2.2, at the moment).
Related
I'm still new to the ElasticSearch technology and right now struggle with creating index template that will be applied to all new indices but can't create proper one.
Currently running ElasticSearch 7.9.2 and it's documentation index templates informs that index_patterns field is required and should be array of wildcards (* matches any string).
Naturally I have tried using ["*"] as pattern via Kibana's console for request:
PUT _index_template/template_1
{
"index_patterns": ["*"],
"priority": 0
}
I've got:
{
"error" : {
"root_cause" : [
{
"type" : "null_pointer_exception",
"reason" : null
}
],
"type" : "null_pointer_exception",
"reason" : null
},
"status" : 500
}
while for request that added empty settings:
PUT _index_template/template_1
{
"index_patterns": ["*"],
"template": {
"settings": {
}
},
"priority": 0
}
I've received:
#! Deprecation: index template [template_1] has index patterns [*] matching patterns from existing older templates [.monitoring-es,.triggered_watches,.management-beats,.transform-internal-005,.logstash-management,.monitoring-kibana,.kibana-event-log-7.9.2-template,.ml-config,.watch-history-11,.ml-meta,ilm-history,.monitoring-logstash,.ml-state,.slm-history,.ml-inference-000002,.monitoring-beats,.monitoring-alerts-7,.ml-anomalies-,.watches,.ml-notifications-000001,.transform-notifications-000002,.ml-stats] with patterns (.monitoring-es => [.monitoring-es-7-*],.triggered_watches => [.triggered_watches*],.management-beats => [.management-beats],.transform-internal-005 => [.transform-internal-005],.logstash-management => [.logstash],.monitoring-kibana => [.monitoring-kibana-7-*],.kibana-event-log-7.9.2-template => [.kibana-event-log-7.9.2-*],.ml-config => [.ml-config],.watch-history-11 => [.watcher-history-11*],.ml-meta => [.ml-meta],ilm-history => [ilm-history-2*],.monitoring-logstash => [.monitoring-logstash-7-*],.ml-state => [.ml-state*],.slm-history => [.slm-history-2*],.ml-inference-000002 => [.ml-inference-000002],.monitoring-beats => [.monitoring-beats-7-*],.monitoring-alerts-7 => [.monitoring-alerts-7],.ml-anomalies- => [.ml-anomalies-*],.watches => [.watches*],.ml-notifications-000001 => [.ml-notifications-000001],.transform-notifications-000002 => [.transform-notifications-*],.ml-stats => [.ml-stats-*]); this template [template_1] will take precedence during new index creation
{
"acknowledged" : true
}
Response depends only on existence of empty template.settings it seems like it might be slightly bugged.
Nevertheless latter approach seems to work however deprecation warning sounds dangerous and discouraging (I've tried setting priority to 0 but to no avail). However Documentation of 6.8 version sports example of "*". So such functionality existed not long ago.
What is the proper way, if there is one, to construct "match all" index template?
Currently to match all indices you really need to use the * as the index pattern and the warning is there because it will match anything, including the internal systems indices.
Depending on what is in your template this can lead to things not working right or break your system.
There is an open issue on github about it, mostly regarding to the .security index, which is also affected when you use an match all index pattern, and there is another open issue that also deals with this problem.
After working with loopback for the past 6 months, i have now encountered a problem i can't seem to figure out the reason for.
My problem occurs when using loopbacks, "where" with a "and" condition.
Like.find({
"where: {
"and": [{
"relation_id": ctx.instance.relation_id
},
{
"user_id": ctx.options.accessToken.userId
}
]
}
})
Above is the call with the where/and filter included.
I console.log the values before the call and see:
"ctx.instance.relation_id" which prints "59a32764029ab660b1c7f862"
"ctx.options.accessToken.userId" which prints "59a32597c606a85b5e08db18"
And below is the object i am trying to query:
{
"_id" : ObjectId("59a5cade884d8c48e135768c"),
"user_id" : "59a32597c606a85b5e08db18",
"relation_id" : "59a32764029ab660b1c7f862",
"created_at" : ISODate("2017-08-29T22:13:18.209+02:00"),
"status" : NumberInt("1")
}
Now. Calling the find() function without the "and" condition for just one of the values, either user_id or relation_id, returns the expected result, but with the "and" it returns an empty array.
The official Loopback documentation gives this examples for using the where/and filter:
Post.find({where: {and: [{title: 'My Post'}, {content: 'Hello'}]}},
function (err, posts) {
...
});
as shown here
And as far as i can tell, my query matches it completely, but still don't get the expected results. I know that there could be many reasons why it fails, but i was hoping someone here, maybe could give some pointers or provide insight i could use to solve my issue.
Thanks
I'm trying to build a chatbot using Amazon's boto3 library. Right now, I am trying to create an intent using the put_intent function. My code is as follows:
intent = lexClient.put_intent(name = 'test',
sampleUtterances = ["Who is messi?"]
)
When I try running this, I get the following exception:
botocore.errorfactory.BadRequestException: An error occurred
(BadRequestException) when calling the PutIntent operation: RelativeId
does not match Lex ARN format: intent:test2:$LATEST
Can anyone tell me what I'm doing wrong?
I got the same error when trying to have a digit in intent name field. Realized that was not allowed when trying to do the same from AWS console.
Error handling could really be more specific.
Try taking the question mark out of the utterance, that has caused me issues in the past!
You need to run GetSlotType. That will return current checksum for that slot. Put that checksum in your PutSlotType checksum. Big bang boom.
https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/LexModelBuildingService.html#getSlotType-property
var params = {
name: "AppointmentTypeValue",
checksum:'54c6ab5f-fe30-483a-a364-b76e32f6f05d',
description: "Type of dentist appointment to schedule'",
enumerationValues: [
{
value: "cleaning"
},
{
value: "whitening"
},
{
value: "root canal"
},
{
value:"punch my face"
}
]
};
For the put_intent function I faced similar issues.
At least the following 3 are worth mentioning.
Sample Utterances
There are requirements for the sample utterances:
An utterance can consist only of Unicode
characters, spaces, and valid punctuation marks. Valid punctuation
marks are: periods for abbreviations, underscores, apostrophes, and
hyphens. If there is a slot placeholder in your utterance, ensure that
it's in the {slotName} format and has spaces at both ends.
It seems like there is no error raised when calling the put_intent function with the following code.
intent = lexClient.put_intent(name = 'test',
sampleUtterances = ["Who is messi"]
)
However, if you try to add it to your bot and start building the bot it will fail.
To fix it remove the question mark at the end of you sampleUtterance.
intent = lexClient.put_intent(name = 'test',
sampleUtterances = ["Who is messi?"]
)
Prior intent version
If your intent already exists you need to add the checksum to your function call. To get the checksum of your intent you can use the get_intent function.
For example docs:
response = client.get_intent(
name='test',
version='$LATEST'
)
found_checksum = response.get('checksum')
After that you can put a new version of the intent:
intent = lexClient.put_intent(name = 'test',
sampleUtterances = ["Who is messi"],
checksum = found_checksum
)
Intent Name (correct in your case, just adding this for reference)
It seems like the name can only contain letters, underscores, and should be <=100 in length. Haven't found anything in the docs. This is just trial and error.
Calling put_intent with the following:
intent = lexClient.put_intent(name = 'test_1',
sampleUtterances = ["Who is messi"]
)
Results in the following error:
BadRequestException: An error occurred (BadRequestException) when calling the PutIntent operation: RelativeId does not match Lex ARN format: intent:test_1:$LATEST
To fix the name you can replace it to:
intent = lexClient.put_intent(name = 'test',
sampleUtterances = ["Who is messi"]
)
I'm trying to add targets to target lists in Sugar via REST service calls. I'm getting a positive response from Sugar but records are not added. The service method I'm using is *set_relationship*:
{
"session":"3ece4lmn5rtweq9vm5581jht",
"module_name":"ProspectLists",
"module_id":"cb13b96f-8334-733c-1548-52c27a5b8b99",
"link_field_name":"prospects",
"name_value_list":[],
"related_ids":["534f894a-4265-143d-c94b-52be908685b1"],
"delete":0
}
I also tried it the other way around:
{
"session":"3ece4lmn5rtweq9vm5581jht",
"module_name":"Prospects",
"module_id":"cb13b96f-8334-733c-1548-52c27a5b8b99",
"link_field_name":"prospect_lists",
"name_value_list":[],
"related_ids":["534f894a-4265-143d-c94b-52be908685b1"],
"delete":0
}
In both cases I get a promising response:
{"created":1,"failed":0,"deleted":0}
...but when I check the target list I can't find any added targets. I also checked the database but there is no trace either.
My Sugar Version is 6.5.16 CE and I'm using the SuiteCRM 7.0.1 extension but I don't think this makes a difference here.
Any hint is highly appreciated. Thanks!
I finally figured it out. It seems like set_relationship is very picky about the parameter order. The parameter naming doesn't even mean a thing. This worked in the end for me:
{
"session":"3ece4lmn5rtweq9vm5581jht",
"module_name":"Prospects",
"module_id":"cb13b96f-8334-733c-1548-52c27a5b8b99",
"link_field_name":"prospect_lists",
"related_ids":["534f894a-4265-143d-c94b-52be908685b1"],
"delete":0
}
Working Python code (API v4.1):
import sugarcrm
import json
import requests
crm_session = sugarcrm.Session(CRM_HOST, CRM_USER, CRM_PASS)
payload = {
"method": "set_relationship",
"input_type": "JSON",
"response_type": "JSON",
"rest_data": json.dumps({
"session": crm_session.session_id,
"module_name": "Prospects",
# ID of the record you're creating relationship FROM
# In my case it is a record from module "Prospects"
"module_id": "cb13b96f-8334-733c-1548-52c27a5b8b99",
"link_field_name": "events_prospects",
# ID of the record you're creating relationship FOR
# In my case it is a record from module "events"
"related_ids": ["534f894a-4265-143d-c94b-52be908685b1"],
"name_value_list": [],
"delete": 0
})
}
result = requests.post(CRM_HOST, data=payload)
#Till is right, be careful with the order of "rest_data" parameters. In my case placing name_value_list before related_ids has been producing positive results with no actual relationship created.
p.s. I'm using this library: https://pypi.python.org/pypi/sugarcrm/0.1
Need to be able to generate the following URL string
http://localhost:3000/admin/cities?q%5Bprovince_id_eq%5D=1&commit=Filter&order=city_name_asc
how does this link_to need to be setup?
link_to(p.cities.count, admin_cities_path)
You could just pass the query parameters as a hash to the URL helper, e.g. Running the following commands in my console, I get the following hash:
url = "http://localhost:3000/admin/cities?q%5Bprovince_id_eq%5D=1&commit=Filter&order=city_name_asc"
query = URI.parse(url).query
hash = Rack::Utils.parse_nested_query(query)
#=> { "q" => { "province_id_eq" => "1" }, "commit" => "Filter", "order" => "city_name_asc" }
Then you'd just do
admin_cities_url(hash)
To get back to the original URL.
Probably this will help you, take a look after the "link_to can also produce links with anchors or query strings"
link_to(p.cities.count, admin_cities_path(q: { province_id_eq: 1 }, order: "city_name_asc"))