當前位置: 首頁>>代碼示例>>Java>>正文


Java IndexResponse.getType方法代碼示例

本文整理匯總了Java中org.elasticsearch.action.index.IndexResponse.getType方法的典型用法代碼示例。如果您正苦於以下問題:Java IndexResponse.getType方法的具體用法?Java IndexResponse.getType怎麽用?Java IndexResponse.getType使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.elasticsearch.action.index.IndexResponse的用法示例。


在下文中一共展示了IndexResponse.getType方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: CreateDocument

import org.elasticsearch.action.index.IndexResponse; //導入方法依賴的package包/類
/**
 * This method Create the Index and insert the document(s)
 */
@Override
public void CreateDocument() {

    try {
        client = ESclient.getInstant();
        IndexResponse response = client.prepareIndex("school", "tenth", "1")
                .setSource(jsonBuilder()
                        .startObject()
                        .field("name", "Sundar")
                        .endObject()
                ).get();
        if (response != null) {
            String _index = response.getIndex();
            String _type = response.getType();
            String _id = response.getId();
            long _version = response.getVersion();
            RestStatus status = response.status();
            log.info("Index has been created successfully with Index: " + _index + " / Type: " + _type + "ID: " + _id);
        }
    } catch (IOException ex) {
        log.error("Exception occurred while Insert Index : " + ex, ex);
    }
}
 
開發者ID:sundarcse1216,項目名稱:es-crud,代碼行數:27,代碼來源:ElasticSearchCrudImpl.java

示例2: CreateIndex

import org.elasticsearch.action.index.IndexResponse; //導入方法依賴的package包/類
private static void CreateIndex(Client client){
    String json = "{" +
            "\"user\":\"daiyutage\"," +
            "\"postDate\":\"2013-01-30\"," +
            "\"message\":\"trying out Elasticsearch\"" +
            "}";

    IndexResponse response = client.prepareIndex("twitter", "tweet","2")
            .setSource(json)
            .get();
    // Index name
    String _index = response.getIndex();
    System.out.println("index:"+_index);
    // Type name  
    String _type = response.getType();
    System.out.println("_type:"+_type);
    // 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("_version:"+_version);
    // isCreated() is true if the document is a new one, false if it has been updated  
    boolean created = response.isCreated();

}
 
開發者ID:hs-web,項目名稱:hsweb-learning,代碼行數:26,代碼來源:ElasticSearch.java

示例3: onResponse

import org.elasticsearch.action.index.IndexResponse; //導入方法依賴的package包/類
@Override
public void onResponse(IndexResponse response) {
	if (response.isCreated()) {
		collector.ack(tuple);
		String index = response.getIndex();
		String type = response.getType();
		String documentId = response.getId();
		String logMsg = "Indexed successfully [" + index + "/"+ type + "/" + documentId + "]";
		// Anchored
		collector.emit(tuple, new Values(documentId));
		logger.info(logMsg);
		logger.debug("{} on tuple: {} ", logMsg, tuple.toString());
	} else {
		collector.reportError(new Throwable(response.toString()));
		collector.fail(tuple);
		logger.error("Failed to index tuple asynchronously: {} ", tuple.toString());
	}
}
 
開發者ID:desp0916,項目名稱:LearnStorm,代碼行數:19,代碼來源:ESIndexActionListener.java

示例4: testIndexAJsonFile

import org.elasticsearch.action.index.IndexResponse; //導入方法依賴的package包/類
@Test
public void testIndexAJsonFile() throws JsonGenerationException, JsonMappingException, IOException {
  EntityInfo entityInfo = new EntityInfo("Ann", "People", 1, "alert alert-success", "time","text",12);
  String json = serBean2Json.serializeBeans2JSON(entityInfo);
  IndexResponse idxResponse = esm.indexJson(_idxName, _typeName, json);

  String indexName = idxResponse.getIndex();
  String typeName = idxResponse.getType();
  String docId = idxResponse.getId();
  long version = idxResponse.getVersion(); // will get 1 if this is the first time you index this document

  assertEquals(indexName, _idxName); // index name must be in lower case
  assertEquals(typeName, _typeName);
  System.out.println("--> docId: " + docId);
  assertEquals(version, 1);
}
 
開發者ID:faustineinsun,項目名稱:WiseCrowdRec,代碼行數:17,代碼來源:TestJavaApiElasticsearchManipulator.java

示例5: testIndex

import org.elasticsearch.action.index.IndexResponse; //導入方法依賴的package包/類
@Test
public void testIndex() throws IOException {
    IndexResponse response = client.prepareIndex("twitter", "tweet", "1").setSource(XContentFactory.jsonBuilder().startObject()
            .field("user", "kimchy").field("postDate", new Date()).field("message", "trying out Elasticsearch").endObject()).get();
    // 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();
    // isCreated() is true if the document is a new one, false if it has
    // been updated
    boolean created = response.isCreated();
    System.out.println(response.toString());

}
 
開發者ID:dzh,項目名稱:jframe,代碼行數:20,代碼來源:TestTransportClient.java

示例6: updateIndex

