Java Code Examples for org.elasticsearch.action.get.GetResponse#getId()
The following examples show how to use
org.elasticsearch.action.get.GetResponse#getId() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Test.java From dht-spider with MIT License | 6 votes |
public static void get(Map<String, Object> m) throws Exception{ GetRequest getRequest = new GetRequest( "haha", "doc", "2"); String[] includes = new String[]{"message","user","*Date"}; String[] excludes = Strings.EMPTY_ARRAY; FetchSourceContext fetchSourceContext = new FetchSourceContext(true, includes, excludes); getRequest.fetchSourceContext(fetchSourceContext); GetResponse getResponse = client.get(getRequest, RequestOptions.DEFAULT); String index = getResponse.getIndex(); String type = getResponse.getType(); String id = getResponse.getId(); if (getResponse.isExists()) { long version = getResponse.getVersion(); String sourceAsString = getResponse.getSourceAsString(); Map<String, Object> sourceAsMap = getResponse.getSourceAsMap(); System.out.println(sourceAsMap); } else { } }
Example 2
Source File: AnomalyDetectorActionHandler.java From anomaly-detection with Apache License 2.0 | 6 votes |
private void onGetAdJobResponseForWrite(GetResponse response, RestChannel channel, AnomalyDetectorFunction function) { if (response.isExists()) { String adJobId = response.getId(); if (adJobId != null) { // check if AD job is running on the detector, if yes, we can't delete the detector try (XContentParser parser = RestHandlerUtils.createXContentParser(channel, response.getSourceAsBytesRef())) { ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.nextToken(), parser::getTokenLocation); AnomalyDetectorJob adJob = AnomalyDetectorJob.parse(parser); if (adJob.isEnabled()) { channel.sendResponse(new BytesRestResponse(RestStatus.BAD_REQUEST, "Detector job is running: " + adJobId)); return; } } catch (IOException e) { String message = "Failed to parse anomaly detector job " + adJobId; logger.error(message, e); channel.sendResponse(new BytesRestResponse(RestStatus.BAD_REQUEST, message)); } } } function.execute(); }
Example 3
Source File: TransportClient.java From elasticsearch-jest-example with MIT License | 6 votes |
/** * 获取索引信息 * @param index * @param type * @param id */ private static void getIndex(String index, String type, String id){ Client client = createTransportClient(); GetResponse response = client.prepareGet(index, type, id) .execute() .actionGet(); boolean exists = response.isExists(); System.out.println(exists);// 判断索引是否存在 String sourceString = response.getSourceAsString(); System.out.println(sourceString);// 获取索引,并且打印出索引内容 System.out.println("****************index ***********************"); // Index name String _index = response.getIndex(); // Type name String _type = response.getType(); // Document ID (generated or not) String _id = response.getId(); // Version (if it's the first time you index this document, you will get: 1) long _version = response.getVersion(); System.out.println(_index+","+_type+","+_id+","+_version); }
Example 4
Source File: ElasticSearchUtilImpl.java From metacat with Apache License 2.0 | 5 votes |
private ElasticSearchDoc parse(final GetResponse response) { ElasticSearchDoc result = null; if (response.isExists()) { final Map<String, Object> responseMap = response.getSourceAsMap(); final String user = (String) responseMap.get(ElasticSearchDoc.Field.USER); final boolean deleted = (boolean) responseMap.get(ElasticSearchDoc.Field.DELETED); final long timestamp = (long) responseMap.get(ElasticSearchDoc.Field.TIMESTAMP); @SuppressWarnings("unchecked") final Object dto = metacatJson.parseJsonValue( response.getSourceAsBytes(), getClass(response.getType()) ); result = new ElasticSearchDoc(response.getId(), dto, user, deleted, timestamp); } return result; }
Example 5
Source File: ElasticsearchIndex.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Returns a Document representing the specified document ID (combination of resource and context), or null when no * such Document exists yet. */ @Override protected SearchDocument getDocument(String id) throws IOException { GetResponse response = client.prepareGet(indexName, documentType, id).execute().actionGet(); if (response.isExists()) { return new ElasticsearchDocument(response.getId(), response.getType(), response.getIndex(), response.getVersion(), response.getSource(), geoContextMapper); } // no such Document return null; }
Example 6
Source File: PersistentObject.java From sfs with Apache License 2.0 | 3 votes |
public static PersistentObject fromGetResponse(PersistentContainer container, GetResponse getResponse) { String id = getResponse.getId(); long persistentVersion = getResponse.getVersion(); JsonObject document = new JsonObject(getResponse.getSourceAsString()); return new PersistentObject(container, id, persistentVersion) .merge(document); }