Package org.elasticsearch.action.index

Examples of org.elasticsearch.action.index.IndexRequest


  @Test
  public void bulk() {
    BulkRequestBuilder bulkRequestBuilder = searchClient.prepareBulk();
    bulkRequestBuilder.add(new UpdateRequest(IndexDefinition.RULE.getIndexName(), IndexDefinition.RULE.getIndexName(), "rule1").doc(Collections.emptyMap()));
    bulkRequestBuilder.add(new DeleteRequest(IndexDefinition.RULE.getIndexName(), IndexDefinition.RULE.getIndexName(), "rule1"));
    bulkRequestBuilder.add(new IndexRequest(IndexDefinition.RULE.getIndexName(), IndexDefinition.RULE.getIndexName(), "rule1").source(Collections.emptyMap()));
    try {
      bulkRequestBuilder.get();

      // expected to fail because elasticsearch is not correctly configured, but that does not matter
      fail();
View Full Code Here


  @Test
  public void to_string() {
    BulkRequestBuilder bulkRequestBuilder = searchClient.prepareBulk();
    bulkRequestBuilder.add(new UpdateRequest(IndexDefinition.RULE.getIndexName(), IndexDefinition.RULE.getIndexName(), "rule1").doc(Collections.emptyMap()));
    bulkRequestBuilder.add(new DeleteRequest(IndexDefinition.RULE.getIndexName(), IndexDefinition.RULE.getIndexName(), "rule1"));
    bulkRequestBuilder.add(new IndexRequest(IndexDefinition.RULE.getIndexName(), IndexDefinition.RULE.getIndexName(), "rule1").source(Collections.emptyMap()));

    assertThat(bulkRequestBuilder.toString()).contains("ES bulk request for [Action 'UpdateRequest' for key 'rule1' on index 'rules' on type 'rules'],")
      .contains("[Action 'DeleteRequest' for key 'rule1' on index 'rules' on type 'rules'],")
      .contains("[Action 'IndexRequest' for key 'rule1' on index 'rules' on type 'rules'],");
  }
View Full Code Here

    SearchClient searchClient = new SearchClient(new Settings(), profiling);

    BulkRequestBuilder bulkRequestBuilder = searchClient.prepareBulk();
    bulkRequestBuilder.add(new UpdateRequest(IndexDefinition.RULE.getIndexName(), IndexDefinition.RULE.getIndexName(), "rule1").doc(Collections.emptyMap()));
    bulkRequestBuilder.add(new DeleteRequest(IndexDefinition.RULE.getIndexName(), IndexDefinition.RULE.getIndexName(), "rule1"));
    bulkRequestBuilder.add(new IndexRequest(IndexDefinition.RULE.getIndexName(), IndexDefinition.RULE.getIndexName(), "rule1").source(Collections.emptyMap()));
    try {
      bulkRequestBuilder.get();

      // expected to fail because elasticsearch is not correctly configured, but that does not matter
      fail();
View Full Code Here

    // generate an id for the document
    String id = getIdForDoc(doc);

    // create an IndexRequest for this document
    IndexRequest indexRequest = new IndexRequest(index, type, id);
    indexRequest.routing(request.param("routing"));
    indexRequest.parent(request.param("parent"));
    indexRequest.source(doc);
    indexRequest.timeout(request.paramAsTime("timeout", IndexRequest.DEFAULT_TIMEOUT));
    indexRequest.refresh(request.paramAsBoolean("refresh", indexRequest.refresh()));

    // TODO: this caused issues, do we need it?
    // indexRequest.version(RestActions.parseVersion(request));
    // indexRequest.versionType(VersionType.fromString(request.param("version_type"),
    // indexRequest.versionType()));

    indexRequest.percolate(request.param("percolate", null));
    indexRequest.opType(IndexRequest.OpType.INDEX);

    // TODO: force creation of index, do we need it?
    // indexRequest.create(true);

    String replicationType = request.param("replication");
    if (replicationType != null) {
      indexRequest.replicationType(ReplicationType.fromString(replicationType));
    }

    String consistencyLevel = request.param("consistency");
    if (consistencyLevel != null) {
      indexRequest.consistencyLevel(WriteConsistencyLevel.fromString(consistencyLevel));
    }

    // we just send a response, no need to fork
    indexRequest.listenerThreaded(true);

    // we don't spawn, then fork if local
    indexRequest.operationThreaded(true);

    return indexRequest;
  }
View Full Code Here

      List<Map<String, Object>> comments = extractIssueComments(issue);
      if (comments != null && !comments.isEmpty()) {
        String issueKey = extractIssueKey(issue);
        for (Map<String, Object> comment : comments) {
          String commentId = extractCommentId(comment);
          IndexRequest irq = indexRequest(indexName).type(commentTypeName).id(commentId)
              .source(prepareCommentIndexedDocument(jiraProjectKey, issueKey, comment));
          if (commentIndexingMode == IssueCommentIndexingMode.CHILD) {
            irq.parent(issueKey);
          }
          esBulk.add(irq);
        }
      }
    }
View Full Code Here

    @VisibleForTesting
    protected BulkRequest createBulkRequest(List<Message> msgList) {
        final BulkRequest request = new BulkRequest();
        for (Message m : msgList) {
            IndexRequest indexRequest = createIndexRequest(m);
            if (indexRequest != null) {
                request.add(indexRequest, m);
            }
        }
        return request;
View Full Code Here

    @Override
    public void store(String type, long timestamp, String jsonData) {
        Date ts = new Date(timestamp);
        Date utc = new Date(ts.getTime() + ts.getTimezoneOffset() * 60000);
        IndexRequest ir = new IndexRequest()
                .index("insight-"+ indexFormat.format(utc))
                .type(type)
                .source(jsonData)
                .create(true);
        queue.add(ir);
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);
View Full Code Here

      List<Map<String, Object>> comments = extractComments(document);
      if (comments != null && !comments.isEmpty()) {
        String issueKey = extractDocumentId(document);
        for (Map<String, Object> comment : comments) {
          String commentId = extractCommentId(comment);
          IndexRequest irq = indexRequest(indexName).type(commentTypeName).id(commentId)
              .source(prepareCommentIndexedDocument(spaceKey, issueKey, comment));
          if (commentIndexingMode == CommentIndexingMode.CHILD) {
            irq.parent(issueKey);
          }
          esBulk.add(irq);
        }
      }
    }
View Full Code Here

                    }

                    if (mutation.hasAdditions()) {
                        if (mutation.isNew()) { //Index
                            log.trace("Adding entire document {}", docid);
                            brb.add(new IndexRequest(indexName, storename, docid).source(getContent(mutation.getAdditions())));
                            bulkrequests++;
                        } else { //Update: TODO make part of batch mutation if/when possible
                            boolean needUpsert = !mutation.hasDeletions();
                            XContentBuilder builder = getContent(mutation.getAdditions());
                            UpdateRequestBuilder update = client.prepareUpdate(indexName, storename, docid).setDoc(builder);
View Full Code Here

TOP

Related Classes of org.elasticsearch.action.index.IndexRequest

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.