org.elasticsearch.action.DocWriteRequest.OpType Java Examples
The following examples show how to use
org.elasticsearch.action.DocWriteRequest.OpType.
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: ElasticSearchBulk.java From pentaho-kettle with Apache License 2.0 | 6 votes |
private void initFromMeta() { index = environmentSubstitute( meta.getIndex() ); type = environmentSubstitute( meta.getType() ); batchSize = meta.getBatchSizeInt( this ); try { timeout = Long.parseLong( environmentSubstitute( meta.getTimeOut() ) ); } catch ( NumberFormatException e ) { timeout = null; } timeoutUnit = meta.getTimeoutUnit(); isJsonInsert = meta.isJsonInsert(); useOutput = meta.isUseOutput(); stopOnError = meta.isStopOnError(); columnsToJson = meta.getFieldsMap(); this.hasFields = columnsToJson.size() > 0; this.opType = StringUtils.isNotBlank( meta.getIdInField() ) && meta.isOverWriteIfSameId() ? OpType.INDEX : OpType.CREATE; }
Example #2
Source File: ACLDocumentManager.java From openshift-elasticsearch-plugin with Apache License 2.0 | 5 votes |
@Override public BulkRequest buildRequest(Client client, BulkRequestBuilder builder, Collection<SearchGuardACLDocument> docs) throws IOException{ for (SearchGuardACLDocument doc : docs) { logContent("Expired doc {} to be: {}", doc.getType(), doc); Map<String, Object> content = new HashMap<>(); content.put(doc.getType(), new BytesArray(XContentHelper.toString(doc))); IndexRequestBuilder indexBuilder = client .prepareIndex(searchGuardIndex, doc.getType(), SEARCHGUARD_CONFIG_ID) .setOpType(OpType.INDEX) .setVersion(doc.getVersion()) .setSource(content); builder.add(indexBuilder.request()); } return builder.request(); }
Example #3
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); } }