Examples of IndexRequest


Examples of org.elasticsearch.action.index.IndexRequest

            RestIndexAction.this.handleRequest(request, channel);
        }
    }

    @Override public void handleRequest(final RestRequest request, final RestChannel channel) {
        IndexRequest indexRequest = new IndexRequest(request.param("index"), request.param("type"), request.param("id"));
        indexRequest.routing(request.param("routing"));
        indexRequest.parent(request.param("parent")); // order is important, set it after routing, so it will set the routing
        indexRequest.source(request.contentByteArray(), request.contentByteArrayOffset(), request.contentLength(), request.contentUnsafe());
        indexRequest.timeout(request.paramAsTime("timeout", IndexRequest.DEFAULT_TIMEOUT));
        indexRequest.refresh(request.paramAsBoolean("refresh", indexRequest.refresh()));
        indexRequest.version(RestActions.parseVersion(request));
        indexRequest.versionType(VersionType.fromString(request.param("version_type"), indexRequest.versionType()));
        indexRequest.percolate(request.param("percolate", null));
        String sOpType = request.param("op_type");
        if (sOpType != null) {
            if ("index".equals(sOpType)) {
                indexRequest.opType(IndexRequest.OpType.INDEX);
            } else if ("create".equals(sOpType)) {
                indexRequest.opType(IndexRequest.OpType.CREATE);
            } else {
                try {
                    XContentBuilder builder = RestXContentBuilder.restContentBuilder(request);
                    channel.sendResponse(new XContentRestResponse(request, BAD_REQUEST, builder.startObject().field("error", "opType [" + sOpType + "] not allowed, either [index] or [create] are allowed").endObject()));
                } catch (IOException e1) {
                    logger.warn("Failed to send response", e1);
                    return;
                }
            }
        }
        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(false);
        // we don't spawn, then fork if local
        indexRequest.operationThreaded(true);
        client.index(indexRequest, new ActionListener<IndexResponse>() {
            @Override public void onResponse(IndexResponse response) {
                try {
                    XContentBuilder builder = RestXContentBuilder.restContentBuilder(request);
                    builder.startObject()
View Full Code Here

Examples of org.elasticsearch.action.index.IndexRequest

*/
@SuppressWarnings("unused")
public class IndexRequestBuilder<JsonInput, JsonOutput> extends AbstractRequestBuilderJsonOutput<IndexRequest, IndexResponse, JsonInput, JsonOutput> {

    public IndexRequestBuilder(Client client, JsonToString<JsonInput> jsonToString, StringToJson<JsonOutput> stringToJson) {
        super(client, new IndexRequest(), jsonToString, stringToJson);
    }
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);
        }
      }
    }

    if (changelogIndexingMode.isExtraDocumentIndexed()) {
      List<Map<String, Object>> changelogs = extractIssueChangelogs(issue);
      if (changelogs != null && !changelogs.isEmpty()) {
        String issueKey = extractIssueKey(issue);
        for (Map<String, Object> changelog : changelogs) {
          String commentId = extractChangelogId(changelog);
          IndexRequest irq = indexRequest(indexName).type(changelogTypeName).id(commentId)
              .source(prepareChangelogIndexedDocument(jiraProjectKey, issueKey, changelog));
          if (changelogIndexingMode == IssueCommentIndexingMode.CHILD) {
            irq.parent(issueKey);
          }
          esBulk.add(irq);
        }
      }
    }
View Full Code Here

Examples of org.elasticsearch.action.index.IndexRequest

  protected IndexResponse index(final XContentBuilder content) {
    final IndexResponse response = nodeTemplate.executeGet(new ClientCallback<IndexResponse>() {

      @Override
      public ActionFuture<IndexResponse> execute(final Client client) {
        final IndexRequest request = Requests.indexRequest(nodeTemplate.getIndexName())
                                             .source(content).type("log");
        return client.index(request);
      }
    });
    assertNotNull("response is null", response);
View Full Code Here

Examples of org.elasticsearch.action.index.IndexRequest

            }
            if (id == null) {
                channel.sendResponse(TYPE, new IllegalArgumentException("id is null"));
                return;
            }
            IndexRequest indexRequest = Requests.indexRequest(index).type(type).id(id)
                    .source((Map<String, Object>) request.asMap().get("data"));
            add(indexRequest, channel);
        } catch (IOException ex) {
            try {
                channel.sendResponse(TYPE, ex);
View Full Code Here

Examples of org.elasticsearch.action.index.IndexRequest

                logger.warn("Skipped object without id when bulkUpdate:" + hit);
                continue;
            }

            try {
                IndexRequest indexReq = Requests.indexRequest(indexName).type(newType).id(hit.id()).source(hit.source());
                if (withVersion)
                    indexReq.version(hit.version());
                if (hit.parent() != null && !hit.parent().isEmpty()) {
                    indexReq.parent(hit.parent());
                }
                brb.add(indexReq);
            } catch (Exception ex) {
                logger.warn("Cannot add object:" + hit + " to bulkIndexing action." + ex.getMessage());
            }
View Full Code Here

Examples of org.elasticsearch.action.index.IndexRequest

                        indexBuilder.setRouting((String)routing);
                    } else {
                        logger.warn("Unable to determine routing value from routing field {} for doc id {}", routingField, id);
                    }
                }
                IndexRequest indexRequest = indexBuilder.request();
                bulkIndexRequests.put(id,  indexRequest);
            }
        }

        List<Object> result = null;
View Full Code Here

Examples of org.elasticsearch.action.index.IndexRequest

    }
    BulkRequestBuilder brb = _elasticClient.prepareBulk();
   
    JsonArray docJsonArray = docsJson.getAsJsonArray();
    for (JsonElement docJson: docJsonArray) {
      IndexRequest ir = new IndexRequest(_sIndexName);
      ir.type(_sIndexType);
      if (null != sParentId) {
        ir.parent(sParentId);
      }
      if (!bAllowOverwrite) {
        ir.opType(OpType.CREATE);
      }//TESTED
     
      // Some _id unpleasantness
      if (null != idFieldName) {
       
        String id = docJson.getAsJsonObject().get(idFieldName).getAsString();
        ir.id(id);
        ir.source(docJson.toString());
      }//TESTED
     
      brb.add(ir);
    }
    brb.setConsistencyLevel(WriteConsistencyLevel.ONE);
View Full Code Here

Examples of org.elasticsearch.action.index.IndexRequest

      throw new RuntimeException("bulkAddDocuments not supported on multi-index manager");
    }
    BulkRequestBuilder brb = _elasticClient.prepareBulk();
   
    for (DBObject docJson: docsJson) {
      IndexRequest ir = new IndexRequest(_sIndexName);
      ir.type(_sIndexType);
      if (null != sParentId) {
        ir.parent(sParentId);
      }
      if (!bAllowOverwrite) {
        ir.opType(OpType.CREATE);
      }//TESTED
     
      // Some _id unpleasantness
      if (null != idFieldName) {
       
        String id = (String) docJson.get(idFieldName);
        ir.id(id);
        ir.source(docJson.toString());
      }//TESTED
     
      brb.add(ir);
    }
    brb.setConsistencyLevel(WriteConsistencyLevel.ONE);
View Full Code Here

Examples of org.elasticsearch.action.index.IndexRequest

    BulkRequestBuilder brb = node.client().prepareBulk();

    for (int i = 0; i < 1000; i++) {
      Beer beer = BeerHelper.generate();
      IndexRequest irq = new IndexRequest("meal", "beer", "beer_" + i);
      String jsonString = mapper.writeValueAsString(beer);
      irq.source(jsonString);
      brb.add(irq);
    }

    BulkResponse br = brb.execute().actionGet();
    Assert.assertFalse(br.hasFailures());
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.