本文整理匯總了Java中org.elasticsearch.action.index.IndexResponse.getResult方法的典型用法代碼示例。如果您正苦於以下問題:Java IndexResponse.getResult方法的具體用法?Java IndexResponse.getResult怎麽用?Java IndexResponse.getResult使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.elasticsearch.action.index.IndexResponse
的用法示例。
在下文中一共展示了IndexResponse.getResult方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: indexFact
import org.elasticsearch.action.index.IndexResponse; //導入方法依賴的package包/類
/**
* Index a Fact into ElasticSearch.
*
* @param fact Fact to index
* @return Indexed Fact
*/
public FactDocument indexFact(FactDocument fact) {
if (fact == null || fact.getId() == null) return null;
IndexResponse response;
try {
IndexRequest request = new IndexRequest(INDEX_NAME, TYPE_NAME, fact.getId().toString())
.source(FACT_DOCUMENT_WRITER.writeValueAsBytes(encodeValues(fact)), XContentType.JSON);
response = clientFactory.getHighLevelClient().index(request);
} catch (IOException ex) {
throw logAndExit(ex, String.format("Could not perform request to index Fact with id = %s.", fact.getId()));
}
if (response.status() != RestStatus.OK && response.status() != RestStatus.CREATED) {
LOGGER.warning("Could not index Fact with id = %s.", fact.getId());
} else if (response.getResult() == DocWriteResponse.Result.CREATED) {
LOGGER.info("Successfully indexed Fact with id = %s.", fact.getId());
} else if (response.getResult() == DocWriteResponse.Result.UPDATED) {
LOGGER.info("Successfully re-indexed existing Fact with id = %s.", fact.getId());
}
return fact;
}
示例2: process
import org.elasticsearch.action.index.IndexResponse; //導入方法依賴的package包/類
@Override
public void process(ResultItems resultItems, Task task) {
Iterator i$ = resultItems.getAll().entrySet().iterator();
try {
XContentBuilder xContentBuilder = jsonBuilder().startObject();
while (i$.hasNext()) {
Map.Entry entry = (Map.Entry) i$.next();
xContentBuilder.field((String) entry.getKey(), entry.getValue());
}
String json = xContentBuilder.endObject().string();
IndexResponse response = null;
if (StringUtils.isNotBlank(resultItems.get("id"))) {
response = client
.prepareIndex(INDEX_NAME, TYPE_NAME, resultItems.get("id"))
.setSource(json).get();
} else {
response = client
.prepareIndex(INDEX_NAME, TYPE_NAME)
.setSource(json).get();
}
if (response.getResult() != IndexResponse.Result.CREATED)
LOG.error("索引失敗,可能重複創建,resultItem:" + resultItems);
} catch (IOException e) {
LOG.error("索引出錯," + e.getLocalizedMessage());
e.printStackTrace();
}
}
示例3: insert
import org.elasticsearch.action.index.IndexResponse; //導入方法依賴的package包/類
public IndexResponse insert(final String index, final String type,
final String id,
final BuilderCallback<IndexRequestBuilder> builder) {
final IndexResponse actionGet = builder
.apply(client().prepareIndex(index, type, id)).execute()
.actionGet();
if (actionGet.getResult() != Result.CREATED) {
onFailure("Failed to insert " + id + " into " + index + "/" + type
+ ".", actionGet);
}
return actionGet;
}