Skip to content

Conversation

@dadoonet
Copy link
Contributor

Query String query now supports a new time_zone option based on JODA time zones.
When using a range on date field, the time zone is applied.

{
"query": {
  "query_string": {
    "text": "date:[2012 TO 2014]",
    "timezone": "Europe/Paris"
  }
 }
}

Closes #7880.

@jpountz
Copy link
Contributor

jpountz commented Oct 20, 2014

This looks good, should we add the same feature to the simple_query_string query for consistency?

@dadoonet
Copy link
Contributor Author

@jpountz Indeed! That was my plan at the beginning and it sounds like I forgot it :)

@dadoonet dadoonet changed the title Add time_zone setting for query_string Add time_zone setting for query_string and simple_query_string Oct 20, 2014
@dadoonet dadoonet changed the title Add time_zone setting for query_string and simple_query_string Add time_zone setting for query_string Oct 20, 2014
@dadoonet
Copy link
Contributor Author

@jpountz Actually, simple_query_string does not support yet range queries. So for now, this PR can be only applied onto query_string.

@jpountz
Copy link
Contributor

jpountz commented Oct 20, 2014

LGTM

@jpountz jpountz removed the review label Oct 20, 2014
@dadoonet dadoonet force-pushed the issue/7880-timezone_query_string branch from aa92782 to 0ff61e1 Compare October 20, 2014 17:36
@dadoonet dadoonet closed this Oct 20, 2014
@dadoonet
Copy link
Contributor Author

Merged in master and 1.x with commits: 0ff61e1 and 9fd06b1

@dadoonet dadoonet deleted the issue/7880-timezone_query_string branch October 20, 2014 17:39
@im-denisenko im-denisenko mentioned this pull request Apr 6, 2015
16 tasks
@im-denisenko
Copy link

@dadoonet Could you have a look please? Either this option not working or I don't understand how it should work.

I have following code:

curl -XPUT 'http://localhost:9200/foo/?pretty' -d '{"mapping": {"tweets": {"properties": {"tweet_date": {"type": "date"}}}}}'
curl -XPOST 'http://localhost:9200/foo/tweets/1/' -d '{"tweet_date": "2015-04-05T23:00:00+0000"}'
curl -XPOST 'http://localhost:9200/foo/tweets/2/' -d '{"tweet_date": "2015-04-06T00:00:00+0000"}'
curl -XPOST 'http://localhost:9200/foo/_refresh?pretty'

curl -XGET 'http://localhost:9200/foo/tweets/_search?pretty' -d '{
    "query": {
        "query_string": {
            "query": "tweet_date:[2015-04-06T00:00:00+0200 TO 2015-04-06T23:00:00+0200]"
        }
    }
}'

curl -XGET 'http://localhost:9200/foo/tweets/_search?pretty' -d '{
    "query": {
        "query_string": {
            "query": "tweet_date:[2015-04-06T00:00:00 TO 2015-04-06T23:00:00]",
            "time_zone": "+0200"
        }
    }
}'

First query result:

{
  "hits" : {
    "total" : 2,
    "max_score" : 1.0,
    "hits" : [ {
      "_index" : "foo",
      "_type" : "tweets",
      "_id" : "2",
      "_score" : 1.0,
      "_source":{"tweet_date": "2015-04-06T00:00:00+0000"}
    }, {
      "_index" : "foo",
      "_type" : "tweets",
      "_id" : "1",
      "_score" : 1.0,
      "_source":{"tweet_date": "2015-04-05T23:00:00+0000"}
    } ]
  }
}

Second query result:

{
  "hits" : {
    "total" : 1,
    "max_score" : 1.0,
    "hits" : [ {
      "_index" : "foo",
      "_type" : "tweets",
      "_id" : "2",
      "_score" : 1.0,
      "_source":{"tweet_date": "2015-04-06T00:00:00+0000"}
    } ]
  }
}

Shouldn't these results be the same?

@dadoonet
Copy link
Contributor Author

dadoonet commented Apr 7, 2015

@im-denisenko I think they should. If you are using Elasticsearch 1.5.0, I'd open an issue with this great full reproduction script.

@im-denisenko
Copy link

@dadoonet Yes, this is 1.5.0
Thanks for answer. It resolves all my "wtf" for last few hours :)

@dadoonet
Copy link
Contributor Author

dadoonet commented Apr 8, 2015

@im-denisenko Could you open an issue so we won't forget to add some tests and fix it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

>feature :Search/Search Search-related issues that do not fall into other categories v1.5.0 v2.0.0-beta1

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add timezone setting for query_string

4 participants