use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.RequestOptions in project graylog2-server by Graylog2.
the class ClientES7 method resetIndexBlock.
@Override
public void resetIndexBlock(String index) {
final UpdateSettingsRequest request = new UpdateSettingsRequest(index).settings(Collections.singletonMap("index.blocks.read_only_allow_delete", null));
client.execute((c, requestOptions) -> c.indices().putSettings(request, requestOptions), "Unable to reset index block for " + index);
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.RequestOptions in project graylog2-server by Graylog2.
the class ClientES7 method bulkIndex.
@Override
public void bulkIndex(BulkIndexRequest bulkIndexRequest) {
final BulkRequest bulkRequest = new BulkRequest();
bulkRequest.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE);
bulkIndexRequest.requests().forEach((indexName, documents) -> documents.forEach(doc -> bulkRequest.add(createIndexRequest(indexName, doc))));
client.execute((c, requestOptions) -> c.bulk(bulkRequest, requestOptions));
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.RequestOptions in project graylog2-server by Graylog2.
the class FixtureImporterES7 method importNode.
private void importNode(JsonNode root) throws IOException {
/* This supports the nosqlunit DataSet structure:
*
* {
* "documents": [
* {
* "document": [
* {
* "index": {
* "indexName": "graylog_0",
* "indexId": "0"
* }
* },
* {
* "data": {
* "source": "example.org",
* "message": "Hi",
* "timestamp": "2015-01-01 01:00:00.000"
* }
* }
* ]
* }
* ]
* }
*/
final BulkRequest bulkRequest = new BulkRequest();
final Set<String> targetIndices = new HashSet<>();
for (final JsonNode document : root.path("documents")) {
final List<JsonNode> indexes = new ArrayList<>();
Map<String, Object> data = new HashMap<>();
for (JsonNode entry : document.path("document")) {
if (entry.hasNonNull("index")) {
indexes.add(entry.path("index"));
} else if (entry.hasNonNull("data")) {
data = OBJECT_MAPPER.convertValue(entry.path("data"), TypeReferences.MAP_STRING_OBJECT);
}
}
for (final JsonNode index : indexes) {
final IndexRequest indexRequest = new IndexRequest().source(data);
final String indexName = index.path("indexName").asText(null);
if (indexName == null) {
throw new IllegalArgumentException("Missing indexName in " + index);
}
targetIndices.add(indexName);
indexRequest.index(indexName);
if (index.hasNonNull("indexId")) {
indexRequest.id(index.path("indexId").asText());
}
bulkRequest.add(indexRequest);
}
}
for (String indexName : targetIndices) {
if (!indexExists(indexName)) {
createIndex(indexName);
}
}
final BulkResponse result = client.execute((c, requestOptions) -> c.bulk(bulkRequest, requestOptions), "Unable to import fixtures.");
if (result.hasFailures()) {
throw new IllegalStateException("Error while bulk indexing documents: " + result.buildFailureMessage());
}
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.RequestOptions in project graylog2-server by Graylog2.
the class MessagesES7IT method indexMessage.
@Override
protected boolean indexMessage(String index, Map<String, Object> source, String id) {
final IndexRequest indexRequest = new IndexRequest(index).source(source).id(id);
final IndexResponse result = this.elasticsearch.elasticsearchClient().execute((c, requestOptions) -> c.index(indexRequest, requestOptions));
return result.status().equals(RestStatus.CREATED);
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.RequestOptions in project graylog2-server by Graylog2.
the class ElasticsearchClient method msearch.
public List<MultiSearchResponse.Item> msearch(List<SearchRequest> searchRequests, String errorMessage) {
final MultiSearchRequest multiSearchRequest = new MultiSearchRequest();
searchRequests.forEach(multiSearchRequest::add);
final MultiSearchResponse result = this.execute((c, requestOptions) -> c.msearch(multiSearchRequest, requestOptions), errorMessage);
return Streams.stream(result).collect(Collectors.toList());
}
Aggregations