Made sure that named filters and queries defined in a wrapped query and filter are not lost.
Closes #6871
This commit is contained in:
parent
c94d056454
commit
687be70736
|
@ -250,6 +250,10 @@ public class QueryParseContext {
|
|||
return ImmutableMap.copyOf(namedFilters);
|
||||
}
|
||||
|
||||
public void combineNamedFilters(QueryParseContext context) {
|
||||
namedFilters.putAll(context.namedFilters);
|
||||
}
|
||||
|
||||
public void addInnerHits(String name, InnerHitsContext.BaseInnerHits context) {
|
||||
SearchContext sc = SearchContext.current();
|
||||
InnerHitsContext innerHitsContext;
|
||||
|
|
|
@ -62,6 +62,7 @@ public class WrapperFilterParser implements FilterParser {
|
|||
context.reset(qSourceParser);
|
||||
Filter result = context.parseInnerFilter();
|
||||
parser.nextToken();
|
||||
parseContext.combineNamedFilters(context);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -62,6 +62,7 @@ public class WrapperQueryParser implements QueryParser {
|
|||
context.reset(qSourceParser);
|
||||
Query result = context.parseInnerQuery();
|
||||
parser.nextToken();
|
||||
parseContext.combineNamedFilters(context);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
package org.elasticsearch.search.matchedqueries;
|
||||
|
||||
import org.elasticsearch.action.search.SearchResponse;
|
||||
import org.elasticsearch.index.query.QueryBuilder;
|
||||
import org.elasticsearch.search.SearchHit;
|
||||
import org.elasticsearch.test.ElasticsearchIntegrationTest;
|
||||
import org.junit.Test;
|
||||
|
@ -243,4 +244,25 @@ public class MatchedQueriesTests extends ElasticsearchIntegrationTest {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMatchedWithWrapperQuery() throws Exception {
|
||||
createIndex("test");
|
||||
ensureGreen();
|
||||
|
||||
client().prepareIndex("test", "type1", "1").setSource("content", "Lorem ipsum dolor sit amet").get();
|
||||
refresh();
|
||||
|
||||
QueryBuilder[] queries = new QueryBuilder[]{
|
||||
wrapperQuery(matchQuery("content", "amet").queryName("abc").buildAsBytes().toUtf8()),
|
||||
constantScoreQuery(wrapperFilter(termFilter("content", "amet").filterName("abc").buildAsBytes().toUtf8()))
|
||||
};
|
||||
for (QueryBuilder query : queries) {
|
||||
SearchResponse searchResponse = client().prepareSearch()
|
||||
.setQuery(query)
|
||||
.get();
|
||||
assertHitCount(searchResponse, 1l);
|
||||
assertThat(searchResponse.getHits().getAt(0).getMatchedQueries()[0], equalTo("abc"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue