private void addToIndex(String projectUuid, String name) { esClient.prepareIndex(INDEX_TYPE_FOO) .setRouting(projectUuid) .setParent(projectUuid) .setSource(ImmutableMap.of( FooIndexDefinition.FIELD_NAME, name, FooIndexDefinition.FIELD_PROJECT_UUID, projectUuid)) .get(); }
private IndexRequest newIndexRequest(IssueDoc issue) { String projectUuid = issue.projectUuid(); return esClient.prepareIndex(INDEX_TYPE_ISSUE) .setId(issue.key()) .setRouting(projectUuid) .setParent(projectUuid) .setSource(issue.getFields()) .request(); }
public void index(final Entity entity, final Tenant tenant) throws SearchEngineException { try { Map<String, Object> source = entityIndexDocumentPurveyor.purveyDocument(entity, tenant); if (source.keySet().size() > 0) { String entityName = StringUtils.substringAfterLast(entity.getClass().getName(), ".").toLowerCase(); this.logger.debug("Indexing {} with id {}...", entityName, entity.getId()); IndexRequestBuilder builder = this.client.prepareIndex("entities", entityName, entity.getId().toString()).setSource(source); if (tenant != null && !Tenant.class.isAssignableFrom(entity.getClass())) { builder.setParent(tenant.getId().toString()); } IndexResponse response = builder.execute().actionGet(); this.logger.debug("" + response.getType()); } } catch (Exception e) { throw new SearchEngineException("Failed to index entity", e); } }
indexRequestBuilder.setParent(parent);
private <T> void save( final String index, final String type, final Collection<T> collection, final Function<T, String> idGenerator, final Function<T, String> parentIdGenerator) { if (collection.isEmpty()) { return; } try { final BulkRequestBuilder bulkBuilder = esResource.getClient().prepareBulk(); for (final T t : collection) { final String source = MAPPER.writeValueAsString(t); bulkBuilder.add( esResource .getClient() .prepareIndex(index, type, idGenerator.apply(t)) .setSource(source, XContentType.JSON) .setParent(parentIdGenerator.apply(t))); } final RestStatus status = bulkBuilder.execute().actionGet().status(); if (!status.equals(RestStatus.OK)) { throw new BaleenException("Rest call failed with code " + status.getStatus()); } } catch (final Exception ee) { getMonitor().error("Couldn't persist to Elasticsearch", ee); } }
private void index(TridentTuple tuple) throws ElasticSearchException { String indexName = tridentElasticSearchMapper.mapToIndex(tuple); String type = tridentElasticSearchMapper.mapToType(tuple); String key = tridentElasticSearchMapper.mapToKey(tuple); Map<String, Object> data = tridentElasticSearchMapper.mapToData(tuple); String parentId = tridentElasticSearchMapper.mapToParentId(tuple); // TODO: this is not efficient. Creating indices should happen at // deployment phase. if (!client.admin().indices().exists(new IndicesExistsRequest(indexName)).actionGet().isExists()) { createIndex(indexName, tridentElasticSearchMapper.mapToIndexSettings(tuple)); createMapping(indexName, type, tridentElasticSearchMapper.mapToMappingSettings(tuple)); } if (StringUtils.isBlank(parentId)) { client.prepareIndex(indexName, type, key).setSource(data).execute().actionGet(); } else { System.out.println("parent: " + parentId); client.prepareIndex(indexName, type, key).setSource(data).setParent(parentId).execute().actionGet(); } }
private IndexRequest newIndexRequest(IssueDoc issue) { String projectUuid = issue.projectUuid(); return esClient.prepareIndex(INDEX_TYPE_ISSUE) .setId(issue.key()) .setRouting(projectUuid) .setParent(projectUuid) .setSource(issue.getFields()) .request(); }
private IndexRequest getPropertyDocumentIndexRequest(IndexInfo indexInfo, Element element, Property property) throws IOException { XContentBuilder jsonBuilder = buildJsonContentFromProperty(indexInfo, property); if (jsonBuilder == null) { return null; } String id = getChildDocId(element, property); //LOGGER.debug(jsonBuilder.string()); IndexRequestBuilder builder = getClient().prepareIndex(indexInfo.getIndexName(), PROPERTY_TYPE, id); builder = builder.setParent(element.getId()); builder = builder.setSource(jsonBuilder); return builder.request(); }
} else { LOGGER.debug("parent: " + parentId); bulkRequest.add(client.prepareIndex(indexName, type, key).setSource(data).setParent(parentId));
private IndexRequest getPropertyDocumentIndexRequest(IndexInfo indexInfo, Element element, Property property) throws IOException { XContentBuilder jsonBuilder = buildJsonContentFromProperty(indexInfo, property); if (jsonBuilder == null) { return null; } String id = getChildDocId(element, property); //LOGGER.debug(jsonBuilder.string()); IndexRequestBuilder builder = getClient().prepareIndex(indexInfo.getIndexName(), PROPERTY_TYPE, id); builder = builder.setParent(element.getId()); builder = builder.setSource(jsonBuilder); return builder.request(); }
if (parentField != null) { String parentId = parentField.getValue(); builder.setParent(parentId);
.prepareIndex(index, entityType, docId + "-" + entity.get("externalId")) .setSource(entity) .setParent(docId) .execute() .actionGet();
/** * This method persists the activity unit in the Elasticsearch repository. * * @param id The id * @param activityUnit The activity unit * @throws Exception Failed to persist */ protected void persist(BulkRequestBuilder localBulkRequestBuilder, String id, ActivityUnit activityUnit) throws Exception { List<ActivityType> activityTypes = activityUnit.getActivityTypes(); // Temporarily clear the list of activities, while the activity unit part is stored activityUnit.setActivityTypes(Collections.<ActivityType>emptyList()); localBulkRequestBuilder.add(_client.getElasticsearchClient().prepareIndex(_client.getIndex(), _client.getType(), id).setSource(ElasticsearchClient.convertTypeToJson(activityUnit))); activityUnit.setActivityTypes(activityTypes); // Persist activity types for (int i = 0; i < activityTypes.size(); i++) { ActivityType activityType = activityTypes.get(i); localBulkRequestBuilder.add(_client.getElasticsearchClient().prepareIndex(_client.getIndex(), _client.getType() + "type", id + "-" + i).setParent(id).setSource( ElasticsearchClient.convertTypeToJson(activityType))); } }
if (options.getId() != null) builder.setId(options.getId()); if (options.getRouting() != null) builder.setRouting(options.getRouting()); if (options.getParent() != null) builder.setParent(options.getParent()); if (options.getOpType() != null) builder.setOpType(options.getOpType()); if (options.isRefresh() != null) builder.setRefresh(options.isRefresh());