当前位置: 首页>>代码示例>>Java>>正文


Java IndexResponse.getIndex方法代码示例

本文整理汇总了Java中org.elasticsearch.action.index.IndexResponse.getIndex方法的典型用法代码示例。如果您正苦于以下问题:Java IndexResponse.getIndex方法的具体用法?Java IndexResponse.getIndex怎么用?Java IndexResponse.getIndex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.elasticsearch.action.index.IndexResponse的用法示例。


在下文中一共展示了IndexResponse.getIndex方法的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.getIndex方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。