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


Java IndexResponse.isCreated方法代码示例

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


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

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

示例2: createOrUpdate

import org.elasticsearch.action.index.IndexResponse; //导入方法依赖的package包/类
private void createOrUpdate(T entity, String id) throws StorageException {
    IndexRequestBuilder requestBuilder = client.prepareIndex(index, type);

    if (id != null) {
        requestBuilder.setId(id);
    }

    IndexResponse response = requestBuilder
            .setSource(mapper.getTo().build(entity))
            .execute()
            .actionGet();

    if (!response.isCreated()) {
        throw new InternalStorageException("Unable to index entity " + entity + " (not created)");
    }
}
 
开发者ID:Ingensi,项目名称:storeit,代码行数:17,代码来源:ElasticsearchStorage.java

示例3: createMapping

import org.elasticsearch.action.index.IndexResponse; //导入方法依赖的package包/类
protected boolean createMapping(MappingConfiguration mapping, String indexId) {
    IndicesAdminClient indices = getClient().admin().indices();

    Map<String, Object> schema = schemaGenerator.generate(mapping);
    log.trace("Built schema creation request:\n{}", Arrays.toString(schema.entrySet().toArray()));

    // create metadata mapping and schema mapping
    CreateIndexRequestBuilder request = indices.prepareCreate(indexId)
            .addMapping(MetadataDataMapping.METADATA_TYPE_NAME, getMetadataSchema())
            .addMapping(mapping.getType(), schema);
    if (mapping.hasIndexCreationRequest()) {
        request.setSettings(mapping.getIndexCreationRequest());
    }

    CreateIndexResponse response = request.get();
    log.debug("Created indices: {}, acknowledged: {}", response, response.isAcknowledged());

    Map<String, Object> mdRecord = createMetadataRecord(mapping.getVersion(), mapping.getName());
    IndexResponse mdResponse = getClient().prepareIndex(indexId, MetadataDataMapping.METADATA_TYPE_NAME, MetadataDataMapping.METADATA_ROW_ID).setSource(mdRecord).get();
    log.debug("Saved mapping metadata '{}': {}", mdResponse.isCreated(), Arrays.toString(mdRecord.entrySet().toArray()));

    return (mdResponse.isCreated() && response.isAcknowledged());
}
 
开发者ID:52North,项目名称:youngs,代码行数:24,代码来源:ElasticsearchSink.java

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

示例5: createUserID

import org.elasticsearch.action.index.IndexResponse; //导入方法依赖的package包/类
private void createUserID(final long userID) {
    final GetResponse getResponse = client
            .prepareGet(userIndex, userType, Long.toString(userID))
            .setRefresh(true).execute().actionGet();
    if (!getResponse.isExists()) {
        final Map<String, Object> source = new HashMap<>();
        source.put("system_id", Long.toString(userID));
        source.put(userIdField, userID);
        source.put(timestampField, new Date());
        final IndexResponse response = client
                .prepareIndex(userIndex, userType, Long.toString(userID))
                .setSource(source).setRefresh(true).execute().actionGet();
        if (!response.isCreated()) {
            throw new TasteException("Failed to create " + source);
        }
    }
}
 
开发者ID:codelibs,项目名称:elasticsearch-taste,代码行数:18,代码来源:ElasticsearchDataModel.java

示例6: createItemID

import org.elasticsearch.action.index.IndexResponse; //导入方法依赖的package包/类
private void createItemID(final long itemID) {
    final GetResponse getResponse = client
            .prepareGet(itemIndex, itemType, Long.toString(itemID))
            .setRefresh(true).execute().actionGet();
    if (!getResponse.isExists()) {
        final Map<String, Object> source = new HashMap<>();
        source.put("system_id", Long.toString(itemID));
        source.put(itemIdField, itemID);
        source.put(timestampField, new Date());
        final IndexResponse response = client
                .prepareIndex(itemIndex, itemType, Long.toString(itemID))
                .setSource(source).setRefresh(true).execute().actionGet();
        if (!response.isCreated()) {
            throw new TasteException("Failed to create " + source);
        }
    }
}
 
开发者ID:codelibs,项目名称:elasticsearch-taste,代码行数:18,代码来源:ElasticsearchDataModel.java

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

示例8: save

import org.elasticsearch.action.index.IndexResponse; //导入方法依赖的package包/类
/**
 * Saves provider params to elastic search and uses owning username as id.
 *
 * @param pp    Provider parameters to be saved
 * @return      Whether the operation was successful
 * @throws Exception
 */
public boolean save( final ProviderParams pp ) throws IOException {

    IndexResponse response = elasticSearchClient.getClient()
            .prepareIndex( DAO_INDEX_KEY, DAO_TYPE_KEY, pp.getUsername() )
            .setRefresh( true )
            .setSource(
                    jsonBuilder()
                            .startObject()
                            .field( "username", pp.getUsername() )
                            .field( "instanceType", pp.getInstanceType() )
                            .field( "accessKey", pp.getAccessKey() )
                            .field( "secretKey", pp.getSecretKey() )
                            .field( "imageId", pp.getImageId() )
                            .field( "keyName", pp.getKeyName() )
                            .field( "keys", pp.getKeys().toString() )
            )
            .execute()
            .actionGet();

    return response.isCreated();
}
 
开发者ID:apache,项目名称:usergrid,代码行数:29,代码来源:ProviderParamsDao.java

示例9: save

import org.elasticsearch.action.index.IndexResponse; //导入方法依赖的package包/类
/**
 * Stores a new user, username is used as ID, since it should be unique
 *
 * @param user  User to save
 * @return      whether the operation succeeded
 * @throws Exception
 */
