public static String escape(String str) {
      StringBuilder sb = new StringBuilder(str.length());
      for (int i = 0; i < str.length(); i++) {
        char c = str.charAt(i);
        char pc = '\0';
        // These characters are part of the query syntax and must be escaped
        if (c == '\"' || c == '\\' && pc != '\\') {
          sb.append('\\');
        }
        sb.append(c);
        pc = c;
      }
      return sb.toString();
    }
Escape value that is to be used in manually constructed
JSON string.
@param str input value
@return escaped str
common/es/src/main/java/io/apiman/common/es/util/EsUtils.java