Explorer icon indicating copy to clipboard operation
Explorer copied to clipboard

Range query fails when using date strings

Open a-drew opened this issue 1 year ago • 3 comments

Summary

Looks like the Range query validation forces us to use integers, however the ES range queries also support various date formats that are passed along as a string. https://www.elastic.co/guide/en/elasticsearch/reference/7.17/query-dsl-range-query.html

Steps to Reproduce

  1. Prepare a new scout query
  2. add a Range query to your search
  3. if the Range query receives dates as strings in the definitions, Assert::numeric fails

Potential Changes

  • Match the validation that ES does on their end
  • Drop the Assert::numeric call / allow strings and just let ES respond with errors if any

a-drew avatar Mar 24 '23 15:03 a-drew

I see, thanks for the good description!

Another solution might be to create a separate DateTimeRange syntax. Then we can use a Datetime class on the PHP side and convert it to the right format for ES at the last minute instead of passing (in)valid strings around.

What do you think?

Jeroen-G avatar Mar 24 '23 15:03 Jeroen-G

I like that idea! Typically, I use Carbon but you'd prefer a datetime implementation, right?

a-drew avatar Mar 25 '23 21:03 a-drew

Yes, I'd prefer the native implementation!

Jeroen-G avatar Mar 26 '23 10:03 Jeroen-G