Java Code Examples for org.elasticsearch.action.DocWriteResponse.Result#CREATED
The following examples show how to use
org.elasticsearch.action.DocWriteResponse.Result#CREATED .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ElasticsearchClusterRunner.java From elasticsearch-cluster-runner with Apache License 2.0 | 5 votes |
@Deprecated 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; }
Example 2
Source File: ElasticsearchClusterRunner.java From elasticsearch-cluster-runner with Apache License 2.0 | 5 votes |
public IndexResponse insert(final String index, final String id, final BuilderCallback<IndexRequestBuilder> builder) { final IndexResponse actionGet = builder.apply(client().prepareIndex().setIndex(index).setId(id)).execute().actionGet(); if (actionGet.getResult() != Result.CREATED) { onFailure("Failed to insert " + id + " into " + index + ".", actionGet); } return actionGet; }
Example 3
Source File: SearchHelper.java From fess with Apache License 2.0 | 5 votes |
public boolean update(final String id, final Consumer<UpdateRequestBuilder> builderLambda) { try { final FessConfig fessConfig = ComponentUtil.getFessConfig(); final UpdateRequestBuilder builder = ComponentUtil.getFessEsClient().prepareUpdate().setIndex(fessConfig.getIndexDocumentUpdateIndex()).setId(id); builderLambda.accept(builder); final UpdateResponse response = builder.execute().actionGet(fessConfig.getIndexIndexTimeout()); return response.getResult() == Result.CREATED || response.getResult() == Result.UPDATED; } catch (final ElasticsearchException e) { throw new FessEsClientException("Failed to update doc " + id, e); } }
Example 4
Source File: EsAbstractBehavior.java From fess with Apache License 2.0 | 5 votes |
@Override protected int delegateInsert(final Entity entity, final InsertOption<? extends ConditionBean> option) { final EsAbstractEntity esEntity = (EsAbstractEntity) entity; IndexRequestBuilder builder = createInsertRequest(esEntity); final IndexResponse response = builder.execute().actionGet(indexTimeout); esEntity.asDocMeta().id(response.getId()); return response.getResult() == Result.CREATED ? 1 : 0; }
Example 5
Source File: EsAbstractBehavior.java From fess with Apache License 2.0 | 5 votes |
@Override protected int delegateInsert(final Entity entity, final InsertOption<? extends ConditionBean> option) { final EsAbstractEntity esEntity = (EsAbstractEntity) entity; IndexRequestBuilder builder = createInsertRequest(esEntity); final IndexResponse response = builder.execute().actionGet(indexTimeout); esEntity.asDocMeta().id(response.getId()); return response.getResult() == Result.CREATED ? 1 : 0; }
Example 6
Source File: FessEsClient.java From fess with Apache License 2.0 | 5 votes |
public boolean update(final String index, final String id, final String field, final Object value) { try { final Result result = client.prepareUpdate().setIndex(index).setId(id).setDoc(field, value).execute() .actionGet(ComponentUtil.getFessConfig().getIndexIndexTimeout()).getResult(); return result == Result.CREATED || result == Result.UPDATED; } catch (final ElasticsearchException e) { throw new FessEsClientException("Failed to set " + value + " to " + field + " for doc " + id, e); } }
Example 7
Source File: FessEsClient.java From fess with Apache License 2.0 | 5 votes |
public boolean store(final String index, final Object obj) { final FessConfig fessConfig = ComponentUtil.getFessConfig(); @SuppressWarnings("unchecked") final Map<String, Object> source = obj instanceof Map ? (Map<String, Object>) obj : BeanUtil.copyBeanToNewMap(obj); final String id = (String) source.remove(fessConfig.getIndexFieldId()); source.remove(fessConfig.getIndexFieldVersion()); final Number seqNo = (Number) source.remove(fessConfig.getIndexFieldSeqNo()); final Number primaryTerm = (Number) source.remove(fessConfig.getIndexFieldPrimaryTerm()); IndexResponse response; try { if (id == null) { // TODO throw Exception in next release // create response = client.prepareIndex().setIndex(index).setSource(new DocMap(source)).setRefreshPolicy(RefreshPolicy.IMMEDIATE) .setOpType(OpType.CREATE).execute().actionGet(fessConfig.getIndexIndexTimeout()); } else { // create or update final IndexRequestBuilder builder = client.prepareIndex().setIndex(index).setId(id).setSource(new DocMap(source)) .setRefreshPolicy(RefreshPolicy.IMMEDIATE).setOpType(OpType.INDEX); if (seqNo != null) { builder.setIfSeqNo(seqNo.longValue()); } if (primaryTerm != null) { builder.setIfPrimaryTerm(primaryTerm.longValue()); } response = builder.execute().actionGet(fessConfig.getIndexIndexTimeout()); } final Result result = response.getResult(); return result == Result.CREATED || result == Result.UPDATED; } catch (final ElasticsearchException e) { throw new FessEsClientException("Failed to store: " + obj, e); } }
Example 8
Source File: EsAbstractBehavior.java From fess with Apache License 2.0 | 5 votes |
@Override protected int delegateInsert(final Entity entity, final InsertOption<? extends ConditionBean> option) { final EsAbstractEntity esEntity = (EsAbstractEntity) entity; IndexRequestBuilder builder = createInsertRequest(esEntity); final IndexResponse response = builder.execute().actionGet(indexTimeout); esEntity.asDocMeta().id(response.getId()); return response.getResult() == Result.CREATED ? 1 : 0; }