Package org.elasticsearch.action.index

Examples of org.elasticsearch.action.index.IndexRequest


                    logger.warn("river was closing while processing wikipedia page [{}]/[{}]. Operation skipped.",
                            page.getID(), page.getTitle());
                    return;
                }

                bulkProcessor.add(new IndexRequest(indexName, typeName, page.getID()).source(builder));
            } catch (Exception e) {
                logger.warn("failed to construct index request", e);
            }
        }
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

      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

        // Get the id from request or if not available generate an id for the document
        String id = request.hasParam("id") ? request.param("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

     * The default content type to use to generate source documents when indexing.
     */
    public static XContentType INDEX_CONTENT_TYPE = XContentType.JSON;

    public static IndexRequest indexRequest() {
        return new IndexRequest();
    }
View Full Code Here

     * @param index The index name to index the request against
     * @return The index request
     * @see org.elasticsearch.client.Client#index(org.elasticsearch.action.index.IndexRequest)
     */
    public static IndexRequest indexRequest(String index) {
        return new IndexRequest(index);
    }
View Full Code Here

                    break;
                }
                // order is important, we set parent after routing, so routing will be set to parent if not set explicitly
                if ("index".equals(action)) {
                    if (opType == null) {
                        add(new IndexRequest(index, type, id).routing(routing).parent(parent).version(version).versionType(versionType)
                                .source(data, from, nextMarker - from, contentUnsafe)
                                .percolate(percolate));
                    } else {
                        add(new IndexRequest(index, type, id).routing(routing).parent(parent).version(version).versionType(versionType)
                                .create("create".equals(opType))
                                .source(data, from, nextMarker - from, contentUnsafe)
                                .percolate(percolate));
                    }
                } else if ("create".equals(action)) {
                    add(new IndexRequest(index, type, id).routing(routing).parent(parent).version(version).versionType(versionType)
                            .create(true)
                            .source(data, from, nextMarker - from, contentUnsafe)
                            .percolate(percolate));
                }
                // move pointers
View Full Code Here

        consistencyLevel = WriteConsistencyLevel.fromId(in.readByte());
        int size = in.readVInt();
        for (int i = 0; i < size; i++) {
            byte type = in.readByte();
            if (type == 0) {
                IndexRequest request = new IndexRequest();
                request.readFrom(in);
                requests.add(request);
            } else if (type == 1) {
                DeleteRequest request = new DeleteRequest();
                request.readFrom(in);
                requests.add(request);
            }
        }
        refresh = in.readBoolean();
    }
View Full Code Here

    @Override public void readFrom(StreamInput in) throws IOException {
        id = in.readVInt();
        byte type = in.readByte();
        if (type == 0) {
            request = new IndexRequest();
        } else if (type == 1) {
            request = new DeleteRequest();
        }
        request.readFrom(in);
    }
View Full Code Here

        BulkItemResponse[] responses = new BulkItemResponse[request.items().length];
        for (int i = 0; i < request.items().length; i++) {
            BulkItemRequest item = request.items()[i];
            if (item.request() instanceof IndexRequest) {
                IndexRequest indexRequest = (IndexRequest) item.request();
                try {

                    // validate, if routing is required, that we got routing
                    MappingMetaData mappingMd = clusterState.metaData().index(request.index()).mapping(indexRequest.type());
                    if (mappingMd != null && mappingMd.routing().required()) {
                        if (indexRequest.routing() == null) {
                            throw new RoutingMissingException(indexRequest.index(), indexRequest.type(), indexRequest.id());
                        }
                    }

                    SourceToParse sourceToParse = SourceToParse.source(indexRequest.source()).type(indexRequest.type()).id(indexRequest.id())
                            .routing(indexRequest.routing()).parent(indexRequest.parent());
                    long version;
                    Engine.IndexingOperation op;
                    if (indexRequest.opType() == IndexRequest.OpType.INDEX) {
                        Engine.Index index = indexShard.prepareIndex(sourceToParse).version(indexRequest.version()).versionType(indexRequest.versionType()).origin(Engine.Operation.Origin.PRIMARY);
                        indexShard.index(index);
                        version = index.version();
                        op = index;
                    } else {
                        Engine.Create create = indexShard.prepareCreate(sourceToParse).version(indexRequest.version()).versionType(indexRequest.versionType()).origin(Engine.Operation.Origin.PRIMARY);
                        indexShard.create(create);
                        version = create.version();
                        op = create;
                    }
                    // update the version on request so it will happen on the replicas
                    indexRequest.version(version);

                    // update mapping on master if needed, we won't update changes to the same type, since once its changed, it won't have mappers added
                    if (op.parsedDoc().mappersAdded()) {
                        updateMappingOnMaster(indexRequest);
                    }

                    // if we are going to percolate, then we need to keep this op for the postPrimary operation
                    if (Strings.hasLength(indexRequest.percolate())) {
                        if (ops == null) {
                            ops = new Engine.IndexingOperation[request.items().length];
                        }
                        ops[i] = op;
                    }

                    // add the response
                    responses[i] = new BulkItemResponse(item.id(), indexRequest.opType().toString().toLowerCase(),
                            new IndexResponse(indexRequest.index(), indexRequest.type(), indexRequest.id(), version));
                } catch (Exception e) {
                    logger.debug("[{}][{}] failed to bulk item (index) {}", e, shardRequest.request.index(), shardRequest.shardId, indexRequest);
                    responses[i] = new BulkItemResponse(item.id(), indexRequest.opType().toString().toLowerCase(),
                            new BulkItemResponse.Failure(indexRequest.index(), indexRequest.type(), indexRequest.id(), ExceptionsHelper.detailedMessage(e)));
                }
            } else if (item.request() instanceof DeleteRequest) {
                DeleteRequest deleteRequest = (DeleteRequest) item.request();
                try {
                    Engine.Delete delete = indexShard.prepareDelete(deleteRequest.type(), deleteRequest.id(), deleteRequest.version()).versionType(deleteRequest.versionType()).origin(Engine.Operation.Origin.PRIMARY);
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.