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


Java IndexResponse.getId方法代码示例

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


在下文中一共展示了IndexResponse.getId方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: createData

import org.elasticsearch.action.index.IndexResponse; //导入方法依赖的package包/类
/**
 * This method will put a new data entry inside Elastic search. identifier
 * value becomes _id inside ES, so every time provide a unique value while
 * saving it.
 *
 * @param index String  ES index name
 * @param type String  ES type name
 * @param identifier ES column identifier as an String
 * @param data Map<String,Object>
 * @return String identifier for created data
 */
public static String createData(String index, String type, String identifier,
    Map<String, Object> data) {
  long startTime = System.currentTimeMillis();
  ProjectLogger.log("ElasticSearchUtil createData method started at ==" +startTime+" for Type "+type, LoggerEnum.PERF_LOG);
  if (ProjectUtil.isStringNullOREmpty(identifier) || ProjectUtil.isStringNullOREmpty(type)
      || ProjectUtil.isStringNullOREmpty(index)) {
    ProjectLogger.log("Identifier value is null or empty ,not able to save data.");
    return "ERROR";
  }
  verifyOrCreateIndexAndType(index, type);
  try {
    data.put("identifier", identifier);
    IndexResponse response = ConnectionManager.getClient().prepareIndex(index, type, identifier)
        .setSource(data)
        .get();
    ProjectLogger
        .log("Save value==" + response.getId() + " " + response.status(), LoggerEnum.INFO.name());
    ProjectLogger.log("ElasticSearchUtil createData method end at ==" +System.currentTimeMillis()+" for Type "+type+" ,Total time elapsed = "+calculateEndTime(startTime), LoggerEnum.PERF_LOG);
    return response.getId();
  } catch (Exception e) {
    ProjectLogger.log("Error while saving "+type+" id : "+identifier, e);
    ProjectLogger.log("ElasticSearchUtil createData method end at ==" +System.currentTimeMillis()+" for Type "+type+" ,Total time elapsed = "+calculateEndTime(startTime), LoggerEnum.PERF_LOG);
    return "";
  }
}
 
开发者ID:project-sunbird,项目名称:sunbird-utils,代码行数:37,代码来源:ElasticSearchUtil.java

示例4: save

import org.elasticsearch.action.index.IndexResponse; //导入方法依赖的package包/类
/**
 * 保存
 */
@Override
public String save(Person person) {
    try {
        XContentBuilder builder = XContentFactory.jsonBuilder().startObject();
        builder.field("name", person.getName());
        builder.field("age", person.getAge());
        builder.field("sex", person.getSex());
        builder.field("birthday", person.getBirthday());
        builder.field("introduce", person.getIntroduce());
        builder.endObject();
        IndexResponse response = this.transportClient.prepareIndex(index, type)
                .setSource(builder).get();
        return response.getId();
    } catch (IOException e) {
        e.printStackTrace();
        log.error(e.getMessage(), e);
    }
    return null;
}
 
开发者ID:jeikerxiao,项目名称:SpringBootStudy,代码行数:23,代码来源:PersonDaoImpl.java

示例5: processIndex

import org.elasticsearch.action.index.IndexResponse; //导入方法依赖的package包/类
/**
 * Processes a "index" request.
 * 
 * @param urlItems Items of the URL
 * @param data JSON to be indexed
 * @return Result of the index request, it contains the id of the document
 */
private InterpreterResult processIndex(String[] urlItems, String data) {
      
  if (urlItems.length < 2 || urlItems.length > 3) {
    return new InterpreterResult(InterpreterResult.Code.ERROR,
                                 "Bad URL (it should be /index/type or /index/type/id)");
  }
      
  final IndexResponse response = client
    .prepareIndex(urlItems[0], urlItems[1], urlItems.length == 2 ? null : urlItems[2])
    .setSource(data)
    .get();

  return new InterpreterResult(
    InterpreterResult.Code.SUCCESS,
    InterpreterResult.Type.TEXT,
    response.getId());
}
 
开发者ID:lorthos,项目名称:incubator-zeppelin-druid,代码行数:25,代码来源:ElasticsearchInterpreter.java

示例6: 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

示例7: 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

示例8: 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

示例9: index

