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

Query string time zone not working #10883

Merged
merged 1 commit into from Apr 29, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -35,6 +35,7 @@
import org.elasticsearch.common.unit.Fuzziness;
import org.elasticsearch.index.mapper.FieldMapper;
import org.elasticsearch.index.mapper.MapperService;
import org.elasticsearch.index.mapper.core.DateFieldMapper;
import org.elasticsearch.index.query.QueryParseContext;
import org.elasticsearch.index.query.support.QueryParsers;

Expand Down Expand Up @@ -128,9 +129,6 @@ public void reset(QueryParserSettings settings) {
setFuzzyMinSim(settings.fuzzyMinSim());
setFuzzyPrefixLength(settings.fuzzyPrefixLength());
setLocale(settings.locale());
if (settings.timeZone() != null) {
setTimeZone(settings.timeZone().toTimeZone());
}
this.analyzeWildcard = settings.analyzeWildcard();
}

Expand Down Expand Up @@ -383,7 +381,13 @@ private Query getRangeQuerySingle(String field, String part1, String part2, bool
}

try {
Query rangeQuery = currentMapper.rangeQuery(part1, part2, startInclusive, endInclusive, parseContext);
Query rangeQuery;
if (currentMapper instanceof DateFieldMapper && settings.timeZone() != null) {
DateFieldMapper dateFieldMapper = (DateFieldMapper) this.currentMapper;
rangeQuery = dateFieldMapper.rangeQuery(part1, part2, startInclusive, endInclusive, settings.timeZone(), null, parseContext);
} else {
rangeQuery = currentMapper.rangeQuery(part1, part2, startInclusive, endInclusive, parseContext);
}
return wrapSmartNameQuery(rangeQuery, fieldMappers, parseContext);
} catch (RuntimeException e) {
if (settings.lenient()) {
Expand Down
42 changes: 40 additions & 2 deletions src/test/java/org/elasticsearch/search/query/SearchQueryTests.java
Expand Up @@ -170,8 +170,8 @@ public void testIndexOptions() throws Exception {
assertHitCount(searchResponse, 1l);

assertFailures(client().prepareSearch().setQuery(matchQuery("field1", "quick brown").type(Type.PHRASE).slop(0)),
RestStatus.INTERNAL_SERVER_ERROR,
containsString("field \"field1\" was indexed without position data; cannot run PhraseQuery (term=quick"));
RestStatus.INTERNAL_SERVER_ERROR,
containsString("field \"field1\" was indexed without position data; cannot run PhraseQuery (term=quick"));
}

@Test // see #3521
Expand Down Expand Up @@ -586,6 +586,44 @@ public void testDateRangeInQueryStringWithTimeZone_7880() {
assertHitCount(searchResponse, 1l);
}

@Test // https://github.com/elasticsearch/elasticsearch/issues/10477
public void testDateRangeInQueryStringWithTimeZone_10477() {
//the mapping needs to be provided upfront otherwise we are not sure how many failures we get back
//as with dynamic mappings some shards might be lacking behind and parse a different query
assertAcked(prepareCreate("test").addMapping(
"type", "past", "type=date"
));
ensureGreen();

client().prepareIndex("test", "type", "1").setSource("past", "2015-04-05T23:00:00+0000").get();
client().prepareIndex("test", "type", "2").setSource("past", "2015-04-06T00:00:00+0000").get();
refresh();

// Timezone set with dates
SearchResponse searchResponse = client().prepareSearch()
.setQuery(queryStringQuery("past:[2015-04-06T00:00:00+0200 TO 2015-04-06T23:00:00+0200]"))
.get();
assertHitCount(searchResponse, 2l);

// Same timezone set with time_zone
searchResponse = client().prepareSearch()
.setQuery(queryStringQuery("past:[2015-04-06T00:00:00 TO 2015-04-06T23:00:00]").timeZone("+0200"))
.get();
assertHitCount(searchResponse, 2l);

// We set a timezone which will give no result
searchResponse = client().prepareSearch()
.setQuery(queryStringQuery("past:[2015-04-06T00:00:00-0200 TO 2015-04-06T23:00:00-0200]"))
.get();
assertHitCount(searchResponse, 0l);

// Same timezone set with time_zone but another timezone is set directly within dates which has the precedence
searchResponse = client().prepareSearch()
.setQuery(queryStringQuery("past:[2015-04-06T00:00:00-0200 TO 2015-04-06T23:00:00-0200]").timeZone("+0200"))
.get();
assertHitCount(searchResponse, 0l);
}

@Test
public void typeFilterTypeIndexedTests() throws Exception {
typeFilterTests("not_analyzed");
Expand Down