本文整理匯總了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);
}
}