public boolean save( User user ) throws IOException {

    IndexResponse response = elasticSearchClient.getClient()
            .prepareIndex( DAO_INDEX_KEY, DAO_TYPE_KEY, user.getUsername() )
            .setRefresh( true )
            .setSource(
                    jsonBuilder()
                            .startObject()
                            .field( "password", user.getPassword() )
                            .endObject()
            )
            .execute()
            .actionGet();

    return response.isCreated();
}
 
开发者ID:apache,项目名称:usergrid,代码行数:24,代码来源:UserDao.java

示例10: save

import org.elasticsearch.action.index.IndexResponse; //导入方法依赖的package包/类
public boolean save( Note note ) throws IOException {

        IndexResponse response = elasticSearchClient.getClient()
                .prepareIndex( DAO_INDEX_KEY, DAO_TYPE_KEY, note.getId() )
                .setRefresh( true )
                .setSource(
                        jsonBuilder()
                                .startObject()
                                .field( "commitId", note.getCommitId() )
                                .field( "runNumber", note.getRunNumber() )
                                .field( "text", note.getText() )
                                .endObject()
                )
                .execute()
                .actionGet();

        return response.isCreated();
    }
 
开发者ID:apache,项目名称:usergrid,代码行数:19,代码来源:NoteDao.java

示例11: save

import org.elasticsearch.action.index.IndexResponse; //导入方法依赖的package包/类
/**
 * Saves commit to elastic search and uses commit id as index id.
 *
 * @param commit    Commit to save
 * @return          Whether the operation was successful
 * @throws Exception
 */
public boolean save( Commit commit ) throws IOException {

    IndexResponse response = elasticSearchClient.getClient()
            .prepareIndex( "modules", "commit", commit.getId() )
            .setRefresh( true )
            .setSource(
                    jsonBuilder()
                            .startObject()
                            .field( "moduleId", commit.getModuleId() )
                            .field( "md5", commit.getMd5() )
                            .field( "createTime", commit.getCreateTime() )
                            .endObject()
            )
            .execute()
            .actionGet();

    return response.isCreated();
}
 
开发者ID:apache,项目名称:usergrid,代码行数:26,代码来源:CommitDao.java

示例12: save

import org.elasticsearch.action.index.IndexResponse; //导入方法依赖的package包/类
/**
 * Saves module to elastic search
 *
 * @param module    Module to save
 * @return          Whether or not the operation was successful
 * @throws Exception
 */
public boolean save( Module module ) throws IOException {

    IndexResponse response = elasticSearchClient.getClient()
            .prepareIndex( DAO_INDEX_KEY, DAO_TYPE_KEY, module.getId() )
            .setRefresh( true )
            .setSource(
                    jsonBuilder()
                            .startObject()
                            .field( "groupId", module.getGroupId() )
                            .field( "artifactId", module.getArtifactId() )
                            .field( "version", module.getVersion() )
                            .field( "vcsRepoUrl", module.getVcsRepoUrl() )
                            .field( "testPackageBase", module.getTestPackageBase() )
                            .endObject()
            )
            .execute()
            .actionGet();

    return response.isCreated();
}
 
开发者ID:apache,项目名称:usergrid,代码行数:28,代码来源:ModuleDao.java

示例13: save

import org.elasticsearch.action.index.IndexResponse; //导入方法依赖的package包/类
/**
 * Saves given RunResult in elastic search, uses the id field as index id
 *
 * @param runResult RunResult object to save
 * @return          Whether the operation succeeded
 * @throws Exception
 */
public boolean save( RunResult runResult ) throws IOException {

    IndexResponse response = elasticSearchClient.getClient()
            .prepareIndex( DAO_INDEX_KEY, DAO_TYPE_KEY, runResult.getId() )
            .setRefresh( true )
            .setSource(
                    jsonBuilder()
                            .startObject()
                            .field( "runId", runResult.getRunId() )
                            .field( "runCount", runResult.getRunCount() )
                            .field( "runTime", runResult.getRunTime() )
                            .field( "ignoreCount", runResult.getIgnoreCount() )
                            .field( "failureCount", runResult.getFailureCount() )
                            .field( "createTime", System.nanoTime() )
                            .field( "failures", runResult.getFailures() )
                            .endObject()
            )
            .execute()
            .actionGet();

    return response.isCreated();
}
 
开发者ID:apache,项目名称:usergrid,代码行数:30,代码来源:RunResultDao.java

示例14: putMetricsPaperIntoES

import org.elasticsearch.action.index.IndexResponse; //导入方法依赖的package包/类
public   boolean putMetricsPaperIntoES(XContentBuilder json) {

        IndexResponse response = client.prepareIndex(INDEX,REF_DATA_TYPE)
                .setSource(json)
                .get();
        return response.isCreated();
    }
 
开发者ID:HongChutang,项目名称:NTPaprEng,代码行数:8,代码来源:ESClient.java

示例15: reportMetrics

import org.elasticsearch.action.index.IndexResponse; //导入方法依赖的package包/类
/**
 * Reports metrics according to provided {@link IndexResponse}
 * @param response
 */
protected void reportMetrics(final IndexResponse response) {
	if(response == null) {
		this.statsdClient.incrementCounter(STATSD_ERRORS);
	} else {
		if(response.isCreated())
			this.statsdClient.incrementCounter(STATSD_TOTAL_DOCUMENTS_CREATED);
		else
			this.statsdClient.incrementCounter(STATSD_TOTAL_DOCUMENTS_UPDATED);
	}
}
 
开发者ID:ottogroup,项目名称:flink-operator-library,代码行数:15,代码来源:ElasticsearchSink.java


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