How "keys" and "key" filters should be used in Couchbase to filter view results? - filtering

I have issue with key and keys filter parameter in Couchbase (Version: 3.0.0 Enterprise Edition) in the web console. Whatever value I set in those parameters, no record is returned.
Documents look like:
{
"folder": "F3",
"ccy": "USD",
"pnl": 789700,
"maturity": "4424-10-16 00:00 AM CEST",
"source": "BackOffice1",
"npv": 341684,
"symbolic_id": 880888,
"bpv": 374000,
"cpty": "CPTY2"
}
Map function is:
function (doc, meta) {
emit([doc.source,doc.cpty], doc.npv);
}
Reduce is the built in function
_count
I assume that I should be able to get all documents with the key ["BackOffice1","CPTY2"] by setting the key parameter in the querystring ?key=["BackOffice1","CPTY2"]&reduce=true&group=true. But nothing is returned.
I may miss something in how we should use key and keys parameters.
For information, startkey and endkey work as expected.
Is there something wrong with my approach ?

You have to add
keys=["BackOffice1","CPTY2"]
as parameter .

I figured out what was the issue with the key parameter. In the Couchbase version 3.0.0, we need to add inclusive_end=true parameter to get results.
Looking at Couchbase bugs, it looks like it was not required in previous versions and that it will be reverted back in next version, refer to https://www.couchbase.com/issues/browse/MB-12378.
After reviewing samples in Couchbase documentation, my usage of keys parameter was not correct. To query view with array as a key, keys parameter should be formatted as follow:
keys=[["value1",value2"],["value3",value2"]].
If I apply this to the example I provided in my question, the query will look like:
?keys=[["BackOffice1","CPTY2"]] or key=["BackOffice1","CPTY2"]
Thanks

Related

Is there any way to filter sap.m.Tree?

I'm new to SAPUI5 component.
Is there a way to apply $filter to sap.m.Tree? It seems weird to me.
I'm currently using $filter options to limit the data from back-end (by using WHERE clause, came from $filter option), so I have to $filter to pass my parameter.
My controller :
this.oCharTable = this.getView().byId("CharTree")
var aFilterChar = new Filter("Matnr", FilterOperator.EQ , filter_base[2])
this.oCharTable.bindElement({
path: "/AUSP_ENTITY",
model: "AUSP_DATA",
filters: [aFilterChar],
parameters: {
NumberOfExpandedLevels : 2
}
});
and It's $batch payload :
GET AUSP_ENTITY?$filter=HierarchyLevel%20eq%20%270%27&$skip=0&$top=100 HTTP/1.1
sap-cancel-on-close: true
It depends on your data source:
if you have a odata v2, you can't filter on children. This is simply not supported by v2
if you have a odata v4, this is not supported by tree-binding. Good news, it on the roadmap https://github.com/SAP/openui5/issues/2728
if you preload all data an put it in a json model. You could filter as you like with vanilla js
Based on the given answer. You could just ignore v2 specification and filter in the backend as you want with any passed filter.
Oh, I think I found the solution - the problem is on backend!
Thanks to this answer, Using Suspend - Resume makes me send right GET request, like
../AUSP_ENTITY?$filter=HierarchyLevel%20eq%20%270%27%20and%20(Matnr%20eq%20%27SomeKindofMaterialHere%27)&$skip=0&$top=100
I changed my backend to select right values, and returning value to frontend.
For future leaders, who might read my question, I changed my backend to take not only take 1 option (this one, might be Matnr), but also take 'HierarchyLevel', which have to be taken care of.
In detail - I using $filter parameters to get data from CDS View, which can reduce the select result to resonable level.
so I redefine DPC_EXT Class, split up my $filter input, and put it into my parameter, and put result into result table.
TL;dr : If you using $filter on Tree View : check the 'return' backend. It might be problem in there.

Data factory lookup (dot) in the item() name

I am having lookup wherein salesforce query is there. I am using elements (item()) in subsequent activities. Till now i had item().name or item().email but now i have item().NVMStatsSF__Related_Lead__r.FirstName which has (dot) in the field name.
How should i parse it through body tag so that it reads it correctly?
So I have the following data in item()
{
"NVMStatsSF__Related_Lead__c": "00QE000egrtgrAK",
"NVMStatsSF__Agent__r.Name": "ABC",
"NVMStatsSF__Related_Lead__r.Email": "geggegg#gmail.com",
"NVMStatsSF__Related_Lead__r.FirstName": "ABC",
"NVMStatsSF__Related_Lead__r.OwnerId": "0025434535IIAW"
}
now when i use item().NVMStatsSF__Agent__r.Name it will not parse because of (dot) after NVMStatsSF__Agent__r. And it is giving me the following error.
'item().NVMStatsSF__Related_Lead__r.Email' cannot be evaluated because property 'NVMStatsSF__Related_Lead__r' doesn't exist, available properties are 'NVMStatsSF__Related_Lead__c, NVMStatsSF__Agent__r.Name, NVMStatsSF__Related_Lead__r.Email, NVMStatsSF__Related_Lead__r.FirstName, NVMStatsSF__Related_Lead__r.OwnerId'.",
"failureType": "UserError",
"target": "WebActivityToAddPerson"
this is because ADF uses '.' for object reading.
Could you find a way to rename the field name which contains '.'?
Seems like you need a built-in function to get the value of an object according to the key. Like getValue(item(), 'key.nestkey'). But unfortunately, seems there isn't such a function. You may need handle your key first.
Finally, it worked. I was being silly.
Instead of taking the value from the child table with the help of (dot) operator I just used subquery. Silly see.
And it worked.

