use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.get.GetResponse in project flink by apache.
the class TestClientBase method assertThatIdsAreWritten.
void assertThatIdsAreWritten(String index, int... ids) throws IOException, InterruptedException {
for (final int id : ids) {
GetResponse response;
do {
response = getResponse(index, id);
Thread.sleep(10);
} while (response.isSourceEmpty());
assertEquals(buildMessage(id), response.getSource().get(DATA_FIELD_NAME));
}
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.get.GetResponse in project flink by apache.
the class SourceSinkDataTestKit method verifyProducedSinkData.
/**
* Verify the results in an Elasticsearch index. The results must first be produced into the
* index using a {@link TestElasticsearchSinkFunction};
*
* @param client The client to use to connect to Elasticsearch
* @param index The index to check
*/
public static void verifyProducedSinkData(Client client, String index) {
for (int i = 0; i < NUM_ELEMENTS; i++) {
GetResponse response = client.get(new GetRequest(index, TYPE_NAME, Integer.toString(i))).actionGet();
Assert.assertEquals(DATA_PREFIX + i, response.getSource().get(DATA_FIELD_NAME));
}
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.get.GetResponse in project pyramid by cheng-li.
the class VisualizerOld method createTable.
private List<Object> createTable(List<Object> data, String fields, Map<String, String> classDescription) throws IOException {
int line_count = 0;
List<Object> output = new ArrayList<>();
for (Object rowData : data) {
final Map<String, Object> row = (Map<String, Object>) rowData;
final Map<String, Object> oneRow = new HashMap<>();
line_count += 1;
final List<Object> r = new ArrayList<>();
final Map<String, Object> idLabels = new HashMap<>();
idLabels.put("id", row.get("id"));
idLabels.put("internalId", row.get("internalId"));
idLabels.put("internalLabels", row.get("internalLabels"));
idLabels.put("feedbackSelect", "none");
idLabels.put("feedbackText", "");
final List<Object> internalLabels = new ArrayList<>();
final Set<String> releLabels = new HashSet<>();
for (int i = 0, rowSize = ((List<Object>) row.get("labels")).size(); i < rowSize; i++) {
Map<Object, Object> label = new HashMap<>();
label.put(((List<Object>) row.get("internalLabels")).get(i), ((List<Object>) row.get("labels")).get(i));
internalLabels.add(label);
releLabels.add(((List<String>) row.get("labels")).get(i));
}
final List<Object> predictions = new ArrayList<>();
final Set<String> pres = new HashSet<>();
for (int i = 0, rowSize = ((List<Object>) row.get("prediction")).size(); i < rowSize; i++) {
Map<Object, Object> label = new HashMap<>();
label.put(((List<Object>) row.get("internalPrediction")).get(i), ((List<Object>) row.get("prediction")).get(i));
predictions.add(label);
pres.add(((List<String>) row.get("prediction")).get(i));
}
idLabels.put("predictions", predictions);
final Set<String> intersections = new HashSet<>(releLabels);
intersections.retainAll(pres);
final Set<String> unions = new HashSet<>(releLabels);
unions.addAll(pres);
if (unions.size() == 0) {
idLabels.put("overlap", "N/A");
} else {
idLabels.put("overlap", String.format("%.2f", (double) intersections.size() / unions.size()));
}
if (releLabels.size() == 0) {
idLabels.put("recall", "N/A");
} else {
idLabels.put("recall", String.format("%.2f", -(double) intersections.size() / releLabels.size()));
}
if (pres.size() == 0) {
idLabels.put("precision", "N/A");
} else {
idLabels.put("precision", (double) intersections.size() / pres.size());
}
oneRow.put("probForPredictedLabels", row.get("probForPredictedLabels"));
oneRow.put("predictedRanking", new ArrayList<>());
for (Map<String, Object> label : (List<Map<String, Object>>) row.get("predictedRanking")) {
final List<Object> curInternalPrediction = (List<Object>) row.get("internalPrediction");
final List<Object> curInternalLabels = (List<Object>) row.get("internalLabels");
final Object labelClassIndex = label.get("classIndex");
if (curInternalLabels.contains(labelClassIndex) && curInternalPrediction.contains(labelClassIndex)) {
label.put("type", "TP");
} else if (!curInternalLabels.contains(labelClassIndex) && curInternalPrediction.contains(labelClassIndex)) {
label.put("type", "FP");
} else if (!curInternalLabels.contains(labelClassIndex) && !curInternalPrediction.contains(labelClassIndex)) {
label.put("type", "FN");
} else {
label.put("type", "");
}
r.add(includesLabel(label.get("className"), internalLabels));
((List<Object>) oneRow.get("predictedRanking")).add(label);
}
for (Map<String, Object> labels : (List<Map<String, Object>>) row.get("predictedLabelSetRanking")) {
labels.put("types", new ArrayList<>());
final List<Object> curInternalLabels = (List<Object>) row.get("internalLabels");
final List<Object> curInternalPrediction = (List<Object>) row.get("internalPrediction");
for (Object index : (List<Object>) labels.get("internalLabels")) {
if (curInternalLabels.contains(index) && curInternalPrediction.contains(index)) {
((List<Object>) labels.get("types")).add("TP");
} else if (!curInternalLabels.contains(index) && curInternalPrediction.contains(index)) {
((List<Object>) labels.get("types")).add("FP");
} else if (curInternalLabels.contains(index) && !curInternalPrediction.contains(index)) {
((List<Object>) labels.get("types")).add("FN");
} else {
((List<Object>) labels.get("types")).add("");
}
}
}
oneRow.put("predictedLabelSetRanking", row.get("predictedLabelSetRanking"));
double sumOfR = 0.0;
double sumOfPrec = 0.0;
int last = 0;
for (int i = 0; i < r.size(); i++) {
if (r.get(i).equals(new Integer(1))) {
sumOfR += (Integer) r.get(i);
sumOfPrec += sumOfR / (i + 1);
last = i + 1;
}
}
if (releLabels.size() == 0) {
idLabels.put("ap", "N/A");
} else {
idLabels.put("ap", String.format("%.2f", sumOfPrec / releLabels.size()));
}
if (sumOfR < releLabels.size()) {
idLabels.put("rankoffullrecall", "N/A");
} else {
idLabels.put("rankoffullrecall", last);
}
oneRow.put("idLabels", idLabels);
GetResponse res = config.getClient().prepareGet(config.getEsIndexName(), "document", (String) row.get("id")).execute().actionGet();
String keys = fields;
oneRow.put("text", new HashMap<String, Map<String, Object>>());
oneRow.put("others", new HashMap<String, Map<String, Object>>());
for (String key : ((Map<String, Object>) res.getSourceAsMap()).keySet()) {
if (keys.equals(key)) {
((Map<String, Object>) oneRow.get("text")).put(key, ((String) ((Map<String, Object>) res.getSourceAsMap()).get(key)).replace("<", "<").replace(">", ">"));
} else {
((Map<String, Object>) oneRow.get("others")).put(key, ((String) ((Map<String, Object>) res.getSourceAsMap()).get(key)));
}
}
createTFPNColumns(row, line_count, oneRow, classDescription);
output.add(oneRow);
}
return output;
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.get.GetResponse in project pyramid by cheng-li.
the class ESIndex method getField.
// todo this method fetch the field from the source, it works even when store=false
// this is slow
public Object getField(String id, String field) {
GetResponse response = client.prepareGet(this.indexName, this.documentType, id).setFetchSource(field, null).execute().actionGet();
Object res = null;
if (response == null) {
if (logger.isWarnEnabled()) {
logger.warn("no response from document " + id + " when fetching field " + field + "!");
}
return null;
} else {
res = response.getSourceAsMap().get(field);
if (res == null) {
if (logger.isWarnEnabled()) {
logger.warn("document " + id + " has no field " + field + "!");
}
}
}
return res;
// return response.getField(field).getValue();
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.get.GetResponse in project play2-elasticsearch by cleverage.
the class IndexService method get.
/**
* Get Indexable Object for an Id
*
* @param indexPath
* @param clazz
* @return
*/
public static <T extends Index> T get(IndexQueryPath indexPath, Class<T> clazz, String id) {
GetRequestBuilder getRequestBuilder = getGetRequestBuilder(indexPath, id);
GetResponse getResponse = getRequestBuilder.execute().actionGet();
return getTFromGetResponse(clazz, getResponse);
}
Aggregations