public <T, K extends Collection> K get(int i, Class<K> collections, Class<T> clazz) { if (i >= fieldNames.length) { throw new IllegalArgumentException(String.format("index[%s] must be lesser than number[%s] of fields selected in SearchQuery.select()", i, fieldNames.length)); } return get(fieldNames[i], collections, clazz); }
public List<ESTuple> listTuple() { if (fields.length == 0) { throw new IllegalArgumentException( String.format("You have not called SearchQuery.select(), call SearchQuery.list() instead of SearchQuery.listTuple()")); } try { String res = callElasticSearch(); JSONArray jarr = new JSONObject(res).getJSONObject("hits").getJSONArray("hits"); List<ESTuple> rlst = new ArrayList<ESTuple>(jarr.length()); for (int i = 0; i < jarr.length(); i++) { JSONObject fs = jarr.getJSONObject(i).getJSONObject("fields"); ESTuple tuple = new ESTuple(fields); for (String name : fields) { tuple.put(name, fs.optString(name, null)); } rlst.add(tuple); } return rlst; } catch (Exception e) { throw new CloudRuntimeException(e.getMessage(), e); } }
public String listAsString() { if (fields.length == 0) { return gson.toJson(list()); } else { List<ESTuple> tuples = listTuple(); List<Map<String, String>> lst = new ArrayList<Map<String, String>>(tuples.size()); for (ESTuple t : tuples) { lst.add(t.getKeyValuePairs()); } return gson.toJson(lst); } }
public String get(int i) { if (i >= fieldNames.length) { throw new IllegalArgumentException(String.format("index[%s] must be lesser than number[%s] of fields selected in SearchQuery.select()", i, fieldNames.length)); } return get(fieldNames[i]); }
public <T> T get(int i, Class<T> clazz) { if (i >= fieldNames.length) { throw new IllegalArgumentException(String.format("index[%s] must be lesser than number[%s] of fields selected in SearchQuery.select()", i, fieldNames.length)); } String val = get(fieldNames[i]); return val == null ? null : (T) gson.fromJson(val, clazz); }