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 in query_string caches now() #2808

Closed
clintongormley opened this issue Mar 22, 2013 · 1 comment
Closed

Date math in query_string caches now() #2808

clintongormley opened this issue Mar 22, 2013 · 1 comment

Comments

@clintongormley
Copy link

When using "now" in date math in the query string, the value for now is cached:

curl -XPUT 'http://127.0.0.1:9200/test/?pretty=1'  -d '
{
   "mappings" : {
      "test" : {
         "properties" : {
            "date" : {
               "type" : "date"
            }
         }
      }
   }
}
'

curl -XPOST 'http://127.0.0.1:9200/test/test?pretty=1'  -d '
{
   "date" : "2020-01-01"
}
'

Run this query multiple times:

curl -XGET 'http://127.0.0.1:9200/test/test/_search?pretty=1'  -d '
{
   "query" : {
      "query_string" : {
         "query" : "date:[now TO *]"
      }
   },
   "explain" : 1
}
'

You will see that the description line "ConstantScore(date:[1363953493782 TO *])" reuses the same start date

# {
#    "hits" : {
#       "hits" : [
#          {
#             "_source" : {
#                "date" : "2020-01-01"
#             },
#             "_score" : 1,
#             "_index" : "test",
#             "_shard" : 4,
#             "_id" : "iOPrtwzdQFGixdfwaAAlcQ",
#             "_node" : "gx3hk4y7S0Khhx8IQ4uYQQ",
#             "_type" : "test",
#             "_explanation" : {
#                "value" : 1,
#                "details" : [
#                   {
#                      "value" : 1,
#                      "description" : "boost"
#                   },
#                   {
#                      "value" : 1,
#                      "description" : "queryNorm"
#                   }
#                ],
#                "description" : "ConstantScore(date:[1363953493782 TO *]), product of:"
#             }
#          }
#       ],
#       "max_score" : 1,
#       "total" : 1
#    },
#    "timed_out" : false,
#    "_shards" : {
#       "failed" : 0,
#       "successful" : 5,
#       "total" : 5
#    },
#    "took" : 5
# }

A range query on the other hand, updates the start date on each run:

curl -XGET 'http://127.0.0.1:9200/test/test/_search?pretty=1'  -d '
{
   "query" : {
      "range" : {
         "date" : {
            "gt" : "now"
         }
      }
   },
   "explain" : 1
}
'
@clintongormley
Copy link
Author

Also see #2809

@kimchy kimchy closed this as completed in c18c609 Mar 27, 2013
kimchy added a commit that referenced this issue Mar 27, 2013
pdegeus added a commit to pdegeus/elasticsearch that referenced this issue Mar 28, 2013
# By Shay Banon (2) and others
# Via Shay Banon
* commit '473473e86762b72c13d435a23fb4a8330c692487':
  remove the field settings for query parser cache, not really relevant
  Date math in query_string caches now() fixes elastic#2808
  Move applying alias filter to ContextSearch#preProcess()
  Terminate early when no terms left in the suggest string.
martijnvg pushed a commit to martijnvg/elasticsearch that referenced this issue Jan 31, 2018
This change removes the InternalClient and the InternalSecurityClient. These are replaced with
usage of the ThreadContext and a transient value, `action.origin`, to indicate which component the
request came from. The security code has been updated to look for this value and ensure the
request is executed as the proper user. This work comes from elastic#2808 where @s1monw suggested
that we do this.

While working on this, I came across index template registries and rather than updating them to use
the new method, I replaced the ML one with the template upgrade framework so that we could
remove this template registry. The watcher template registry is still needed as the template must be
updated for rolling upgrades to work (see elastic#2950).
martijnvg pushed a commit that referenced this issue Feb 5, 2018
This change removes the InternalClient and the InternalSecurityClient. These are replaced with
usage of the ThreadContext and a transient value, `action.origin`, to indicate which component the
request came from. The security code has been updated to look for this value and ensure the
request is executed as the proper user. This work comes from #2808 where @s1monw suggested
that we do this.

While working on this, I came across index template registries and rather than updating them to use
the new method, I replaced the ML one with the template upgrade framework so that we could
remove this template registry. The watcher template registry is still needed as the template must be
updated for rolling upgrades to work (see #2950).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant