Examples of IndexRequest


Examples of org.elasticsearch.action.index.IndexRequest

  }

  @Test(expected = DocumentMissingException.class)
  public void shouldThrowExceptionIfDocumentDoesNotExistWhileDoingPartialUpdate() {
    // when
    IndexRequest indexRequest = new IndexRequest();
    UpdateQuery updateQuery = new UpdateQueryBuilder().withId(randomNumeric(5))
        .withClass(SampleEntity.class).withIndexRequest(indexRequest).build();
    elasticsearchTemplate.update(updateQuery);
  }
View Full Code Here

Examples of org.elasticsearch.action.index.IndexRequest

  @Test
  public void shouldDoUpsertIfDocumentDoesNotExist() {
    //given
    String documentId = randomNumeric(5);
    String message = "test message";
    IndexRequest indexRequest = new IndexRequest();
    indexRequest.source("message", message);
    UpdateQuery updateQuery = new UpdateQueryBuilder().withId(documentId)
        .withDoUpsert(true).withClass(SampleEntity.class)
        .withIndexRequest(indexRequest).build();
    //when
    elasticsearchTemplate.update(updateQuery);
View Full Code Here

Examples of org.elasticsearch.action.index.IndexRequest

    private final List<IndexRequest> _bulkBuffer = newArrayList();

    private void addToBulk(final int id, final String value1, final String value2,
            final int iValue1, final long lValue) throws IOException {
        final String stringID = String.valueOf(id);
        _bulkBuffer.add(new IndexRequest(__index, __type, stringID)
                .routing(stringID).source(
                        XContentFactory.jsonBuilder()
                                .startObject()
                                .field(__txtField1, value1)
                                .field(__txtField2, value2)
View Full Code Here

Examples of org.elasticsearch.action.index.IndexRequest

                final int idx = i + j;
                if(idx >= ids.length) {
                    bulk.setRefresh(true).execute().actionGet();
                    return;
                }
                bulk.add(new IndexRequest(__index, __type1, ids[idx])
                        .routing(ids[idx])
                        .source(XContentFactory.jsonBuilder()
                                .startObject()
                                .field(__txtField, "Document created by " + users[idx])
                                .field(__userField, users[idx])
View Full Code Here

Examples of org.elasticsearch.action.index.IndexRequest

    StringBuilder message = new StringBuilder();
    message.append("ES bulk request for ");
    for (ActionRequest item : request.requests()) {
      message.append(String.format("[Action '%s' ", item.getClass().getSimpleName()));
      if (item instanceof IndexRequest) {
        IndexRequest request = (IndexRequest) item;
        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()));
      } else if (item instanceof UpdateRequest) {
        UpdateRequest request = (UpdateRequest) item;
        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()));
      } else if (item instanceof DeleteRequest) {
        DeleteRequest request = (DeleteRequest) item;
        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()));
      }
      message.append("],");
    }
    return message.toString();
  }
View Full Code Here

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

Examples of org.elasticsearch.action.index.IndexRequest

  @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

Examples of org.elasticsearch.action.index.IndexRequest

    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

Examples of org.elasticsearch.action.index.IndexRequest

    // 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

Examples of org.elasticsearch.action.index.IndexRequest

      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
TOP
Copyright © 2018 www.massapi.com. 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.