@Override public String toString() { StringBuilder message = new StringBuilder().append("ES index request"); message.append(String.format(" for key '%s'", request.id())); message.append(String.format(" on index '%s'", request.index())); message.append(String.format(" on type '%s'", request.type())); return message.toString(); } }
private static IndexRequest createIndexRequest(String element, ParameterTool parameterTool) { Map<String, Object> json = new HashMap<>(); json.put("data", element); return Requests.indexRequest() .index(parameterTool.getRequired("index")) .type(parameterTool.getRequired("type")) .id(element) .source(json); }
private static IndexRequest createIndexRequest(String element, ParameterTool parameterTool) { Map<String, Object> json = new HashMap<>(); json.put("data", element); return Requests.indexRequest() .index(parameterTool.getRequired("index")) .type(parameterTool.getRequired("type")) .id(element) .source(json); } }
private static IndexRequest createIndexRequest(String element, ParameterTool parameterTool) { Map<String, Object> json = new HashMap<>(); json.put("data", element); return Requests.indexRequest() .index(parameterTool.getRequired("index")) .type(parameterTool.getRequired("type")) .id(element) .source(json); }
private static IndexRequest createIndexRequest(String element, ParameterTool parameterTool) { Map<String, Object> json = new HashMap<>(); json.put("data", element); return Requests.indexRequest() .index(parameterTool.getRequired("index")) .type(parameterTool.getRequired("type")) .id(element) .source(json); }
private static IndexRequest createIndexRequest(String element, ParameterTool parameterTool) { Map<String, Object> json = new HashMap<>(); json.put("data", element); return Requests.indexRequest() .index(parameterTool.getRequired("index")) .type(parameterTool.getRequired("type")) .id(element) .source(json); }
private static IndexRequest newIndexRequest(IndexPermissions dto, IndexType indexType) { Map<String, Object> doc = new HashMap<>(); if (dto.isAllowAnyone()) { doc.put(IndexAuthorizationConstants.FIELD_ALLOW_ANYONE, true); // no need to feed users and groups } else { doc.put(IndexAuthorizationConstants.FIELD_ALLOW_ANYONE, false); doc.put(IndexAuthorizationConstants.FIELD_GROUP_IDS, dto.getGroupIds()); doc.put(IndexAuthorizationConstants.FIELD_USER_IDS, dto.getUserIds()); } return new IndexRequest(indexType.getIndex(), indexType.getType()) .id(dto.getProjectUuid()) .routing(dto.getProjectUuid()) .source(doc); }
public static void uploadFile(Client tc, String filepath, String index, String id) throws Exception { LOGGER.info("Will update '" + id + "' with " + filepath); try (Reader reader = new FileReader(filepath)) { final String res = tc .index(new IndexRequest(index).type("sg").id(id).setRefreshPolicy(RefreshPolicy.IMMEDIATE) .source(id, readXContent(reader, XContentType.YAML))).actionGet().getId(); if (!id.equals(res)) { throw new Exception(" FAIL: Configuration for '" + id + "' failed for unknown reasons. Pls. consult logfile of elasticsearch"); } } catch (Exception e) { throw e; } }
/** * Performs an index operation with a retry. * @param request The index request that we want to perform. * @param operationDescription The type of operation that we are performing. */ private void indexWithRetry(final IndexRequest request, final String operationDescription) { try { new RetryUtil<IndexResponse>().retryOnException(() -> { try { return elasticSearchClient.index(request); } catch (IOException e) { throw new RuntimeException(e); } }, null, null, RETRY_COUNT, operationDescription, "indexWithRetry"); } catch (Exception e) { Monitors.error(className, "index"); logger.error("Failed to index {} for request type: {}", request.id(), request.type(), e); } }
public void addBulkRequest(String id, XContentBuilder source, String routing, String parent) { bulkProcessor.add(indexRequest(index).type(type).id(id).source(source).routing(routing).parent(parent)); insertedDocuments.incrementAndGet(); }
public void addBulkRequest(String id, Map<?, ?> source, String routing, String parent) { bulkProcessor.add(indexRequest(index).type(type).id(id).source(source).routing(routing).parent(parent)); insertedDocuments.incrementAndGet(); }
private IndexRequest newIndexRequestWithDocId(String id) { return new IndexRequest(INDEX, INDEX_TYPE_FAKE.getType()) .id(id) .source(ImmutableMap.of(FakeIndexDefinition.INT_FIELD, 42)); } }
@Override public void process(String element, RuntimeContext ctx, RequestIndexer indexer) { Map<java.lang.String, Object> json = new HashMap<>(); json.put("data", element); indexer.add( Requests.indexRequest() .index("index") .type("type") .id("id") .source(json) ); } }
private static IndexRequest newRuleDocIndexRequest(RuleForIndexingDto ruleForIndexingDto) { RuleDoc doc = RuleDoc.of(ruleForIndexingDto); return new IndexRequest(INDEX_TYPE_RULE.getIndex(), INDEX_TYPE_RULE.getType()) .id(doc.getId()) .routing(doc.getRouting()) .source(doc.getFields()); }
private static IndexRequest newRuleExtensionDocIndexRequest(RuleExtensionForIndexingDto ruleExtensionForIndexingDto) { RuleExtensionDoc doc = RuleExtensionDoc.of(ruleExtensionForIndexingDto); return new IndexRequest(INDEX_TYPE_RULE_EXTENSION.getIndex(), INDEX_TYPE_RULE_EXTENSION.getType()) .id(doc.getId()) .routing(doc.getRouting()) .parent(doc.getParent()) .source(doc.getFields()); }
private static IndexRequest newRuleExtensionDocIndexRequest(RuleForIndexingDto ruleForIndexingDto) { RuleExtensionDoc ruleExtensionDoc = RuleExtensionDoc.of(ruleForIndexingDto); return new IndexRequest(INDEX_TYPE_RULE_EXTENSION.getIndex(), INDEX_TYPE_RULE_EXTENSION.getType()) .id(ruleExtensionDoc.getId()) .routing(ruleExtensionDoc.getRouting()) .parent(ruleExtensionDoc.getParent()) .source(ruleExtensionDoc.getFields()); }
private static IndexRequest newIndexRequest(UserDto user, ListMultimap<String, String> organizationUuidsByUserUuid) { UserDoc doc = new UserDoc(Maps.newHashMapWithExpectedSize(8)); // all the keys must be present, even if value is null doc.setUuid(user.getUuid()); doc.setLogin(user.getLogin()); doc.setName(user.getName()); doc.setEmail(user.getEmail()); doc.setActive(user.isActive()); doc.setScmAccounts(UserDto.decodeScmAccounts(user.getScmAccounts())); doc.setOrganizationUuids(organizationUuidsByUserUuid.get(user.getUuid())); return new IndexRequest(INDEX_TYPE_USER.getIndex(), INDEX_TYPE_USER.getType()) .id(doc.getId()) .routing(doc.getRouting()) .source(doc.getFields()); } }
private static IndexRequest newIndexRequest(IndexedActiveRuleDto dto) { ActiveRuleDoc doc = new ActiveRuleDoc(dto.getId()) .setRuleId(dto.getRuleId()) .setRuleProfileUuid(dto.getRuleProfileUuid()) .setSeverity(SeverityUtil.getSeverityFromOrdinal(dto.getSeverity())); // all the fields must be present, even if value is null String inheritance = dto.getInheritance(); doc.setInheritance(inheritance == null ? ActiveRuleInheritance.NONE.name() : inheritance); return new IndexRequest(INDEX_TYPE_ACTIVE_RULE.getIndex(), INDEX_TYPE_ACTIVE_RULE.getType()) .id(doc.getId()) .parent(doc.getParent()) .routing(doc.getRouting()) .source(doc.getFields()); }
@Test public void testUpdate() throws Exception { final Settings settings = Settings.builder() .put(ConfigConstants.SEARCHGUARD_ROLES_MAPPING_RESOLUTION, "BOTH") .build(); setup(settings); final RestHelper rh = nonSslRestHelper(); try (TransportClient tc = getInternalTransportClient()) { tc.index(new IndexRequest("indexc").type("typec").id("0") .setRefreshPolicy(RefreshPolicy.IMMEDIATE) .source("{\"content\":1}", XContentType.JSON)).actionGet(); } HttpResponse res = rh.executePostRequest("indexc/typec/0/_update?pretty=true&refresh=true", "{\"doc\" : {\"content\":2}}", encodeBasicHeader("user_c", "user_c")); System.out.println(res.getBody()); Assert.assertEquals(HttpStatus.SC_OK, res.getStatusCode()); }
@Test public void testSingle() throws Exception { setup(); try (TransportClient tc = getInternalTransportClient()) { tc.index(new IndexRequest("shakespeare").type("type").id("1").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON)).actionGet(); ConfigUpdateResponse cur = tc.execute(ConfigUpdateAction.INSTANCE, new ConfigUpdateRequest(new String[]{"config","roles","rolesmapping","internalusers","actiongroups"})).actionGet(); Assert.assertEquals(clusterInfo.numNodes, cur.getNodes().size()); } RestHelper rh = nonSslRestHelper(); //sg_shakespeare -> picard HttpResponse resc = rh.executeGetRequest("shakespeare/_search", encodeBasicHeader("picard", "picard")); System.out.println(resc.getBody()); Assert.assertEquals(HttpStatus.SC_OK, resc.getStatusCode()); Assert.assertTrue(resc.getBody().contains("\"content\":1")); resc = rh.executeHeadRequest("shakespeare", encodeBasicHeader("picard", "picard")); Assert.assertEquals(HttpStatus.SC_OK, resc.getStatusCode()); }