Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Query String caching could cause matched_filters not working #4371

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,9 @@ public Query parse(QueryParseContext parseContext) throws IOException, QueryPars

Query query = parseContext.indexCache().queryParserCache().get(qpSettings);
if (query != null) {
if (queryName != null) {
parseContext.addNamedQuery(queryName, query);
}
return query;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,4 +203,52 @@ public void testIndicesFilterSupportsName() {
}
}
}

/**
* Test case for issue #4361: https://github.com/elasticsearch/elasticsearch/issues/4361
*/
@Test
public void testMatchedWithShould() throws Exception {
createIndex("test");
ensureGreen();

client().prepareIndex("test", "type1", "1").setSource("content", "Lorem ipsum dolor sit amet").get();
client().prepareIndex("test", "type1", "2").setSource("content", "consectetur adipisicing elit").get();
refresh();

// Execute search a first time to load it in cache
client().prepareSearch()
.setQuery(
boolQuery()
.minimumNumberShouldMatch(1)
.should(queryString("dolor").queryName("dolor"))
.should(queryString("elit").queryName("elit"))
)
.setPreference("_primary")
.get();

SearchResponse searchResponse = client().prepareSearch()
.setQuery(
boolQuery()
.minimumNumberShouldMatch(1)
.should(queryString("dolor").queryName("dolor"))
.should(queryString("elit").queryName("elit"))
)
.setPreference("_primary")
.get();

//_primary
assertHitCount(searchResponse, 2l);
for (SearchHit hit : searchResponse.getHits()) {
if (hit.id().equals("1")) {
assertThat(hit.matchedQueries().length, equalTo(1));
assertThat(hit.matchedQueries(), hasItemInArray("dolor"));
} else if (hit.id().equals("2")) {
assertThat(hit.matchedQueries().length, equalTo(1));
assertThat(hit.matchedQueries(), hasItemInArray("elit"));
} else {
fail("Unexpected document returned with id " + hit.id());
}
}
}
}