Closed pulkitsinghal closed 9 years ago
Here's are logs from a test that passes despite the fact that I haven't explicitly implemented the FIELDS filter yet.
{email: false}
as a FIELDS filter conditionThis is what comes back from the backend:
loopback:connector:elasticsearch ESConnector.prototype.all +0ms model User
result [
{
"seq": 0,
"name": "John Lennon",
"email": "john@b3atl3s.co.uk",
"birthday": "1980-12-08T00:00:00.000Z",
"role": "lead",
"order": 2,
"vip": true
},
{
"seq": 1,
"name": "Paul McCartney",
"email": "paul@b3atl3s.co.uk",
"birthday": "1942-06-18T00:00:00.000Z",
"role": "lead",
"order": 1,
"vip": true
},
...
]
Now, here's the next part of the log that shows that when the test case receives the data back ... the email field has been magically filtered out!
[
{
"seq": 0,
"name": "John Lennon",
"birthday": "1980-12-08T00:00:00.000Z",
"role": "lead",
"order": 2,
"vip": true
},
{
"seq": 1,
"name": "Paul McCartney",
"birthday": "1942-06-18T00:00:00.000Z",
"role": "lead",
"order": 1,
"vip": true
},
...
]
✓ should only include fields as specified (2061ms)
To be clear, the fields are handled by both connector implementation and juggler (https://github.com/strongloop/loopback-datasource-juggler/blob/master/lib/dao.js#L530). The connector can use fields
to optimize its interaction with the underlying data store, but juggler will further enforce the fields
when model instances are created with the results from the connector.
Thanks Raymond! In that case I'll simply avoid implementing filters in ES connector for now as there's no point for me in stressing the backend with fields/source filtering. If the community needs it, it can be reconsidered.
As for writing a test such that we can be sure to test the actual connector implementation instead of the juggler one which may overshadow a mistake in ES and make tests pass ... I suppose somehow it can be written to not use Model.find()
but use Connector.all()
when the time comes.
The original test case was available at: https://github.com/strongloop/loopback-datasource-juggler/blob/master/test/basic-querying.test.js#L446
I simply copied and repurposed it here: https://github.com/strongloop-community/loopback-connector-elastic-search/blob/master/test/02.basic-querying.test.js#L522