Browse Source

Percolator: Fix assertion in percolation with nested docs

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
Britta Weber 11 years ago
parent
commit
8cca9b28df

+ 2 - 1
src/main/java/org/elasticsearch/percolator/PercolatorService.java

@@ -208,7 +208,8 @@ public class PercolatorService extends AbstractComponent {
 
             // 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;

+ 10 - 0
src/test/java/org/elasticsearch/percolator/PercolatorTests.java

@@ -1662,6 +1662,16 @@ public class PercolatorTests extends ElasticsearchIntegrationTest {
         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();