import org.elasticsearch.action.index.IndexResponse; //導入方法依賴的package包/類
@Override
public void updateIndex(String indexName, SearchIndexSupport item) {
    if (item == null || item.getId() == null)
        return;

    Client client = ElasticSearch.CLIENT.get();

    Map<String, Object> jsonProduct = item.getIndexMap();

    if (log.isTraceEnabled())
        log.trace("Indexing json product: " + jsonProduct);

    if (jsonProduct == null)
        return;

    String key = Annotations.getIndexedCollectionName(((Model) item).getClass());

    IndexResponse response = client.prepareIndex(indexName, key, String.valueOf(item.getId()))
        .setSource(jsonProduct).setOperationThreaded(false).execute().actionGet();

    String _index = response.getIndex();
    String _type = response.getType();
    String _id = response.getId();
    long _version = response.getVersion();

    if (log.isTraceEnabled())
        log.trace("Index: " + _index + ", Type: " + _type + ", Version: " + _version + ", _Id: " + _id + ", Id: "
            + item.getId());
}
 
開發者ID:geetools,項目名稱:geeCommerce-Java-Shop-Software-and-PIM,代碼行數:30,代碼來源:DefaultElasticsearchIndexHelper.java

示例7: printIndexInfo

import org.elasticsearch.action.index.IndexResponse; //導入方法依賴的package包/類
/**
 * 打印索引信息
 * @param response
 */
private static void printIndexInfo(IndexResponse response) {
	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);
}
 
開發者ID:ameizi,項目名稱:elasticsearch-jest-example,代碼行數:17,代碼來源:TransportClient.java

示例8: dataSetImport

import org.elasticsearch.action.index.IndexResponse; //導入方法依賴的package包/類
/**
 * Imports dataset
 *
 * @throws java.io.IOException
 */
private static void dataSetImport()
        throws IOException, ExecutionException, IOException, InterruptedException, ParseException {

    JSONParser parser = new JSONParser();
    URL url = Resources.getResource(DATA_SET_NAME);
    Object obj = parser.parse(new FileReader(url.getFile()));

    JSONObject jsonObject = (JSONObject) obj;

    IndexResponse responseBook = client.prepareIndex(ES_INDEX_BOOK, ES_TYPE_INPUT, "id")
            .setSource(jsonObject.toJSONString())
            .execute()
            .actionGet();

    String json2 = "{" +

            "\"message\":\"" + MESSAGE_TEST + "\"" +
            "}";

    IndexResponse response2 = client.prepareIndex(ES_INDEX_MESSAGE, ES_TYPE_MESSAGE).setCreate(true)
            .setSource(json2).setReplicationType(ReplicationType.ASYNC)
            .execute()
            .actionGet();

    String json = "{" +
            "\"user\":\"kimchy\"," +
            "\"postDate\":\"2013-01-30\"," +
            "\"message\":\"trying out Elasticsearch\"" +
            "}";

    IndexResponse response = client.prepareIndex(ES_INDEX, ES_TYPE).setCreate(true)
            .setSource(json)
            .execute()
            .actionGet();

    String index = response.getIndex();
    String _type = response.getType();
    String _id = response.getId();
    try {
        CountResponse countResponse = client.prepareCount(ES_INDEX).setTypes(ES_TYPE)
                .execute()
                .actionGet();

        SearchResponse searchResponse = client.prepareSearch(ES_INDEX_BOOK).setTypes(ES_TYPE_INPUT)
                .execute()
                .actionGet();

        //searchResponse.getHits().hits();
        //assertEquals(searchResponse.getCount(), 1);
    } catch (AssertionError | Exception e) {
        cleanup();
        e.printStackTrace();
    }
}
 
開發者ID:Stratio,項目名稱:deep-spark,代碼行數:60,代碼來源:ESJavaRDDFT.java

示例9: testIndex

import org.elasticsearch.action.index.IndexResponse; //導入方法依賴的package包/類
private void testIndex() throws IOException {

        String jsonString = "{" + //
                "\"user\":\"kimchy\"," + //
                "\"postDate\":\"2013-01-30\"," + //
                "\"message\":\"trying out Elastic Search\"," + "}";

        IndexResponse response = client.prepareIndex("twitter", "tweet") //
                .setSource(jsonString) //
                .execute() //
                .actionGet();

        // 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();

        Map<String, Object> jsonMap = new HashMap<String, Object>();
        jsonMap.put("user", "kimchy");
        jsonMap.put("postDate", new Date());
        jsonMap.put("message", "trying out Elastic Search");

        ObjectMapper mapper = new ObjectMapper(); // create once, reuse
        String json = mapper.writeValueAsString(jsonMap);
        LOGGER.info(json);

        XContentBuilder builder = jsonBuilder() //
                .startObject() //
                .field("user", "kimchy") //
                .field("postDate", new Date()) //
                .field("message", "trying out Elastic Search") //
                .endObject();

        String json2 = builder.string();

        IndexResponse response2 = client.prepareIndex("twitter", "tweet", "1") //
                .setSource(jsonBuilder() //
                        .startObject() //
                        .field("user", "kimchy") //
                        .field("postDate", new Date()) //
                        .field("message", "trying out Elastic Search") //
                        .endObject() //
                ) //
                .execute() //
                .actionGet();

    }
 
開發者ID:xuzhikethinker,項目名稱:t4f-data,代碼行數:53,代碼來源:ElasticSearchTest.java


注:本文中的org.elasticsearch.action.index.IndexResponse.getType方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。