If searchContext not set, abort parsing and throw ISE
This commit is contained in:
parent
c884304753
commit
dd12e0b86c
|
@ -21,6 +21,7 @@ package org.elasticsearch.index.query;
|
||||||
|
|
||||||
import org.apache.lucene.search.Filter;
|
import org.apache.lucene.search.Filter;
|
||||||
import org.apache.lucene.search.Query;
|
import org.apache.lucene.search.Query;
|
||||||
|
import org.elasticsearch.ElasticSearchIllegalStateException;
|
||||||
import org.elasticsearch.common.Strings;
|
import org.elasticsearch.common.Strings;
|
||||||
import org.elasticsearch.common.inject.Inject;
|
import org.elasticsearch.common.inject.Inject;
|
||||||
import org.elasticsearch.common.lucene.search.XConstantScoreQuery;
|
import org.elasticsearch.common.lucene.search.XConstantScoreQuery;
|
||||||
|
@ -106,13 +107,13 @@ public class HasChildFilterParser implements FilterParser {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!queryFound) {
|
if (!queryFound) {
|
||||||
throw new QueryParsingException(parseContext.index(), "[child] filter requires 'query' field");
|
throw new QueryParsingException(parseContext.index(), "[has_child] filter requires 'query' field");
|
||||||
}
|
}
|
||||||
if (query == null) {
|
if (query == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (childType == null) {
|
if (childType == null) {
|
||||||
throw new QueryParsingException(parseContext.index(), "[child] filter requires 'type' field");
|
throw new QueryParsingException(parseContext.index(), "[has_child] filter requires 'type' field");
|
||||||
}
|
}
|
||||||
|
|
||||||
DocumentMapper childDocMapper = parseContext.mapperService().documentMapper(childType);
|
DocumentMapper childDocMapper = parseContext.mapperService().documentMapper(childType);
|
||||||
|
@ -128,6 +129,9 @@ public class HasChildFilterParser implements FilterParser {
|
||||||
query = new XFilteredQuery(query, parseContext.cacheFilter(childDocMapper.typeFilter(), null));
|
query = new XFilteredQuery(query, parseContext.cacheFilter(childDocMapper.typeFilter(), null));
|
||||||
|
|
||||||
SearchContext searchContext = SearchContext.current();
|
SearchContext searchContext = SearchContext.current();
|
||||||
|
if (searchContext == null) {
|
||||||
|
throw new ElasticSearchIllegalStateException("[has_child] Can't execute, search context not set.");
|
||||||
|
}
|
||||||
|
|
||||||
HasChildFilter childFilter = HasChildFilter.create(query, parentType, childType, searchContext);
|
HasChildFilter childFilter = HasChildFilter.create(query, parentType, childType, searchContext);
|
||||||
searchContext.addRewrite(childFilter);
|
searchContext.addRewrite(childFilter);
|
||||||
|
|
|
@ -22,6 +22,7 @@ package org.elasticsearch.index.query;
|
||||||
import org.apache.lucene.search.ConstantScoreQuery;
|
import org.apache.lucene.search.ConstantScoreQuery;
|
||||||
import org.apache.lucene.search.Filter;
|
import org.apache.lucene.search.Filter;
|
||||||
import org.apache.lucene.search.Query;
|
import org.apache.lucene.search.Query;
|
||||||
|
import org.elasticsearch.ElasticSearchIllegalStateException;
|
||||||
import org.elasticsearch.common.Strings;
|
import org.elasticsearch.common.Strings;
|
||||||
import org.elasticsearch.common.inject.Inject;
|
import org.elasticsearch.common.inject.Inject;
|
||||||
import org.elasticsearch.common.xcontent.XContentParser;
|
import org.elasticsearch.common.xcontent.XContentParser;
|
||||||
|
@ -118,6 +119,9 @@ public class HasChildQueryParser implements QueryParser {
|
||||||
|
|
||||||
// wrap the query with type query
|
// wrap the query with type query
|
||||||
SearchContext searchContext = SearchContext.current();
|
SearchContext searchContext = SearchContext.current();
|
||||||
|
if (searchContext == null) {
|
||||||
|
throw new ElasticSearchIllegalStateException("[has_child] Can't execute, search context not set.");
|
||||||
|
}
|
||||||
Query query;
|
Query query;
|
||||||
if (scoreType != null) {
|
if (scoreType != null) {
|
||||||
Filter parentFilter = parseContext.cacheFilter(parentDocMapper.typeFilter(), null);
|
Filter parentFilter = parseContext.cacheFilter(parentDocMapper.typeFilter(), null);
|
||||||
|
|
|
@ -21,6 +21,7 @@ package org.elasticsearch.index.query;
|
||||||
|
|
||||||
import org.apache.lucene.search.Filter;
|
import org.apache.lucene.search.Filter;
|
||||||
import org.apache.lucene.search.Query;
|
import org.apache.lucene.search.Query;
|
||||||
|
import org.elasticsearch.ElasticSearchIllegalStateException;
|
||||||
import org.elasticsearch.common.Strings;
|
import org.elasticsearch.common.Strings;
|
||||||
import org.elasticsearch.common.inject.Inject;
|
import org.elasticsearch.common.inject.Inject;
|
||||||
import org.elasticsearch.common.lucene.search.XConstantScoreQuery;
|
import org.elasticsearch.common.lucene.search.XConstantScoreQuery;
|
||||||
|
@ -105,25 +106,29 @@ public class HasParentFilterParser implements FilterParser {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!queryFound) {
|
if (!queryFound) {
|
||||||
throw new QueryParsingException(parseContext.index(), "[parent] filter requires 'query' field");
|
throw new QueryParsingException(parseContext.index(), "[has_parent] filter requires 'query' field");
|
||||||
}
|
}
|
||||||
if (query == null) {
|
if (query == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (parentType == null) {
|
if (parentType == null) {
|
||||||
throw new QueryParsingException(parseContext.index(), "[parent] filter requires 'parent_type' field");
|
throw new QueryParsingException(parseContext.index(), "[has_parent] filter requires 'parent_type' field");
|
||||||
}
|
}
|
||||||
|
|
||||||
DocumentMapper parentDocMapper = parseContext.mapperService().documentMapper(parentType);
|
DocumentMapper parentDocMapper = parseContext.mapperService().documentMapper(parentType);
|
||||||
if (parentDocMapper == null) {
|
if (parentDocMapper == null) {
|
||||||
throw new QueryParsingException(parseContext.index(), "[parent] filter configured 'parent_type' [" + parentType + "] is not a valid type");
|
throw new QueryParsingException(parseContext.index(), "[has_parent] filter configured 'parent_type' [" + parentType + "] is not a valid type");
|
||||||
}
|
}
|
||||||
|
|
||||||
// wrap the query with type query
|
// wrap the query with type query
|
||||||
query = new XFilteredQuery(query, parseContext.cacheFilter(parentDocMapper.typeFilter(), null));
|
query = new XFilteredQuery(query, parseContext.cacheFilter(parentDocMapper.typeFilter(), null));
|
||||||
|
|
||||||
SearchContext searchContext = SearchContext.current();
|
SearchContext searchContext = SearchContext.current();
|
||||||
|
// In case of delete by query api
|
||||||
|
if (searchContext == null) {
|
||||||
|
throw new ElasticSearchIllegalStateException("[has_parent] Can't execute, search context not set");
|
||||||
|
}
|
||||||
|
|
||||||
HasParentFilter parentFilter = HasParentFilter.create(query, parentType, searchContext);
|
HasParentFilter parentFilter = HasParentFilter.create(query, parentType, searchContext);
|
||||||
searchContext.addRewrite(parentFilter);
|
searchContext.addRewrite(parentFilter);
|
||||||
|
|
|
@ -23,6 +23,7 @@ import org.apache.lucene.search.BooleanClause;
|
||||||
import org.apache.lucene.search.ConstantScoreQuery;
|
import org.apache.lucene.search.ConstantScoreQuery;
|
||||||
import org.apache.lucene.search.Filter;
|
import org.apache.lucene.search.Filter;
|
||||||
import org.apache.lucene.search.Query;
|
import org.apache.lucene.search.Query;
|
||||||
|
import org.elasticsearch.ElasticSearchIllegalStateException;
|
||||||
import org.elasticsearch.common.Strings;
|
import org.elasticsearch.common.Strings;
|
||||||
import org.elasticsearch.common.inject.Inject;
|
import org.elasticsearch.common.inject.Inject;
|
||||||
import org.elasticsearch.common.lucene.search.XBooleanFilter;
|
import org.elasticsearch.common.lucene.search.XBooleanFilter;
|
||||||
|
@ -99,19 +100,19 @@ public class HasParentQueryParser implements QueryParser {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!queryFound) {
|
if (!queryFound) {
|
||||||
throw new QueryParsingException(parseContext.index(), "[parent] query requires 'query' field");
|
throw new QueryParsingException(parseContext.index(), "[has_parent] query requires 'query' field");
|
||||||
}
|
}
|
||||||
if (innerQuery == null) {
|
if (innerQuery == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (parentType == null) {
|
if (parentType == null) {
|
||||||
throw new QueryParsingException(parseContext.index(), "[parent] query requires 'parent_type' field");
|
throw new QueryParsingException(parseContext.index(), "[has_parent] query requires 'parent_type' field");
|
||||||
}
|
}
|
||||||
|
|
||||||
DocumentMapper parentDocMapper = parseContext.mapperService().documentMapper(parentType);
|
DocumentMapper parentDocMapper = parseContext.mapperService().documentMapper(parentType);
|
||||||
if (parentDocMapper == null) {
|
if (parentDocMapper == null) {
|
||||||
throw new QueryParsingException(parseContext.index(), "[parent] query configured 'parent_type' [" + parentType + "] is not a valid type");
|
throw new QueryParsingException(parseContext.index(), "[has_parent] query configured 'parent_type' [" + parentType + "] is not a valid type");
|
||||||
}
|
}
|
||||||
|
|
||||||
List<String> childTypes = new ArrayList<String>(2);
|
List<String> childTypes = new ArrayList<String>(2);
|
||||||
|
@ -144,6 +145,10 @@ public class HasParentQueryParser implements QueryParser {
|
||||||
// wrap the query with type query
|
// wrap the query with type query
|
||||||
innerQuery = new XFilteredQuery(innerQuery, parseContext.cacheFilter(parentDocMapper.typeFilter(), null));
|
innerQuery = new XFilteredQuery(innerQuery, parseContext.cacheFilter(parentDocMapper.typeFilter(), null));
|
||||||
SearchContext searchContext = SearchContext.current();
|
SearchContext searchContext = SearchContext.current();
|
||||||
|
if (searchContext == null) {
|
||||||
|
throw new ElasticSearchIllegalStateException("[has_parent] Can't execute, search context not set.");
|
||||||
|
}
|
||||||
|
|
||||||
Query query;
|
Query query;
|
||||||
if (score) {
|
if (score) {
|
||||||
ParentQuery parentQuery = new ParentQuery(searchContext, innerQuery, parentType, childTypes, childFilter);
|
ParentQuery parentQuery = new ParentQuery(searchContext, innerQuery, parentType, childTypes, childFilter);
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
package org.elasticsearch.index.query;
|
package org.elasticsearch.index.query;
|
||||||
|
|
||||||
import org.apache.lucene.search.Query;
|
import org.apache.lucene.search.Query;
|
||||||
|
import org.elasticsearch.ElasticSearchIllegalStateException;
|
||||||
import org.elasticsearch.common.Strings;
|
import org.elasticsearch.common.Strings;
|
||||||
import org.elasticsearch.common.inject.Inject;
|
import org.elasticsearch.common.inject.Inject;
|
||||||
import org.elasticsearch.common.lucene.search.XFilteredQuery;
|
import org.elasticsearch.common.lucene.search.XFilteredQuery;
|
||||||
|
@ -97,10 +98,10 @@ public class TopChildrenQueryParser implements QueryParser {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!queryFound) {
|
if (!queryFound) {
|
||||||
throw new QueryParsingException(parseContext.index(), "[child] requires 'query' field");
|
throw new QueryParsingException(parseContext.index(), "[top_children] requires 'query' field");
|
||||||
}
|
}
|
||||||
if (childType == null) {
|
if (childType == null) {
|
||||||
throw new QueryParsingException(parseContext.index(), "[child] requires 'type' field");
|
throw new QueryParsingException(parseContext.index(), "[top_children] requires 'type' field");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (query == null) {
|
if (query == null) {
|
||||||
|
@ -121,6 +122,9 @@ public class TopChildrenQueryParser implements QueryParser {
|
||||||
query = new XFilteredQuery(query, parseContext.cacheFilter(childDocMapper.typeFilter(), null));
|
query = new XFilteredQuery(query, parseContext.cacheFilter(childDocMapper.typeFilter(), null));
|
||||||
|
|
||||||
SearchContext searchContext = SearchContext.current();
|
SearchContext searchContext = SearchContext.current();
|
||||||
|
if (searchContext == null) {
|
||||||
|
throw new ElasticSearchIllegalStateException("[top_children] Can't execute, search context not set.");
|
||||||
|
}
|
||||||
TopChildrenQuery childQuery = new TopChildrenQuery(searchContext, query, childType, parentType, scoreType, factor, incrementalFactor);
|
TopChildrenQuery childQuery = new TopChildrenQuery(searchContext, query, childType, parentType, scoreType, factor, incrementalFactor);
|
||||||
searchContext.addRewrite(childQuery);
|
searchContext.addRewrite(childQuery);
|
||||||
return childQuery;
|
return childQuery;
|
||||||
|
|
Loading…
Reference in New Issue