I'm getting a really weird error when I try to preform a DeleteItem with expressions. Can anyone help?
Thanks
{
"TableName": "MyTable",
"Key": {
"SESSION": {
"S": "1E3E181C-1238-D168-725D-9B0FE7F5EA3E"
}
},
"FilterExpression": "#X < :X ",
"ExpressionAttributeNames": {
"#X": "ttl"
},
"ExpressionAttributeValues": {
":X": {
"N": "1502905189"
}
}
}
// RESULT
Array
(
[__type] => com.amazon.coral.validate#ValidationException
[message] => ExpressionAttributeNames can only be specified when using expressions
)
The delete item should not contain FilterExpression. If you would like to delete the item based on some condition, you can use ConditionExpression to specify the condition.
"ConditionExpression" : "#X < :X "
Please replace the FilterExpression with ConditionExpression.
Related
I would like my UpdateItem function to add the new value to the previous one but I can't figure out how to use numbers for the calculation and access the current value to be added to the new one.
Here is my working function, what I want to do is included in comment. How can I do it?
{
"TableName": "Votes",
"Key": {
"votesId": {
"S": "$input.path('$.votesId')"
}
},
"UpdateExpression": "set buy = :val1",
"ExpressionAttributeValues" : {
":val1": {
"N": "$input.path('$.buy')"
//Would like: "N": "buy + $input.path('$.buy')"
}
},
"ReturnValues": "ALL_NEW"
}
Here is how I test it:
{
"votesId":1,
"down":0,
"up":0,
"hold":0,
"buy":0,
"sell":0
}
You can use UpdateExpression to indicate which attributes are to be updated and what actions to perform.
Specifically in your case, UpdateExpression supports the following:
SET myNum = myNum + :val
I'm trying to search from an object that has a list property.
I need to be able to select all object that contains all sublist items.
ex :
If my object has [A,B,C] it should be returned for the given querys :
[A], [A,B], [A,B,C], [A,C], [C,A] ... (Input order doesn't have to match)
But if the sublist contains any element that is not part of the object list, it should not be returned.
ex :
[D], [A,D] ...
Those querys should not be valid.
I've managed to do it for the query with an existing sublist, but not when any item of the sublist doesn't exists.
Any ideas ?
Thanks !
Use comma seperate for sublist query item as a value for match query and set operator value to "and" as following:
Sample of document:
{
"Id": 1,
"Name": "One",
"tags": ["A","B","C"]
}
For sublist:[A,B]:
{
"query": {
"match": {
"tags": {
"query": "A,B",
"operator": "and"
}
}
}
}
I test in ElasticSearch 5.6.0 and 6.1.2
Assuming A, B, C, etc are mapped as keyword types, multiple bool query filter clauses would be one way
var response = client.Search<User>(s => s
.Query(q => +q
.Term(f => f.Badges, "A") && +q
.Term(f => f.Badges, "B") && +q
.Term(f => f.Badges, "C")
)
);
generates the following query
{
"query": {
"bool": {
"filter": [
{
"term": {
"badges": {
"value": "A"
}
}
},
{
"term": {
"badges": {
"value": "B"
}
}
},
{
"term": {
"badges": {
"value": "C"
}
}
}
]
}
}
}
A user document would need to have at least all of A, B and C badges to be considered a match.
A user document may well have other badges in addition to A, B and C; if you need to find documents that have exactly A, B and C, take a look at the terms_set query with a minimum_should_match* value set to the number of passed terms.
I am a beginner to couchDB.
I have data as below:
one:[{
"name":abc,
"value":1
},
{
"name":efg,
"value":1
},
{
"name":abc,
"value":1
},
I would like to get the count of similar keys and get the maximum.
e.g. in my case "abc" is twice. so the maximum(reduce function) should return
result: {"name":abc,value:2}
Did you try this design document:
{
"_id":"_design/company",
"views":
{
"abc_customers": {
"map": "function(doc) { if (doc.name == 'abc') emit(doc.name,doc.value) }",
"reduce" : "_count"
},
"efg_customers": {
"map": "function(doc) { if (doc.name == 'efg') emit(doc.name,doc.value) }",
"reduce" : "_count"
}
}
}
See this one for a comparison of _count and _sum. Possibly you need _count.
By the above CouchDB design document, you will get count for each doc.name of abc, efg, ... and then you can do a search for max/min of counts.
I am trying to retrieve a list of entries from AWS DynamoDB with a primary hash and sort key composite.
The idea is to retrieve a list which matches a given query string value which is a part of the sort key, for example, the sort keys can be a_b_c, a_d_e, a_f_g and i need to get the all entries with b in it.
I am asking for three query strings from the client and concatenating them in the body mapping template in the integration request section of AWS API gateway.
I am searching the web to accomplish the same but haven't been successful in finding a solution.
It would save a lot of time if somebody could help me with this.
Below is my approach.
{
"TableName": "$util.escapeJavaScript("$context.stage\_TableName").replaceAll("\\","")",
"FilterExpression": "identityId = :v1 and aWithbWithc = :v2 + _ + :v3 + _ + :v4",
"ExpressionAttributeValues": {
":v1": {
"S": "$context.identity.cognitoIdentityId"
},
":v2" : {
"S" : "$input.params('a')"
},
":v3" : {
"S" : "$input.params('b')"
},
":v4" : {
"S" : "$input.params('c')"
}
}
}
I have found the solution and putting it out here.
{
"TableName": "$util.escapeJavaScript("$context.stage\_TableName").replaceAll("\\","")",
"FilterExpression": "identityId = :v1 and aWithbWithc = :v2",
"ExpressionAttributeValues": {
":v1": {
"S": "$context.identity.cognitoIdentityId"
},
":v2" : {
"S" : "$util.escapeJavaScript($input.params('a'))__$util.escapeJavaScript($input.params('b'))__$util.escapeJavaScript($input.params('c'))"
}
}
}
you can have something like
{
#set($tableNameSuffix = "_TableName")
"TableName": "$stageVariables.environment$tableNameSuffix",
"ConsistentRead": true,
"KeyConditionExpression": "XXX = :val",
"ExpressionAttributeValues": {
":val": {
"S": "$method.request.path.xxx"
}
}
}
I wrote the following parser (paste into http://pegjs.org/online and it works):
Expression = Pairs / FullTextWithPairs
Pairs = (';'? _ p:Pair { return p; })*
FullTextWithPairs = fto:FullText po:Pairs
{
var arr = [];
if (fto) {
arr.push(fto);
}
return arr.concat(po);
}
FullText = ft:ValueString ';'
{
return {'key' : 'fullText', 'op': '=', 'value': ft};
}
Pair = k:Field op:Operator v:ValueString
{
var res = {'key' : k, 'op': op, 'value': v};
console.log(res);
return res;
}
Operator = ('<>' / [=><])
ValueString = vs:[^;]+ {return vs.join('');}
Field = 'location' / 'application' / 'count'
_ = ' '*
It parses this string of key-value pairs: location=USA; application<>app; count>5
to this:
[
{
"key": "location",
"op": "=",
"value": "USA"
},
{
"key": "application",
"op": "<>",
"value": "app"
},
{
"key": "count",
"op": ">",
"value": "5"
}
]
The problem is I want to enable a free-text search as well, which is entered before the key-value pairs, for example:
this: free text foobar; location=USA; application<>app; count>5
and get this:
[
{
"key": "fullText",
"op": "=",
"value": "free text foobar"
},
{
"key": "location",
"op": "=",
"value": "USA"
},
{
"key": "application",
"op": "<>",
"value": "app"
},
{
"key": "count",
"op": ">",
"value": "5"
}
]
The parser should recognize that the first part is not a key-value pair (according to "Pair" rule) and insert it as "fullText" object.
Basically "Expression" rule should do it, according to what I read in the docs - A / B means if A doesn't pass the B is tried. In the second case "Paris" is faild because "free text foobar" doesn't pass the Pairs rule, but it just throws an exception instead of moving on.
Congrats to whomever survived up to here, what am I doing wrong? :)
Thank you
Played with the grammar some more, the solution was to use !Pair and (for some reason) to change the order of the "Expression" rule:
Expression = FullTextWithPairs / Pairs
Pairs = (';'? _ p:Pair { return p; })*
FullTextWithPairs = fto:FullText po:Pairs
{
var arr = [];
if (fto) {
arr.push(fto);
}
return arr.concat(po);
}
FullText = !Pair ft:ValueString ';'
{
return {'key' : 'fullText', 'op': '=', 'value': ft};
}
Pair = _? k:Field op:Operator v:ValueString
{
var res = {'key' : k, 'op': op, 'value': v};
console.log(res);
return res;
}
Operator = ('<>' / [=><])
ValueString = vs:[^;]+ {return vs.join('');}
Field = 'location' / 'application' / 'count'
_ = ' '*