use of org.elasticsearch.action.update.UpdateRequest in project tutorials-java by Artister.
the class BookController method update.
@PutMapping("update/book/novel")
@ResponseBody
public ResponseEntity update(@RequestParam("id") String id, @RequestParam(name = "title", required = false) String title, @RequestParam(name = "author", required = false) String author) {
UpdateRequest update = new UpdateRequest("book", "novel", id);
try {
XContentBuilder builder = XContentFactory.jsonBuilder().startObject();
if (title != null) {
builder.field("title", title);
}
if (author != null) {
builder.field("author", author);
}
builder.endObject();
update.doc(builder);
UpdateResponse result = client.update(update).get();
return new ResponseEntity(result.getResult().toString(), HttpStatus.OK);
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}
return null;
}
use of org.elasticsearch.action.update.UpdateRequest in project pinpoint by naver.
the class ElasticsearchExecutorInterceptor method recordeESattributes.
// TODO max dsl limit need
private void recordeESattributes(SpanEventRecorder recorder, Object target, Object[] args, Object result, Throwable throwable) {
if (recordESVersion) {
if (target instanceof ClusterInfoAccessor) {
// record elasticsearch version and cluster name.
recorder.recordAttribute(ElasticsearchConstants.ARGS_VERSION_ANNOTATION_KEY, ((ClusterInfoAccessor) target)._$PINPOINT$_getClusterInfo());
}
}
if (recordDsl) {
if (args[0] instanceof SearchRequest) {
SearchRequest request = (SearchRequest) args[0];
recorder.recordAttribute(ElasticsearchConstants.ARGS_DSL_ANNOTATION_KEY, StringUtils.abbreviate(request.source().toString(), 256));
} else if (args[0] instanceof GetRequest) {
// GetRequest request = (GetRequest) args[0];
recorder.recordAttribute(ElasticsearchConstants.ARGS_DSL_ANNOTATION_KEY, StringUtils.abbreviate(args[0].toString(), 256));
} else if (args[0] instanceof IndexRequest) {
// IndexRequest request = (IndexRequest) args[0];
recorder.recordAttribute(ElasticsearchConstants.ARGS_DSL_ANNOTATION_KEY, StringUtils.abbreviate(args[0].toString(), 256));
} else if (args[0] instanceof DeleteRequest) {
// DeleteRequest request = (DeleteRequest) args[0];
recorder.recordAttribute(ElasticsearchConstants.ARGS_DSL_ANNOTATION_KEY, StringUtils.abbreviate(args[0].toString(), 256));
} else if (args[0] instanceof UpdateRequest) {
// UpdateRequest request = (UpdateRequest) args[0];
recorder.recordAttribute(ElasticsearchConstants.ARGS_DSL_ANNOTATION_KEY, StringUtils.abbreviate(args[0].toString(), 256));
}
}
}
use of org.elasticsearch.action.update.UpdateRequest in project vertexium by visallo.
the class Elasticsearch5SearchIndex method addExtendedData.
@Override
public void addExtendedData(Graph graph, Iterable<ExtendedDataRow> extendedDatas, Authorizations authorizations) {
Map<ElementType, Map<String, List<ExtendedDataRow>>> rowsByElementTypeAndId = mapExtendedDatasByElementTypeByElementId(extendedDatas);
// prefetch the vertices and edges for performance
Map<String, Vertex> verticesById;
if (rowsByElementTypeAndId.containsKey(ElementType.VERTEX) && !rowsByElementTypeAndId.get(ElementType.VERTEX).isEmpty()) {
Iterable<Vertex> vertices = graph.getVertices(rowsByElementTypeAndId.get(ElementType.VERTEX).keySet(), FetchHints.NONE, authorizations);
verticesById = stream(vertices).collect(Collectors.toMap(Vertex::getId, Function.identity()));
} else {
verticesById = new HashMap<>();
}
Map<String, Edge> edgesById;
if (rowsByElementTypeAndId.containsKey(ElementType.EDGE) && !rowsByElementTypeAndId.get(ElementType.EDGE).isEmpty()) {
edgesById = stream(graph.getEdges(rowsByElementTypeAndId.get(ElementType.EDGE).keySet(), FetchHints.NONE, authorizations)).collect(Collectors.toMap(Edge::getId, Function.identity()));
} else {
edgesById = new HashMap<>();
}
Set<String> missingElements = new HashSet<>();
rowsByElementTypeAndId.forEach((elementType, elements) -> {
elements.forEach((elementId, rows) -> {
Element element = elementType == ElementType.VERTEX ? verticesById.get(elementId) : edgesById.get(elementId);
if (element == null) {
missingElements.add(String.format("%s:%s", elementType == ElementType.VERTEX ? "Vertex" : "Edge", elementId));
return;
}
bulkUpdate(graph, new ConvertingIterable<ExtendedDataRow, UpdateRequest>(rows) {
@Override
protected UpdateRequest convert(ExtendedDataRow row) {
String tableName = (String) row.getPropertyValue(ExtendedDataRow.TABLE_NAME);
String rowId = (String) row.getPropertyValue(ExtendedDataRow.ROW_ID);
List<ExtendedDataMutation> columns = stream(row.getProperties()).map(property -> new ExtendedDataMutation(tableName, rowId, property.getName(), property.getKey(), property.getValue(), property.getTimestamp(), property.getVisibility())).collect(Collectors.toList());
return prepareUpdate(graph, element, tableName, rowId, columns, authorizations).request();
}
});
});
});
if (missingElements.size() > 0) {
throw new VertexiumException("Could not add all extended data, missing elements: " + Joiner.on(", ").join(missingElements));
}
}
use of org.elasticsearch.action.update.UpdateRequest in project topcom-cloud by 545314690.
the class ElasticSearchService method updateData.
/**
* 功能描述:更新数据
* @param index 索引名
* @param type 类型
* @param _id 数据id
* @param json 数据
*/
public void updateData(String index, String type, String _id, String json) throws Exception {
try {
UpdateRequest updateRequest = new UpdateRequest(index, type, _id).doc(json);
client.update(updateRequest).get();
} catch (Exception e) {
log.error("update data failed.", e);
}
}
Aggregations