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

failed to get data back using "@timestamp" as epoch_second in range query #88048

Closed
iamorchid opened this issue Jun 27, 2022 · 2 comments
Closed
Labels
>bug :Search/Search Search-related issues that do not fall into other categories Team:Search Meta label for search team

Comments

@iamorchid
Copy link

iamorchid commented Jun 27, 2022

Elasticsearch Version

8.2.0

Installed Plugins

No response

Java Version

openjdk version "11.0.2" 2019-01-15 OpenJDK Runtime Environment 18.9 (build 11.0.2+9) OpenJDK 64-Bit Server VM 18.9 (build 11.0.2+9, mixed mode)

OS Version

Linux test 5.14.0+ #4 SMP PREEMPT Tue Sep 7 12:04:46 CST 2021 x86_64 x86_64 x86_64 GNU/Linux

Problem Description

Within my data, there is a field named "@timestamp" whose value is epoch second (in index mapping, I model it as "epoch_second").

{
  "mappings": {
    "properties": {
      "@timestamp": {
        "type": "date",
        "format": "epoch_second"
      }
    }
  }
}

However, I failed to get my data using range query. After some investigation, I found that this is casued by the following logic in DateFieldMapper.java . Namely, from/to in range query would always be parsed as epoch millis (they are integers). I think this is not correct.

            if (forcedDateParser == null) {
                if (lowerTerm instanceof Number || upperTerm instanceof Number) {
                    // force epoch_millis
                    parser = EPOCH_MILLIS_PARSER;
                } else {
                    parser = dateMathParser;
                }
            }

Steps to Reproduce

I think my query is clear enough.

Logs (if relevant)

No response

@iamorchid iamorchid added >bug needs:triage Requires assignment of a team area label labels Jun 27, 2022
@iamorchid iamorchid changed the title failed to get data back using "@timestamp" as epoch_second failed to get data back using "@timestamp" as epoch_second in range query Jun 27, 2022
@gmarouli gmarouli added :Search/Search Search-related issues that do not fall into other categories and removed needs:triage Requires assignment of a team area label labels Jun 27, 2022
@elasticmachine elasticmachine added the Team:Search Meta label for search team label Jun 27, 2022
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-search (Team:Search)

@ywelsch
Copy link
Contributor

ywelsch commented Jun 27, 2022

This is how it's documented (see https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-range-query.html#numeric-date). If you want the value to represent an epoch_second, you need to pass it as a String value (e.g. "1656327911") that will be parsed according to the set format.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>bug :Search/Search Search-related issues that do not fall into other categories Team:Search Meta label for search team
Projects
None yet
Development

No branches or pull requests

4 participants