import org.elasticsearch.action.index.IndexResponse; //导入方法依赖的package包/类
@Override
public String index(SpiderInfo spiderInfo) {
    IndexResponse indexResponse;
    if (getByDomain(spiderInfo.getDomain(), 10, 1).size() > 0) {
        List<SpiderInfo> mayDuplicate = Lists.newLinkedList();
        List<SpiderInfo> temp;
        int i = 1;
        do {
            temp = getByDomain(spiderInfo.getDomain(), 100, i++);
            mayDuplicate.addAll(temp);
        } while (temp.size() > 0);
        if (mayDuplicate.indexOf(spiderInfo) != -1 && (spiderInfo = mayDuplicate.get(mayDuplicate.indexOf(spiderInfo))) != null) {
            LOG.warn("已经含有此模板,不再存储");
            return spiderInfo.getId();
        }
    }
    try {
        indexResponse = client.prepareIndex(INDEX_NAME, TYPE_NAME)
                .setSource(gson.toJson(spiderInfo))
                .get();
        LOG.debug("索引爬虫模板成功");
        return indexResponse.getId();
    } catch (Exception e) {
        LOG.error("索引 Webpage 出错," + e.getLocalizedMessage());
    }
    return null;
}
 
开发者ID:bruceq,项目名称:Gather-Platform,代码行数:28,代码来源:SpiderInfoDAO.java

示例10: index

import org.elasticsearch.action.index.IndexResponse; //导入方法依赖的package包/类
@Override
public String index(Webpage webpage) {
    IndexResponse indexResponse = null;
    try {
        indexResponse = client.prepareIndex(INDEX_NAME, TYPE_NAME)
                .setSource(gson.toJson(webpage))
                .get();
        return indexResponse.getId();
    } catch (Exception e) {
        LOG.error("索引 Webpage 出错," + e.getLocalizedMessage());
    }
    return null;
}
 
开发者ID:bruceq,项目名称:Gather-Platform,代码行数:14,代码来源:CommonWebpageDAO.java

示例11: index

import org.elasticsearch.action.index.IndexResponse; //导入方法依赖的package包/类
@Override
public String index(Webpage page) {
	IndexResponse response = null;
	try {
		response = client.prepareIndex(INDEX_NAME, TYPE_NAME)
				.setSource(GSON.toJson(page), XContentType.JSON).get();
		return response.getId();
	} catch(Exception e) {
		LOG.error("索引 webpage 出错, 由于 " + e.getLocalizedMessage());
	}
	return null;
}
 
开发者ID:TransientBuckwheat,项目名称:nest-spider,代码行数:13,代码来源:WebpageDAO.java

示例12: 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

示例13: createObject

import org.elasticsearch.action.index.IndexResponse; //导入方法依赖的package包/类
public void createObject(String type, Metable object, Credentials requester) {

		Meta meta = object.meta();
		Check.isTrue(meta == null || meta.id == null, "[meta.id] is not null");

		meta = new Meta();
		meta.createdBy = requester.name();
		meta.updatedBy = requester.name();

		DateTime now = DateTime.now();
		meta.createdAt = now;
		meta.updatedAt = now;

		object.meta(meta);
		ObjectNode node = (ObjectNode) Json8.toNode(object);

		node.with("meta").remove("id");
		node.with("meta").remove("version");
		node.with("meta").remove("type");

		IndexResponse response = Start.get().getElasticClient()//
				.index(requester.backendId(), type, node.toString());

		meta.type = type;
		meta.id = response.getId();
		meta.version = response.getVersion();
	}
 
开发者ID:spacedog-io,项目名称:spacedog-server,代码行数:28,代码来源:DataStore.java

示例14: testIndexAJsonFileWithDocId

import org.elasticsearch.action.index.IndexResponse; //导入方法依赖的package包/类
@Test
public void testIndexAJsonFileWithDocId() throws JsonGenerationException, JsonMappingException, IOException {
  EntityInfo entityInfo = new EntityInfo("Bob", "People", 3, "alert alert-success", "time","text", 26);
  String json = serBean2Json.serializeBeans2JSON(entityInfo);
  IndexResponse idxResponse = esm.indexJsonSetId(_idxName, _typeName,json, "6");

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

  System.out.println("--> docId (assigned before): " + docId);
  assertEquals(version, 1);
}
 
开发者ID:faustineinsun,项目名称:WiseCrowdRec,代码行数:13,代码来源:TestJavaApiElasticsearchManipulator.java

示例15: executeApp

import org.elasticsearch.action.index.IndexResponse; //导入方法依赖的package包/类
@Override
public void executeApp() throws Exception {
    client = Util.client();
    client.addTransportAddress(
            new InetSocketTransportAddress(new InetSocketAddress("127.0.0.1", 9300)));
    IndexResponse response = client.prepareIndex("testindex", "testtype")
            .setSource("abc", 11, "xyz", "some text")
            .get();
    documentId = response.getId();
    transactionMarker();
    client.close();
}
 
开发者ID:glowroot,项目名称:glowroot,代码行数:13,代码来源:ElasticsearchSyncIT.java


注:本文中的org.elasticsearch.action.index.IndexResponse.getId方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。