Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(es): respect format parameter in range query #5208

Conversation

etolbakov
Copy link
Collaborator

Description

Introduce the support for format parameter in RangeQuery

How was this PR tested?

curl -X GET "http://localhost:7280/api/v1/_elastic/stackoverflow-schemaless/_search?pretty" -H 'Content-Type: application/json' -d'
{
  "query": {
    "range": {
      "age": {
        "gte": "2023-01-01",
        "lte": "2023-12-31",
        "boost": 2.0,
        "format": "%Y-%m-%d"
      }
    }
  }
}

Related issue

#5109

@etolbakov
Copy link
Collaborator Author

Thanks for the reply @fulmicoton
At the moment my understanding is lacking 2 things

  1. General logic: if format is specified - we use it to convert gt/ gte, lt/lte to date and then the result convert to a JsonLiteral::String. Please let me know if I'm wrong.

  2. DateTimeInputFormat conversion: there's a from_str method that I was planing to use, but passing "format": "yyyy-MM-dd" won't succeed. Am I doing wrong assumptions on input format?

@fulmicoton
Copy link
Contributor

DateTimeInputFormat conversion: there's a from_str method that I was planing to use, but passing "format": "yyyy-MM-dd" won't succeed. Am I doing wrong assumptions on input format?

I suspect you are suffering from a check that verifies that the date format includes parsing times.
As a workaround, you can use StrptimeParser directly instead of DateTimeInputFormat
(StrptimeParser::from_str(date_time_format_str)).

@fulmicoton
Copy link
Contributor

  1. General logic: I think your approach is ok.

@etolbakov
Copy link
Collaborator Author

@fulmicoton thank you for the response!
Could you please take a look a the changes when you have time?
If that LGTY , I will add a test (not sure where though) and convert it to the PR.

Examples Successful and Failed Responses ⬇️
curl -X GET "http://localhost:7280/api/v1/_elastic/stackoverflow-schemaless/_search?pretty" -H 'Content-Type: application/json' -d'
{
"query": {
  "range": {
    "age": {
      "gte": "2023-01-01",
      "lte": "2023-12-31",
      "boost": 2.0,
      "format": "yyyy-MM-dd"
    }
  }
}
}
'
{
"status": 400,
"error": {
  "caused_by": null,
  "reason": "Failed to parse date time: a character literal was not valid",
  "stack_trace": null,
  "type": null
}
}


curl -X GET "http://localhost:7280/api/v1/_elastic/stackoverflow-schemaless/_search?pretty"
-H 'Content-Type: application/json' -d'
∙ {
∙   "query": {
∙     "range": {
∙       "age": {
∙         "gte": "2023-01-01",
∙         "lte": "2023-12-31",
∙         "boost": 2.0,
∙         "format": "%Y-%m-%d"
∙       }
∙     }
∙   }
∙ }
'
{
"took": 5,
"timed_out": false,
"_shards": {
  "total": 1,
  "successful": 1,
  "skipped": 0,
  "failed": 0
},
"hits": {
  "total": {
    "value": 0,
    "relation": "eq"
  },
  "hits": []
}
}

@etolbakov etolbakov marked this pull request as ready for review July 12, 2024 10:29
@etolbakov
Copy link
Collaborator Author

@fulmicoton
Could you please have a look when you have time?

@fulmicoton fulmicoton merged commit 3c7d0e0 into quickwit-oss:main Jul 16, 2024
4 of 5 checks passed
@fulmicoton
Copy link
Contributor

thank you! I will complete our rest api test suite in another PR and send it to you for next time!

@etolbakov etolbakov deleted the elasticsearch-range-query-format-support branch July 16, 2024 05:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants