private void buildFunctionScriptFilter(StringBuilder buffer) {
		boolean needsAnd = false;
		buffer.append("\"filter\": {");
		buffer.append("\"script\": { \"script\": { ");
		buffer.append("\"inline\": \"");
		if (filterMask != 0) {
			buffer.append("int flags = (int)doc['flags'].value; ");
		}
		if (!childIds.isEmpty()) {
			buffer.append("def childid = doc['childid']; ");
		}
		buffer.append("return ");
		if (filterMask !=0) {
			buffer.append("((flags & params.mask) == params.value)");
			needsAnd = true;
		}
		for(String id : childIds) {
			if (needsAnd) {
				buffer.append(" && ");
			}
			buffer.append(id);
			needsAnd = true;
		}
		buffer.append("\", \"params\": { ");
		boolean needsComma = false;
		if (filterMask != 0) {
			buffer.append("\"mask\": ").append(filterMask);
			buffer.append(", \"value\": ").append(filterValue);
			needsComma = true;
		}
		for(Entry<String,String> entry : funcParams.entrySet()) {
			if (needsComma) {
				buffer.append(", ");
			}
			else {
				needsComma = true;
			}
			buffer.append('\"').append(entry.getKey()).append("\": \"");
			buffer.append(entry.getValue()).append('\"');			
		}
		buffer.append("} } } }");
	}
Container for collecting an elasticsearch query filter document from BSimFilter elements
Ghidra/Features/BSim/src/main/java/ghidra/features/bsim/query/elastic/ElasticEffects.java