use of net.yacy.grid.io.index.Index in project yacy_grid_mcp by yacy.
the class ExistService method serviceImpl.
@Override
public ServiceResponse serviceImpl(Query call, HttpServletResponse response) {
// String indexName, String typeName, final String id, JSONObject object
String indexName = call.get("index", "");
String typeName = call.get("type", "");
if (typeName.length() == 0)
typeName = null;
String id = call.get("id", "");
JSONObject json = new JSONObject(true);
if (indexName.length() > 0 && id.length() > 0) {
try {
Index index = Data.gridIndex.getElasticIndex();
String url = index.checkConnection().getConnectionURL();
boolean exists = index.exist(indexName, typeName, id);
json.put(ObjectAPIHandler.SUCCESS_KEY, true);
json.put("exists", exists);
if (url != null)
json.put(ObjectAPIHandler.SERVICE_KEY, url);
} catch (IOException e) {
json.put(ObjectAPIHandler.SUCCESS_KEY, false);
json.put(ObjectAPIHandler.COMMENT_KEY, e.getMessage());
}
} else {
json.put(ObjectAPIHandler.SUCCESS_KEY, false);
json.put(ObjectAPIHandler.COMMENT_KEY, "the request must contain an index, type, and an id");
}
return new ServiceResponse(json);
}
Aggregations