django-elasticsearch-dsl-drf icon indicating copy to clipboard operation
django-elasticsearch-dsl-drf copied to clipboard

Add optional validators to the filtering/search OR implement silent mode

Open alexgmin opened this issue 6 years ago • 5 comments

If a date filter receives a invalid value, like ?date__range=foo__bar, the end result is a RequestError like this RequestError(400, 'search_phase_execution_exception', 'failed to parse date field [foo] with format [strict_date_optional_time||epoch_millis]') Considering there are legitimate search_phase_execution_exceptions, like a field not existing, shouldn't the library have the same behavior as the default drf filters, for example, which just ignores invalid values?

I'm guessing the best solution would be to validate the date before sending it to elastic, which is what django-filters does.

I'm also not sure if this affects other types than dates.

alexgmin avatar Jan 04 '19 13:01 alexgmin

@Alexgmin:

TL;DR - I don't see it happening.

Reasons:

  • Elasticsearch accepts so many formats.
  • They also vary from version to version.
  • It would also add a lot of complexity to the package.
  • Besides, returning no results if filter values are not valid, is in my opinion quite ok. I would find it confusing otherwise.

barseghyanartur avatar Jan 04 '19 14:01 barseghyanartur

P.S.

The only thing I could do, is to add optional validators to the filtering/search. Developers themselves would be then responsible for adding proper validators.

barseghyanartur avatar Jan 04 '19 14:01 barseghyanartur

The only thing I could do, is to add optional validators to the filtering/search. Developers themselves would be then responsible for adding proper validators.

I don't see a downside of doing this. I would appreciate it.

Thinking about it a bit more and looking at the date datatype docs, I think this should be solved in elasticsearch-dsl instead of in this package, just like the the data type validation is done in drf or django instead of on the filter packages.

alexgmin avatar Jan 05 '19 01:01 alexgmin

When I've sent a bad value to filter data I'll get 500 http error because of bad response from ES. @barseghyanartur What do you think about to handle Request Error 400 from ES and return an empty response? I'm new in elastic search, maybe you know some way to validate query before applying it and if it bad we may skip it?

orehush avatar Mar 07 '19 15:03 orehush

@orehush:

At the moment, you should be ignoring errors from your frontend.

Validation or silent mode will be implemented some day.

You have 3 options:

  • (a) Wait until I or someone else implement.
  • (b) Implement yourself (contributions here are appreciated).
  • (c) Sponsor development of that feature (contact me for the details).

barseghyanartur avatar Mar 08 '19 08:03 barseghyanartur