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

Date Math does not work in filtered query #2819

Closed
garcimouche opened this issue Mar 27, 2013 · 5 comments
Closed

Date Math does not work in filtered query #2819

garcimouche opened this issue Mar 27, 2013 · 5 comments
Assignees

Comments

@garcimouche
Copy link

newbie to ES.
This does not return any docs:

  "query": {
    "filtered": {
      "query": {
        "match_all": {}
      },
      "filter": {
        "range": {
          "screened": {
            "from": "now-3d",
            "to": "now+3d"
          }
        }
      }
    }
  }

This does:

      "query": {
        "match_all": {}
      },
      "filter": {
        "range": {
          "screened": {
            "from": "now-3d",
            "to": "now+3d"
          }
        }
      }
@imotov
Copy link
Contributor

imotov commented Mar 27, 2013

That might be a duplicate of #2808

@spinscale
Copy link
Contributor

I could not reproduce this immediately on master or 0.90 or 0.20.6.

@garcimouche can you give us some more information, what you did, which data was inserted, how your mapping looks like?

@garcimouche
Copy link
Author

sure
ES v 0.20.6

data:

[
{ 
    "branch": "50",
    "port": 123,
    "user": "MY_USER",
    "shipper_id": 1234567,
    "client_id": 90020690,
    "shipper_name": "MY SHIPPER NAME",
    "client_name": "MY CLIENT NAME",
    "tags":["tag1","tag2"],
    "screened": 20130325110225,
    "shipment-value":503.22
},
{ 
    "branch": "99",
    "port": 351,
    "user": "ANOTHER USER",
    "shipper_id": 1234568,
    "client_id": 90020691,
    "shipper_name": "WALMART",
    "client_name": "TARGET",
    "tags":["tag2","tag3"],
    "screened": 20130325110225,
    "billed": 20130325130527,
    "shipment-value":1503.22,
    "billing-revenue-fees":27.00
}
]

mapping

{
    "settings" : {
        "index.query.default_field" : "client-name",
    },
    "mappings": {
        "entry": {
            "_ttl" : { "enabled" : "true", "default" : "93d" },
            "_all" : {"enabled" : "false"},
            "properties": {
                "branch": {"type":"string", "index" : "not_analyzed"},
                "port": {"type":"integer"},
                "user": {"type":"string", "index" : "not_analyzed"},
                "shipper-id": {"type":"integer"},
                "client-id": {"type":"integer"},
                "shipper-name": {"type":"string", "analyzer": "standard"},
                "client-name": {"type":"string", "analyzer": "standard"},
                "tags": {"type" : "string", "index" : "not_analyzed"},
                "screened": {"type" : "date", "format" : "yyyyMMddhhmmss"},
                "billed": {"type" : "date", "format" : "yyyyMMddhhmmss"},
                "shipment-value": {"type" : "float"},
                "billing-revenue-fees": {"type" : "float"}
            }
        }
    }
}

queries snapshot mentioned in 1st post.

Thank you!

@javanna
Copy link
Member

javanna commented Oct 18, 2013

@garcimouche I had a look at your example data, and actually none of the range queries would actually work with those documents.

The reason is that you did map the screened field as a date, specifying a format or it as well, but that format is used when you submit the document as a string. If you provide it as a number, it will get indexed as is, since date fields are internally represented as long. So, the number doesn't get converted to a string and then parsed as a date...but it gets indexed directly as a time from epoch. In fact in your case the numeric value 20130325110225 was indexed as something like Fri, 27 Nov 2607 20:58:30 GMT I believe.

To solve this you need to submit the field as a string with the specified format (just add double quotes around it). Otherwise if you want to submit it as number, the long must be a time from epoch.

Adding the double quotes both queries work with 0.90.5, also after #2808 was fixed.

@ghost ghost assigned javanna Oct 18, 2013
@javanna
Copy link
Member

javanna commented Feb 14, 2014

Closing, seems like there was an issue with the submitted documents as said above.

@javanna javanna closed this as completed Feb 14, 2014
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

No branches or pull requests

4 participants