private SearchGuardLicense createOrGetTrial(String msg) { long created = System.currentTimeMillis(); ThreadContext threadContext = threadPool.getThreadContext(); try(StoredContext ctx = threadContext.stashContext()) { threadContext.putHeader(ConfigConstants.SG_CONF_REQUEST_HEADER, "true"); GetResponse get = client.prepareGet(searchguardIndex, "sg", "tattr").get(); if(get.isExists()) { created = (long) get.getSource().get("val"); } else { try { client.index(new IndexRequest(searchguardIndex) .type("sg") .id("tattr") .setRefreshPolicy(RefreshPolicy.IMMEDIATE) .create(true) .source("{\"val\": "+System.currentTimeMillis()+"}", XContentType.JSON)).actionGet(); } catch (VersionConflictEngineException e) { //ignore } catch (Exception e) { LOGGER.error("Unable to index tattr", e); } } } return SearchGuardLicense.createTrialLicense(formatDate(created), clusterService, msg); } }
/** * Set to {@code true} to force this index to use {@link org.elasticsearch.action.index.IndexRequest.OpType#CREATE}. */ public IndexRequestBuilder setCreate(boolean create) { request.create(create); return this; }
/** * Set to <tt>true</tt> to force this index to use {@link org.elasticsearch.action.index.IndexRequest.OpType#CREATE}. */ public IndexRequestBuilder setCreate(boolean create) { request.create(create); return this; }
/** * Set to {@code true} to force this index to use {@link org.elasticsearch.action.index.IndexRequest.OpType#CREATE}. */ public IndexRequestBuilder setCreate(boolean create) { request.create(create); return this; }
/** * Set to <tt>true</tt> to force this index to use {@link org.elasticsearch.action.index.IndexRequest.OpType#CREATE}. */ public IndexRequestBuilder setCreate(boolean create) { request.create(create); return this; }
public IndexRequestBuilder<JsonInput, JsonOutput> create(boolean create) { request.create(create); return this; }
/** * Set to {@code true} to force this index to use {@link org.elasticsearch.action.index.IndexRequest.OpType#CREATE}. */ public IndexRequestBuilder setCreate(boolean create) { request.create(create); return this; }
private IndexRequest indexOther(JsonElement e, String type, boolean overwrite) { JsonObject obj = e.getAsJsonObject(); // handle objects that don't have IDs (i.e. labels) // set the ID to the MD5 hash of the string representation String id; if (obj.has("id")) { id = obj.get("id").getAsString(); } else { id = DigestUtils.md5Hex(e.toString()); } IndexRequest req = new IndexRequest(index) .type(type) .id(id).create(!overwrite) .source(e.toString()); return req; }
@Override public void store(String type, long timestamp, String jsonData) { Date ts = new Date(timestamp); Date utc = new Date(ts.getTime() + ts.getTimezoneOffset() * 60000); IndexRequest ir = new IndexRequest() .index("insight-"+ indexFormat.format(utc)) .type(type) .source(jsonData) .create(true); queue.add(ir); }
@Override public void store(String type, long timestamp, String jsonData) { Date ts = new Date(timestamp); Date utc = new Date(ts.getTime() + ts.getTimezoneOffset() * 60000); IndexRequest ir = new IndexRequest() .index("insight-"+ indexFormat.format(utc)) .type(type) .source(jsonData) .create(true); queue.add(ir); }
@Override public void store(String type, long timestamp, String jsonData) { Date ts = new Date(timestamp); Date utc = new Date(ts.getTime() + ts.getTimezoneOffset() * 60000); IndexRequest ir = new IndexRequest() .index("insight-"+ indexFormat.format(utc)) .type(type) .source(jsonData) .create(true); queue.add(ir); }
private IndexRequest indexEvent(JsonElement e) { JsonObject obj = e.getAsJsonObject(); String type = obj.get("type").getAsString(); String id = obj.get("id").getAsString(); if (isEventIndexed(id)) { return null; } IndexRequest req = new IndexRequest(index) .type(type) .id(id).create(false) // we want to overwrite old items .source(e.toString()); return req; }
} else { internalAdd(new IndexRequest(index, type, id).routing(routing).parent(parent).version(version) .versionType(versionType).create("create".equals(opType)).setPipeline(pipeline) .setIfSeqNo(ifSeqNo).setIfPrimaryTerm(ifPrimaryTerm) .source(sliceTrimmingCarriageReturn(data, from, nextMarker, xContentType), xContentType), payload); .versionType(versionType).create(true).setPipeline(pipeline) .setIfSeqNo(ifSeqNo).setIfPrimaryTerm(ifPrimaryTerm) .source(sliceTrimmingCarriageReturn(data, from, nextMarker, xContentType), xContentType), payload);
.parent(request.parent()).timeout(request.timeout()).waitForActiveShards(request.waitForActiveShards()) .create(true);
private void index(String json) throws IOException { Map<String, Object> record = mapper.readValue(json, Map.class); IndexRequest request = null; if (record.containsKey(idFieldName)) { Object idValue = record.get(idFieldName); request = Requests.indexRequest(indexNameForRecord(record)).id(String.valueOf(idValue)).type(mappingNameForRecord(record)).create(false).source(json); } else { request = Requests.indexRequest(indexNameForRecord(record)).type(mappingNameForRecord(record)).source(json); } if (record.containsKey(routingFieldName)) { Object routingValue = record.get(routingFieldName); request.routing(String.valueOf(routingValue)); } currentRequest.add(request); }
.type(type) .source(writer.toString()) .create(true); sender.put(request);
/** Writes a single MapWritable record to the bulkRequest object. Once <b>elasticsearch.bulk.size</b> are accumulated the records are written to elasticsearch. */ public void write(NullWritable key, MapWritable fields) throws IOException { XContentBuilder builder = XContentFactory.jsonBuilder(); buildContent(builder, fields); if (idField == -1) { // Document has no inherent id currentRequest.add(Requests.indexRequest(indexName).type(objType).source(builder)); } else { try { Text mapKey = new Text(idFieldName); String record_id = fields.get(mapKey).toString(); currentRequest.add(Requests.indexRequest(indexName).id(record_id).type(objType).create(false).source(builder)); } catch (Exception e) { LOG.warn("Encountered malformed record"); } } processBulkIfNeeded(); }
private SearchGuardLicense createOrGetTrial(String msg) { long created = System.currentTimeMillis(); ThreadContext threadContext = threadPool.getThreadContext(); try(StoredContext ctx = threadContext.stashContext()) { threadContext.putHeader(ConfigConstants.SG_CONF_REQUEST_HEADER, "true"); GetResponse get = client.prepareGet(searchguardIndex, "sg", "tattr").get(); if(get.isExists()) { created = (long) get.getSource().get("val"); } else { try { client.index(new IndexRequest(searchguardIndex) .type("sg") .id("tattr") .setRefreshPolicy(RefreshPolicy.IMMEDIATE) .create(true) .source("{\"val\": "+System.currentTimeMillis()+"}", XContentType.JSON)).actionGet(); } catch (VersionConflictEngineException e) { //ignore } catch (Exception e) { LOGGER.error("Unable to index tattr", e); } } } return SearchGuardLicense.createTrialLicense(formatDate(created), clusterService, msg); } }
.parent(request.parent()).timeout(request.timeout()).waitForActiveShards(request.waitForActiveShards()) .create(true);
.parent(request.parent()).timeout(request.timeout()).waitForActiveShards(request.waitForActiveShards()) .create(true);