Skip to content

Commit

Permalink
Query String caching could cause matched_filters not working
Browse files Browse the repository at this point in the history
When searching with a query containing query_strings inside a bool query, the specified _name is randomly missing from the results due to caching.

Closes elastic#4361.
Closes elastic#4371.
  • Loading branch information
dadoonet committed Dec 7, 2013
1 parent f9782de commit c2424e6
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
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
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());
}
}
}
}

0 comments on commit c2424e6

Please sign in to comment.