Merge pull request #17238 from cbuescher/simplify-nestedInnerQueryParseSupport
Remove unused methods and fields in NestedInnerQueryParseSupport
This commit is contained in:
commit
ff021c60d9
|
@ -20,9 +20,7 @@
|
||||||
package org.elasticsearch.index.query.support;
|
package org.elasticsearch.index.query.support;
|
||||||
|
|
||||||
import org.apache.lucene.search.Query;
|
import org.apache.lucene.search.Query;
|
||||||
import org.apache.lucene.search.join.BitSetProducer;
|
|
||||||
import org.elasticsearch.common.bytes.BytesReference;
|
import org.elasticsearch.common.bytes.BytesReference;
|
||||||
import org.elasticsearch.common.lucene.search.Queries;
|
|
||||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||||
import org.elasticsearch.common.xcontent.XContentHelper;
|
import org.elasticsearch.common.xcontent.XContentHelper;
|
||||||
import org.elasticsearch.common.xcontent.XContentParser;
|
import org.elasticsearch.common.xcontent.XContentParser;
|
||||||
|
@ -45,46 +43,18 @@ public class NestedInnerQueryParseSupport {
|
||||||
protected final QueryParseContext parseContext;
|
protected final QueryParseContext parseContext;
|
||||||
|
|
||||||
private BytesReference source;
|
private BytesReference source;
|
||||||
private Query innerQuery;
|
|
||||||
private Query innerFilter;
|
private Query innerFilter;
|
||||||
protected String path;
|
protected String path;
|
||||||
|
|
||||||
private boolean filterParsed = false;
|
private boolean filterParsed = false;
|
||||||
private boolean queryParsed = false;
|
|
||||||
protected boolean queryFound = false;
|
|
||||||
protected boolean filterFound = false;
|
protected boolean filterFound = false;
|
||||||
|
|
||||||
protected BitSetProducer parentFilter;
|
|
||||||
protected Query childFilter;
|
|
||||||
|
|
||||||
protected ObjectMapper nestedObjectMapper;
|
protected ObjectMapper nestedObjectMapper;
|
||||||
private ObjectMapper parentObjectMapper;
|
|
||||||
|
|
||||||
public NestedInnerQueryParseSupport(XContentParser parser, QueryShardContext context) {
|
public NestedInnerQueryParseSupport(XContentParser parser, QueryShardContext context) {
|
||||||
shardContext = context;
|
shardContext = context;
|
||||||
parseContext = shardContext.parseContext();
|
parseContext = shardContext.parseContext();
|
||||||
shardContext.reset(parser);
|
shardContext.reset(parser);
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public NestedInnerQueryParseSupport(QueryShardContext context) {
|
|
||||||
this.parseContext = context.parseContext();
|
|
||||||
this.shardContext = context;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void query() throws IOException {
|
|
||||||
if (path != null) {
|
|
||||||
setPathLevel();
|
|
||||||
try {
|
|
||||||
innerQuery = parseContext.parseInnerQueryBuilder().toQuery(this.shardContext);
|
|
||||||
} finally {
|
|
||||||
resetPathLevel();
|
|
||||||
}
|
|
||||||
queryParsed = true;
|
|
||||||
} else {
|
|
||||||
source = XContentFactory.smileBuilder().copyCurrentStructure(parseContext.parser()).bytes();
|
|
||||||
}
|
|
||||||
queryFound = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void filter() throws IOException {
|
public void filter() throws IOException {
|
||||||
|
@ -103,35 +73,6 @@ public class NestedInnerQueryParseSupport {
|
||||||
filterFound = true;
|
filterFound = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Query getInnerQuery() throws IOException {
|
|
||||||
if (queryParsed) {
|
|
||||||
return innerQuery;
|
|
||||||
} else {
|
|
||||||
if (path == null) {
|
|
||||||
throw new QueryShardException(shardContext, "[nested] requires 'path' field");
|
|
||||||
}
|
|
||||||
if (!queryFound) {
|
|
||||||
throw new QueryShardException(shardContext, "[nested] requires either 'query' or 'filter' field");
|
|
||||||
}
|
|
||||||
|
|
||||||
XContentParser old = parseContext.parser();
|
|
||||||
try {
|
|
||||||
XContentParser innerParser = XContentHelper.createParser(source);
|
|
||||||
parseContext.parser(innerParser);
|
|
||||||
setPathLevel();
|
|
||||||
try {
|
|
||||||
innerQuery = parseContext.parseInnerQueryBuilder().toQuery(this.shardContext);
|
|
||||||
} finally {
|
|
||||||
resetPathLevel();
|
|
||||||
}
|
|
||||||
queryParsed = true;
|
|
||||||
return innerQuery;
|
|
||||||
} finally {
|
|
||||||
parseContext.parser(old);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Query getInnerFilter() throws IOException {
|
public Query getInnerFilter() throws IOException {
|
||||||
if (filterParsed) {
|
if (filterParsed) {
|
||||||
return innerFilter;
|
return innerFilter;
|
||||||
|
@ -178,27 +119,12 @@ public class NestedInnerQueryParseSupport {
|
||||||
return nestedObjectMapper;
|
return nestedObjectMapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean queryFound() {
|
|
||||||
return queryFound;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean filterFound() {
|
public boolean filterFound() {
|
||||||
return filterFound;
|
return filterFound;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ObjectMapper getParentObjectMapper() {
|
|
||||||
return parentObjectMapper;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setPathLevel() {
|
private void setPathLevel() {
|
||||||
ObjectMapper objectMapper = shardContext.nestedScope().getObjectMapper();
|
shardContext.nestedScope().nextLevel(nestedObjectMapper);
|
||||||
if (objectMapper == null) {
|
|
||||||
parentFilter = shardContext.bitsetFilter(Queries.newNonNestedFilter());
|
|
||||||
} else {
|
|
||||||
parentFilter = shardContext.bitsetFilter(objectMapper.nestedTypeFilter());
|
|
||||||
}
|
|
||||||
childFilter = nestedObjectMapper.nestedTypeFilter();
|
|
||||||
parentObjectMapper = shardContext.nestedScope().nextLevel(nestedObjectMapper);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void resetPathLevel() {
|
private void resetPathLevel() {
|
||||||
|
|
Loading…
Reference in New Issue