loopbackio / loopback-connector-elastic-search

Strongloop Loopback connector for Elasticsearch
MIT License
78 stars 56 forks source link

Check for undefined/null field is not working #90

Open wolfgang-s opened 7 years ago

wolfgang-s commented 7 years ago

When I try to query:

{filter: {where: {empty_field_name: null}}} there is an exception:

Trace: [parsing_exception] No text specified for text query, with { line=1 & col=64 } at .../node_modules/loopback-connector-es/lib/esConnector.js:835:12

Line number could be different, since I'm on my on branch.

pulkitsinghal commented 7 years ago

Thanks for the heads up.

Other than fixing it so we are not running into an exception, in terms of expected behavior:

  1. do you as a user expect to match and retrieve all documents where that fieldName is explicitly null?
  2. do you as a user expect to match and retrieve all documents where that fieldName is null, <empty>, or undefined
  3. do you as a user expect to match and retrieve all documents where that fieldName simply doesn't exist?

I realize that some of my questions are silly because of how ES indexing/storage works but still please humor me.

Also I wonder if loopback has smartly defined an explicit behavior for their ORM for such queries so we don't make this up as we do along! cc @bajtos - What do you think?

bajtos commented 7 years ago

Also I wonder if loopback has smartly defined an explicit behavior for their ORM for such queries so we don't make this up as we do along! cc @bajtos - What do you think?

My knowledge of juggler and connectors is limited, @strongloop-community/sq-lb-apex are better suited to help you.

j-craig commented 5 years ago

Is there any movement on this? It seems to me like pretty necessary functionality to be able to query a database for nulls.

As to your three questions, I don't much experience with ES, so I can't say all the implications here, but I would say "yes" to 1.

As far as 2, I'm not positive what <empty> and undefined mean to you (or ES), but I take <empty> to mean an empty string value whereas undefined means a document that doesn't have the field (as opposed to a null value for the field). My answer here is that I would not treat an empty string as a null. I'm not so sure on undefined; in a way it seems like it would be nice to include them but on the other hand, if there were some other mechanism to query for undefined then it could simply be added as an or condition (just like you could add the empty string to a query).

For question 3, this would not make sense to me since the query would return documents that don't have the field but not return documents where that field is null.

j-craig commented 5 years ago

Also, FWIW, a similar query (filter of {"where": {"field": null}}) with a MongoDB datasource returns documents with an explicit null for the given field, but not documents with an empty string for the field or that do not have such a field.