本文整理汇总了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();
}
示例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)");
}
}
示例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());
}
示例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());
}
}
示例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);
}
}
}
示例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);
}
}
}
示例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());
}
示例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();
}
示例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();
}
示例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();
}
示例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();
}
示例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();
}
示例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();
}
示例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();
}
示例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);
}
}