Skip to content

Commit

Permalink
Terms Filter Lookup: Failure when no mappings for the terms field exi…
Browse files Browse the repository at this point in the history
…sts (no data indexed)

closes #3216
  • Loading branch information
kimchy committed Jun 22, 2013
1 parent 9268108 commit db5b0a6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
Expand Up @@ -155,8 +155,14 @@ public Filter parse(QueryParseContext parseContext) throws IOException, QueryPar
previousTypes = QueryParseContext.setTypesWithPrevious(new String[]{smartNameFieldMappers.docMapper().type()});
}
}

if (lookupId != null) {
// if there are no mappings, then nothing has been indexing yet against this shard, so we can return
// no match (but not cached!), since the Terms Lookup relies on the fact that there are mappings...
if (fieldMapper == null) {
return Queries.MATCH_NO_FILTER;
}

// external lookup, use it
TermsLookup termsLookup = new TermsLookup(fieldMapper, lookupIndex, lookupType, lookupId, lookupPath, parseContext);
if (cacheKey == null) {
Expand Down
Expand Up @@ -31,7 +31,6 @@
import org.elasticsearch.rest.RestStatus;
import org.elasticsearch.search.facet.FacetBuilders;
import org.elasticsearch.test.integration.AbstractSharedClusterTest;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.testng.annotations.Test;

import java.io.IOException;
Expand All @@ -57,7 +56,7 @@ public class SimpleQueryTests extends AbstractSharedClusterTest {
public int numberOfNodes() {
return 4;
}

@Test // see https://github.com/elasticsearch/elasticsearch/issues/3177
public void testIssue3177() {
run(prepareCreate("test").setSettings(ImmutableSettings.settingsBuilder().put("index.number_of_shards", 1)));
Expand Down Expand Up @@ -933,6 +932,12 @@ public void testTermsLookupFilter() throws Exception {
assertThat(searchResponse.getHits().getTotalHits(), equalTo(2l));
assertThat(searchResponse.getHits().getHits()[0].getId(), anyOf(equalTo("2"), equalTo("4")));
assertThat(searchResponse.getHits().getHits()[1].getId(), anyOf(equalTo("2"), equalTo("4")));

searchResponse = client().prepareSearch("test")
.setQuery(filteredQuery(matchAllQuery(), termsLookupFilter("not_exists").lookupIndex("lookup2").lookupType("type").lookupId("3").lookupPath("arr.term"))
).execute().actionGet();
assertThat("Failures " + Arrays.toString(searchResponse.getShardFailures()), searchResponse.getShardFailures().length, equalTo(0));
assertThat(searchResponse.getHits().getTotalHits(), equalTo(0l));
}

@Test
Expand Down

0 comments on commit db5b0a6

Please sign in to comment.