Added more unit like test that verifies that has_child is never cached even if wrapped by another filter.
This commit is contained in:
parent
2f32908193
commit
2d58603e81
|
@ -32,6 +32,7 @@ import org.elasticsearch.common.inject.AbstractModule;
|
|||
import org.elasticsearch.common.inject.Injector;
|
||||
import org.elasticsearch.common.inject.ModulesBuilder;
|
||||
import org.elasticsearch.common.inject.util.Providers;
|
||||
import org.elasticsearch.common.lucene.search.AndFilter;
|
||||
import org.elasticsearch.common.lucene.search.CachedFilter;
|
||||
import org.elasticsearch.common.lucene.search.NoCacheFilter;
|
||||
import org.elasticsearch.common.lucene.search.XBooleanFilter;
|
||||
|
@ -47,12 +48,14 @@ import org.elasticsearch.index.engine.IndexEngineModule;
|
|||
import org.elasticsearch.index.mapper.MapperService;
|
||||
import org.elasticsearch.index.mapper.MapperServiceModule;
|
||||
import org.elasticsearch.index.query.functionscore.FunctionScoreModule;
|
||||
import org.elasticsearch.index.search.child.TestSearchContext;
|
||||
import org.elasticsearch.index.settings.IndexSettingsModule;
|
||||
import org.elasticsearch.index.similarity.SimilarityModule;
|
||||
import org.elasticsearch.indices.fielddata.breaker.CircuitBreakerService;
|
||||
import org.elasticsearch.indices.fielddata.breaker.DummyCircuitBreakerService;
|
||||
import org.elasticsearch.indices.query.IndicesQueriesModule;
|
||||
import org.elasticsearch.script.ScriptModule;
|
||||
import org.elasticsearch.search.internal.SearchContext;
|
||||
import org.elasticsearch.test.ElasticsearchTestCase;
|
||||
import org.elasticsearch.threadpool.ThreadPool;
|
||||
import org.elasticsearch.threadpool.ThreadPoolModule;
|
||||
|
@ -109,6 +112,8 @@ public class IndexQueryParserFilterCachingTests extends ElasticsearchTestCase {
|
|||
|
||||
String mapping = copyToStringFromClasspath("/org/elasticsearch/index/query/mapping.json");
|
||||
injector.getInstance(MapperService.class).merge("person", new CompressedString(mapping), true);
|
||||
String childMapping = copyToStringFromClasspath("/org/elasticsearch/index/query/child-mapping.json");
|
||||
injector.getInstance(MapperService.class).merge("child", new CompressedString(childMapping), true);
|
||||
injector.getInstance(MapperService.class).documentMapper("person").parse(new BytesArray(copyToBytesFromClasspath("/org/elasticsearch/index/query/data.json")));
|
||||
queryParser = injector.getInstance(IndexQueryParserService.class);
|
||||
}
|
||||
|
@ -152,6 +157,26 @@ public class IndexQueryParserFilterCachingTests extends ElasticsearchTestCase {
|
|||
parsedQuery = queryParser.parse(query).query();
|
||||
assertThat(parsedQuery, instanceOf(ConstantScoreQuery.class));
|
||||
assertThat(((ConstantScoreQuery) parsedQuery).getFilter(), instanceOf(CachedFilter.class));
|
||||
|
||||
try {
|
||||
SearchContext.setCurrent(new TestSearchContext());
|
||||
query = copyToStringFromClasspath("/org/elasticsearch/index/query/has-child.json");
|
||||
parsedQuery = queryParser.parse(query).query();
|
||||
assertThat(parsedQuery, instanceOf(ConstantScoreQuery.class));
|
||||
assertThat(((ConstantScoreQuery) parsedQuery).getFilter(), instanceOf(NoCacheFilter.class));
|
||||
|
||||
query = copyToStringFromClasspath("/org/elasticsearch/index/query/and-filter-cache.json");
|
||||
parsedQuery = queryParser.parse(query).query();
|
||||
assertThat(parsedQuery, instanceOf(ConstantScoreQuery.class));
|
||||
assertThat(((ConstantScoreQuery) parsedQuery).getFilter(), instanceOf(CachedFilter.class));
|
||||
|
||||
query = copyToStringFromClasspath("/org/elasticsearch/index/query/has-child-in-and-filter-cached.json");
|
||||
parsedQuery = queryParser.parse(query).query();
|
||||
assertThat(parsedQuery, instanceOf(ConstantScoreQuery.class));
|
||||
assertThat(((ConstantScoreQuery) parsedQuery).getFilter(), instanceOf(AndFilter.class));
|
||||
} finally {
|
||||
SearchContext.removeCurrent();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
{
|
||||
"filtered":{
|
||||
"filter":{
|
||||
"and":{
|
||||
"filters":[
|
||||
{
|
||||
"term":{
|
||||
"name.first":"shay1"
|
||||
}
|
||||
},
|
||||
{
|
||||
"term":{
|
||||
"name.first":"shay4"
|
||||
}
|
||||
}
|
||||
],
|
||||
"_cache" : true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
{
|
||||
"child":{
|
||||
"properties":{
|
||||
"field":{
|
||||
"type":"string"
|
||||
}
|
||||
},
|
||||
"_parent" : {
|
||||
"type" : "person"
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
{
|
||||
"filtered":{
|
||||
"filter":{
|
||||
"and" : {
|
||||
"filters" : [
|
||||
{
|
||||
"has_child" : {
|
||||
"type" : "child",
|
||||
"query" : {
|
||||
"match_all" : {}
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"_cache" : true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
{
|
||||
"filtered":{
|
||||
"filter":{
|
||||
"has_child" : {
|
||||
"type" : "child",
|
||||
"query" : {
|
||||
"match_all" : {}
|
||||
},
|
||||
"_cache" : true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -63,7 +63,7 @@ import org.elasticsearch.search.suggest.SuggestionSearchContext;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
class TestSearchContext extends SearchContext {
|
||||
public class TestSearchContext extends SearchContext {
|
||||
|
||||
final CacheRecycler cacheRecycler;
|
||||
final PageCacheRecycler pageCacheRecycler;
|
||||
|
@ -74,7 +74,7 @@ class TestSearchContext extends SearchContext {
|
|||
ContextIndexSearcher searcher;
|
||||
int size;
|
||||
|
||||
TestSearchContext(CacheRecycler cacheRecycler, PageCacheRecycler pageCacheRecycler, IdCache idCache, IndexService indexService, FilterCache filterCache) {
|
||||
public TestSearchContext(CacheRecycler cacheRecycler, PageCacheRecycler pageCacheRecycler, IdCache idCache, IndexService indexService, FilterCache filterCache) {
|
||||
this.cacheRecycler = cacheRecycler;
|
||||
this.pageCacheRecycler = pageCacheRecycler;
|
||||
this.idCache = idCache;
|
||||
|
@ -82,6 +82,14 @@ class TestSearchContext extends SearchContext {
|
|||
this.filterCache = filterCache;
|
||||
}
|
||||
|
||||
public TestSearchContext() {
|
||||
this.cacheRecycler = null;
|
||||
this.pageCacheRecycler = null;
|
||||
this.idCache = null;
|
||||
this.indexService = null;
|
||||
this.filterCache = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean clearAndRelease() {
|
||||
return false;
|
||||
|
|
Loading…
Reference in New Issue