本文整理汇总了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;
}