Added term filter and refactored the to_json method into the base query and base filter