@Override
    public void endElement(final String uri, final String localName, final String qName) throws SAXException {
        final String value;

        if (inOuterArray && currentDepth == 0) {
            // We are at the end of the outer `array` element
            if (localName.equals(JSONParser.XML_ELEMENT_ARRAY)) {
                // Consider this to be the end of the stream part
                inOuterArray = false;
            } else {
                fatalError("Expected an end array to close the document, got '" + localName + "' instead",
                        new IllegalArgumentException());
            }
        } else {
            switch (localName) {
                case JSONParser.XML_ELEMENT_MAP:
                    try {
                        currentDepth--;
                        jsonGenerator.writeEndObject();
                        if (currentDepth == 0) {
                            // We have closed out an outer `map`, so queue the document for indexing
                            processDocument();
                        }
                    } catch (IOException e) {
                        fatalError("Invalid end of object", e);
                    }
                    break;
                case JSONParser.XML_ELEMENT_ARRAY:
                    try {
                        currentDepth--;
                        jsonGenerator.writeEndArray();
                    } catch (IOException e) {
                        fatalError("Invalid end of array", e);
                    }
                    break;
                case JSONParser.XML_ELEMENT_STRING:
                    value = content.toString();
                    try {
                        if (!value.isEmpty()) {
                            if (includeField(currentDocFieldName)) {
                                writeFieldName();
                                jsonGenerator.writeString(value);
                                currentDocPropertyCount++;
                            }
                            storeIndexNameVariableValue(value);
                        }
                    } catch (IOException e) {
                        fatalError("Invalid string value '" + value + "' for property '" +
                                   currentDocFieldName + "'", e);
                    }
                    break;
                case JSONParser.XML_ELEMENT_BOOLEAN:
                    value = content.toString();
                    try {
                        if (!value.isEmpty()) {
                            if (includeField(currentDocFieldName)) {
                                writeFieldName();
                                jsonGenerator.writeBoolean(Boolean.parseBoolean(value));
                                currentDocPropertyCount++;
                            }
                            storeIndexNameVariableValue(value);
                        }
                    } catch (IOException e) {
                        fatalError("Invalid boolean value '" + value + "' for property '" +
                                   currentDocFieldName + "'", e);
                    }
                    break;
                case JSONParser.XML_ELEMENT_NULL:
                    try {
                        if (includeField(currentDocFieldName)) {
                            writeFieldName();
                            jsonGenerator.writeNull();
                            currentDocPropertyCount++;
                        }
                        storeIndexNameVariableValue("");
                    } catch (IOException e) {
                        fatalError("Invalid null value for property '" + currentDocFieldName + "'", e);
                    }
                    break;
                case JSONParser.XML_ELEMENT_NUMBER:
                    value = content.toString();
                    try {
                        if (!value.isEmpty()) {
                            if (includeField(currentDocFieldName)) {
                                writeFieldName();
                                jsonGenerator.writeNumber(value);
                                currentDocPropertyCount++;
                            }
                            storeIndexNameVariableValue(value);
                        }
                    } catch (IOException e) {
                        fatalError("Invalid number value '" + value + "' for property '" +
                                   currentDocFieldName + "'", e);
                    }
                    break;
            }
        }

        currentDocFieldName = null;
        content.clear();
        super.endElement(uri, localName, qName);
    }
Sets the locator to use when reporting errors.

@param locator The locator to use.
stroom-search/stroom-search-elastic/src/main/java/stroom/search/elastic/indexing/ElasticIndexingFilter.java