Skip to content

Commit

Permalink
Percolator: Fix assertion in percolation with nested docs
Browse files Browse the repository at this point in the history
Assertion was triggered for percolating documents with nested object
in mapping if the document did not actually contain a nested object.
Reason:
MultiDocumentPercolatorIndex checks if the number of documents is
actualu >1. Instead we can just use the SingleDocumentPercolatorIndex
in this case.

closes #6263
  • Loading branch information
brwe committed May 21, 2014
1 parent 0fc00c4 commit 26edf79
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
Expand Up @@ -208,7 +208,8 @@ public PercolateShardResponse percolate(PercolateShardRequest request) {

// parse the source either into one MemoryIndex, if it is a single document or index multiple docs if nested
PercolatorIndex percolatorIndex;
if (indexShard.mapperService().documentMapper(request.documentType()).hasNestedObjects()) {
if (parsedDocument.docs().size() > 1) {
assert indexShard.mapperService().documentMapper(request.documentType()).hasNestedObjects();
percolatorIndex = multi;
} else {
percolatorIndex = single;
Expand Down
10 changes: 10 additions & 0 deletions src/test/java/org/elasticsearch/percolator/PercolatorTests.java
Expand Up @@ -1662,6 +1662,16 @@ public void testNestedPercolation() throws IOException {
assertEquals(response.getMatches()[0].getId().string(), "Q");
}

@Test
public void makeSureNonNestedDocumentDoesNotTriggerAssertion() throws IOException {
initNestedIndexAndPercolation();
XContentBuilder doc = jsonBuilder();
doc.startObject();
doc.field("some_unnested_field", "value");
PercolateResponse response = client().preparePercolate().setPercolateDoc(new PercolateSourceBuilder.DocBuilder().setDoc(doc)).setIndices("nestedindex").setDocumentType("company").get();
assertNoFailures(response);
}

@Test
public void testNestedPercolationOnExistingDoc() throws IOException {
initNestedIndexAndPercolation();
Expand Down

0 comments on commit 26edf79

Please sign in to comment.