Fix TemplateQueryParser swallows additional parameters
Request parameters such as "size" and "fields" were ignored when placed after the template query in the reqest. closes #5933
This commit is contained in:
parent
d8f0f7077f
commit
c7bb784b08
|
@ -74,7 +74,6 @@ public class TemplateQueryParser implements QueryParser {
|
||||||
final QueryParseContext context = new QueryParseContext(parseContext.index(), parseContext.indexQueryParser);
|
final QueryParseContext context = new QueryParseContext(parseContext.index(), parseContext.indexQueryParser);
|
||||||
context.reset(qSourceParser);
|
context.reset(qSourceParser);
|
||||||
Query result = context.parseInnerQuery();
|
Query result = context.parseInnerQuery();
|
||||||
parser.nextToken();
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,8 @@ import org.elasticsearch.action.search.SearchResponse;
|
||||||
import org.elasticsearch.common.bytes.BytesArray;
|
import org.elasticsearch.common.bytes.BytesArray;
|
||||||
import org.elasticsearch.common.bytes.BytesReference;
|
import org.elasticsearch.common.bytes.BytesReference;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
|
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||||
import org.elasticsearch.test.ElasticsearchIntegrationTest;
|
import org.elasticsearch.test.ElasticsearchIntegrationTest;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
@ -35,6 +37,8 @@ import java.util.Map;
|
||||||
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
|
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
|
||||||
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
|
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
|
||||||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount;
|
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount;
|
||||||
|
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoFailures;
|
||||||
|
import static org.hamcrest.Matchers.equalTo;
|
||||||
import static org.hamcrest.Matchers.is;
|
import static org.hamcrest.Matchers.is;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -71,6 +75,42 @@ public class TemplateQueryTest extends ElasticsearchIntegrationTest {
|
||||||
assertHitCount(sr, 2);
|
assertHitCount(sr, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testTemplateInBodyWithSize() throws IOException {
|
||||||
|
String request = "{\n" +
|
||||||
|
" \"size\":0,"+
|
||||||
|
" \"query\": {\n" +
|
||||||
|
" \"template\": {\n" +
|
||||||
|
" \"query\": {\"match_{{template}}\": {}},\n" +
|
||||||
|
" \"params\" : {\n" +
|
||||||
|
" \"template\" : \"all\"\n" +
|
||||||
|
" }\n" +
|
||||||
|
" }\n" +
|
||||||
|
" }\n" +
|
||||||
|
"}";
|
||||||
|
SearchResponse sr = client().prepareSearch().setSource(request)
|
||||||
|
.execute().actionGet();
|
||||||
|
assertNoFailures(sr);
|
||||||
|
assertThat(sr.getHits().hits().length, equalTo(0));
|
||||||
|
request = "{\n" +
|
||||||
|
" \"query\": {\n" +
|
||||||
|
" \"template\": {\n" +
|
||||||
|
" \"query\": {\"match_{{template}}\": {}},\n" +
|
||||||
|
" \"params\" : {\n" +
|
||||||
|
" \"template\" : \"all\"\n" +
|
||||||
|
" }\n" +
|
||||||
|
" }\n" +
|
||||||
|
" },\n" +
|
||||||
|
" \"size\":0"+
|
||||||
|
"}";
|
||||||
|
|
||||||
|
sr = client().prepareSearch().setSource(request)
|
||||||
|
.execute().actionGet();
|
||||||
|
assertNoFailures(sr);
|
||||||
|
assertThat(sr.getHits().hits().length, equalTo(0));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTemplateWOReplacementInBody() throws IOException {
|
public void testTemplateWOReplacementInBody() throws IOException {
|
||||||
Map<String, Object> vars = new HashMap<>();
|
Map<String, Object> vars = new HashMap<>();
|
||||||
|
|
Loading…
Reference in New Issue