Sensenet length filter Not working

I want to query the Field which are empty and which are not empty using Sensenet Odata Rest API. Their documentation mentions a filter function called 'length'. I have tried to query the field with the length operation but it fails with the error.
This is the filter I have used
$filter=length(Name) eq 2
Sense/Net 6.5.4.9496
Exception
"code": "NotSpecified",
"exceptiontype": "SnNotSupportedException",
"message": {
"lang": "en-us",
"value": "Unknown method: length"
},
Wiki Link http://wiki.sensenet.com/OData_REST_API
The length operation was included in the list of supported methods incorrectly, we apologise for that. SenseNet compiles these filters to Lucene queries and it is not possible to compose such a query in Lucene that performs an operation on a field.
(the remaining methods, like substringof or startswith can be compiled to a wildcard expression easily, so that should work)
Unfortunately 'empty' expressions are also not supported by Lucene, because of their document/term structure. So the following expression does not work either:
Description eq ''
Edit: as a workaround, developers may create a custom field index handler.
For every field you want to check for emptiness (e.g. Description), you may create a technical hidden bool field (IsDescriptionEmpty) in the content type definition. The only thing you have to create and define is a custom field index handler class. In your case it would inherit from the built-in bool field index handler and you could return a boolean index value based on whether the target field (in this case Description) is empty or not.
After this you would be able to define search exressions like the following:
+Type:File +IsDescriptionEmpty:true
Please check the wiki article below and the source code for index handler examples.
How to create a field indexhandler

Entity cannot be found by elasticsearch

I have the following entity in ElasticSearch:
{
"id": 123,
"entity-id": 1019,
"entity-name": "aaa",
"status": "New",
"creation-date": "2014-08-06",
"author": "bubu"
}
I try to query for all entities with status=New, so the above entity should appear there.
I run this code:
qesponse.setQuery(QueryBuilders.termQuery("status", "New"));
return qResponse.setFrom(start).setSize(size).execute().actionGet().toString();
But it return no result.
If I use this code (general search, not of specific field) I get the above entity.
qResponse.setQuery(QueryBuilders.queryString("New");
return qResponse.setFrom(start).setSize(size).execute().actionGet().toString();
Why?
The problem is a mismatch between a Term Query and using the Standard Analyzer when you index. The Standard Analyzer, among other things, lowercases the field when it's indexed:
Standard Analyzer
An analyzer of type standard is built using the Standard Tokenizer
with the Standard Token Filter, Lower Case Token Filter, and Stop
Token Filter.
http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/analysis-standard-analyzer.html
The Term query, however, matches without analysis:
Term Query
Matches documents that have fields that contain a term (not analyzed).
The term query maps to Lucene TermQuery.
http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-term-query.html
So in your case when you index the field status it becomes "new". But when you search with a Term Query it's looking for "New" - they don't match. They do match with a general search it works because the general search also uses the Standard Analyzer.
The default value of index for a string field is analyzed . So, when you write "status" = "New" , it will use standard_analyzer, and after analyzing it will write as "new" .
So, term Query doesn't seems to be working, If you wish to query like you specified ,write mapping for the field as "not_analyzed".
For more info. link

Autocomplete function not working in meteor

I have an autocomplete textbox function which I am using in meteor.
It works fine for the following hardcoded data like :
$(document).ready(function() {
$("#demo-input-facebook-theme").tokenInput(
[{id: 7, name: "Ruby"},{id: 11, name: "Python"},{id: 13, name: "JavaScript"}],
{theme: "facebook"}
);
});
Now , I had fetched data from database MongoDB, when I pass this data as parameter to the autocomplete function it does not work... I have also used the method JSON.stringify().
The returned data looks like :
[{"_id":"ab170916-a44b-49f9-85ef-a34c90fb815d","Namelist_name":"Badminton"},
{"_id":"f768e4ba-b628-4d3f-8da6-0bad31346dcc","Namelist_name":"Biking"},
{"_id":"0bee086b-1785-40c9-9c5d-a39331c875e1","Namelist_name":"Chess"},
{"_id":"4eae1e54-ec60-4578-8052-0bf1bccf13b1","Namelist_name":"Golf"},
{"_id":"a0d2b89e-a2d6-4b30-8e38-779c5a886d49","Namelist_name":"Hiking"},
{"_id":"f3a05456-38d4-40f2-86b1-eddea061fdf0","Namelist_name":"Tennis"},
{"_id":"3669b9a2-3f87-4579-8064-82d627196fcb","Namelist_name":"Walking"},
{"_id":"6ac6497e-82b2-40fe-8b24-152e9f42750d","Namelist_name":"Wine Tasting"},
{"_id":"15a7ca87-aef7-43ab-945b-168647bb59aa","Namelist_name":"Yoga"},
{"_id":"bc40d166-64ef-4e61-85cd-60064dc037cd","Namelist_name":"Zumba"}]
Just change the Namelist_name with only name keyword. Since jquery tokeninput uses name as key
as mentioned in your hardcoded data. And if we download jquery tokeninput from http://loopj.com/jquery-tokeninput/. we come to know that the keyword is 'name'.
Hope this helps....
If you compare your returned JSON data with the test data that works there is one essential difference: you are missing the id field in your MongoDB JSON results and instead providing _id. The id field is currently a hardcoded default for the jQuery tokenInput plugin you are using for autocomplete.
Several folks have submitted patches to allow setting a different key using the tokenValue parameter.
Example (untested) patch: tokenValue cannot be changed.
If you're autocompleting multiple items with free text, you may want to check out this package I created:
https://github.com/mizzao/meteor-autocomplete