Package at.molindo.esi4j.mapping

Examples of at.molindo.esi4j.mapping.TypeMapping


      TypeMapping mapping = _context.findTypeMapping(object);
      return mapping.indexRequest(_client, _indexName, object);
    }

    public Session delete(Object o) {
      TypeMapping mapping = _context.findTypeMapping(o);
      delete(mapping.getTypeClass(), mapping.getId(o), mapping.getVersion(o));
      return this;
    }
View Full Code Here


      add(toDeleteRequest(type, id, version));
      return this;
    }

    private DeleteRequestBuilder toDeleteRequest(Class<?> type, Object id, Long version) {
      TypeMapping mapping = _context.findTypeMapping(type);
      return mapping.deleteRequest(_client, _indexName, mapping.toIdString(id), version);
    }
View Full Code Here

    index.execute(new Esi4JOperation<Void>() {

      @Override
      public Void execute(Client client, String indexName, Esi4JOperation.OperationContext context) {

        final TypeMapping mapping = context.findTypeMapping(rebuildSession.getType());

        ModuleIdAndVersionStream moduleStream = new ModuleIdAndVersionStream(rebuildSession,
            DEFAULT_BATCH_SIZE, mapping);

        IdAndVersionFactory factory = new MappedObjectIdAndVersionFactory(mapping);

        ElasticSearchSorter elasticSearchSorter = new ElasticSearchSorter(createSorter(factory));
        IteratorFactory iteratorFactory = new IteratorFactory(factory);
        String workingDirectory = SystemUtils.getJavaIoTmpDir().getAbsolutePath();

        ElasticSearchIdAndVersionStream esStream = new ElasticSearchIdAndVersionStream(
            new ElasticSearchDownloader(client, indexName, "_type:" + mapping.getTypeAlias(), factory),
            elasticSearchSorter, iteratorFactory, workingDirectory);

        long start = System.currentTimeMillis();

        BulkIndexHelper h = new BulkIndexHelper().setMaxRunning(2);
        h.setResponseHandler(new BulkIndexHelper.IResponseHandler() {

          @Override
          public void handle(String id, String type) {
            if ("delete".equals(type)) {
              onDelete(mapping.getTypeClass(), mapping.toId(id));
            } else {
              onIndex(mapping.getTypeClass(), mapping.toId(id));
            }
          }

        });
View Full Code Here

  public Esi4JRebuildSession startRebuildSession(final Class<?> type) {
    return _index.execute(new Esi4JOperation<Esi4JRebuildSession>() {

      @Override
      public Esi4JRebuildSession execute(Client client, String indexName, OperationContext helper) {
        final TypeMapping mapping = helper.findTypeMapping(type);

        return new Esi4JRebuildSession() {

          private final long _scrollTimeoutSeconds = 60;

          private String _scrollId;
          private boolean _endReached = false;

          @Override
          public boolean isOrdered() {
            return true;
          }

          @Override
          public Class<?> getType() {
            return type;
          }

          /**
           * only uses the batchSize from the first invocation and
           * ignores changes
           */
          @Override
          public List<?> getNext(int batchSize) {
            if (_endReached) {
              // TODO improve
              throw new IllegalStateException("reached end");
            }

            ActionFuture<SearchResponse> responseFuture;
            if (_scrollId == null) {
              // first request
              SearchRequestBuilder builder = new SearchRequestBuilder(_client)
                  .setIndices(mapping.getTypeAlias()).setPostFilter(FilterBuilders.matchAllFilter())
                  .setScroll(TimeValue.timeValueSeconds(_scrollTimeoutSeconds))
                  .addSort("_id", SortOrder.ASC).setSize(batchSize);

              responseFuture = _client.search(builder.request());
            } else {
              responseFuture = _client.searchScroll(new SearchScrollRequestBuilder(_client, _scrollId)
                  .request());
            }

            SearchResponse response = responseFuture.actionGet();

            SearchHit[] hits = response.getHits().getHits();
            ArrayList<Object> list = new ArrayList<Object>(hits.length);

            if (hits.length == 0) {
              _endReached = true;
              _scrollId = null;
            } else {
              _scrollId = response.getScrollId();
              for (int i = 0; i < hits.length; i++) {
                Object o = mapping.read(hits[i]);
                if (o != null) {
                  list.add(o);
                }
              }
            }
View Full Code Here

  @Override
  public void addToBulk(BulkRequestBuilder bulk, String indexName, OperationContext context) {
    Object entity = getEntity();
    if (entity != null) {
      TypeMapping mapping = context.findTypeMapping(entity);
      IndexRequest index = mapping.indexRequest(indexName, entity);

      if (index != null) {
        bulk.add(index);
      } else {
        DeleteRequest delete = mapping.deleteRequest(indexName, entity);
        if (delete != null) {
          bulk.add(delete);
        }
      }
    }
View Full Code Here

  @Override
  public void addToBulk(BulkRequestBuilder bulk, String indexName, OperationContext context) {
    Object entity = getEntity();

    TypeMapping mapping;

    String id;
    if (entity instanceof ObjectKey) {
      ObjectKey key = (ObjectKey) entity;
      mapping = context.findTypeMapping(key.getType());
      id = mapping.toIdString(key.getId());
    } else {
      mapping = context.findTypeMapping(entity);
      id = mapping.getIdString(entity);
    }

    bulk.add(mapping.deleteRequest(indexName, id, null));
  }
View Full Code Here

TOP

Related Classes of at.molindo.esi4j.mapping.TypeMapping

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.