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