Examples of IndexResponse


Examples of org.elasticsearch.action.index.IndexResponse

                .setRefresh(true)
                .execute().actionGet();
        client.admin().cluster().prepareHealth().setWaitForGreenStatus().setWaitForActiveShards(4).execute().actionGet();

        for (int i = 0; i < 10; i++) {
            IndexResponse index = client.prepareIndex("test", "type1", Integer.toString(i)).setSource("field1", "value1")
                    .setPercolate("*").execute().actionGet();
            assertThat(index.matches().size(), equalTo(1));
            assertThat(index.matches(), hasItem("kuku"));
        }

        for (int i = 0; i < 10; i++) {
            IndexResponse index = client.prepareIndex("test", "type1", Integer.toString(i)).setSource("field1", "value1")
                    .setPercolate("color:blue").execute().actionGet();
            assertThat(index.matches().size(), equalTo(1));
            assertThat(index.matches(), hasItem("kuku"));
        }

        for (int i = 0; i < 10; i++) {
            IndexResponse index = client.prepareIndex("test", "type1", Integer.toString(i)).setSource("field1", "value1")
                    .setPercolate("color:green").execute().actionGet();
            assertThat(index.matches().size(), equalTo(0));
        }

        // test bulk
        BulkRequestBuilder bulkRequestBuilder = client.prepareBulk();
        for (int i = 0; i < 10; i++) {
            bulkRequestBuilder.add(client.prepareIndex("test", "type1", Integer.toString(i)).setSource("field1", "value1")
                    .setPercolate("*"));
        }
        BulkResponse bulkResponse = bulkRequestBuilder.execute().actionGet();
        assertThat(bulkResponse.hasFailures(), equalTo(false));
        for (BulkItemResponse bulkItemResponse : bulkResponse) {
            IndexResponse index = bulkItemResponse.response();
            assertThat(index.matches().size(), equalTo(1));
            assertThat(index.matches(), hasItem("kuku"));
        }
    }
View Full Code Here

Examples of org.elasticsearch.action.index.IndexResponse

                        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)));
                }
View Full Code Here

Examples of org.elasticsearch.action.index.IndexResponse

        id = in.readVInt();
        opType = in.readUTF();

        byte type = in.readByte();
        if (type == 0) {
            response = new IndexResponse();
            response.readFrom(in);
        } else if (type == 1) {
            response = new DeleteResponse();
            response.readFrom(in);
        }
View Full Code Here

Examples of org.elasticsearch.action.index.IndexResponse

                            builder.field(Fields.ERROR, itemResponse.failure().message());
                        } else {
                            builder.field(Fields.OK, true);
                        }
                        if (itemResponse.response() instanceof IndexResponse) {
                            IndexResponse indexResponse = itemResponse.response();
                            if (indexResponse.matches() != null) {
                                builder.startArray(Fields.MATCHES);
                                for (String match : indexResponse.matches()) {
                                    builder.value(match);
                                }
                                builder.endArray();
                            }
                        }
View Full Code Here

Examples of org.elasticsearch.action.index.IndexResponse

        if (!setIndexRequestSource(document, prepareIndex)) {
            throw new ExpectedBodyTypeException(exchange, XContentBuilder.class);
        }
        ListenableActionFuture<IndexResponse> future = prepareIndex.execute();
        IndexResponse response = future.actionGet();
        exchange.getIn().setBody(response.getId());
    }
View Full Code Here

Examples of org.elasticsearch.action.index.IndexResponse

  protected void flushIndex() {
    nodeTemplate.flushIndex();
  }

  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");
View Full Code Here

Examples of org.elasticsearch.action.index.IndexResponse

    private String add(String index, String type, String routing, String json) {
        IndexRequestBuilder req =  client.prepareIndex(index, type).setSource(json);
        if (routing != null)
            req.setRouting(routing);
       
        IndexResponse rsp = req.execute().actionGet();
        return rsp.getId();
    }
View Full Code Here

Examples of org.elasticsearch.action.index.IndexResponse

        String topic = request.hasParam("topic") ? request.paramAsString("topic") : "*";
        try {
            // advertise phase - save message in the index (for disconnected subscribers)
            final XContentBuilder messageBuilder = createPublishMessage(request);
            final XContentBuilder responseBuilder = jsonBuilder().startObject();
            IndexResponse indexResponse = client.prepareIndex()
                    .setIndex(pubSubIndexName)
                    .setType(TYPE)
                    .setSource(messageBuilder)
                    .setRefresh(request.paramAsBoolean("refresh", true))
                    .execute().actionGet();
            responseBuilder.field("id", indexResponse.getId());
            // push phase - scroll over subscribers for this topic currently connected
            QueryBuilder queryBuilder = termQuery("topic", topic);
            SearchResponse searchResponse = client.prepareSearch()
                    .setIndices(pubSubIndexName)
                    .setTypes("subscribe")
View Full Code Here

Examples of org.elasticsearch.action.index.IndexResponse

            documentRevision = generateRevisionNumber();
            document.put("_rev", documentRevision);
        }
        IndexRequestBuilder indexBuilder = client.prepareIndex(index, docType, docId);
        indexBuilder.setSource(document);
        IndexResponse response = indexBuilder.execute().actionGet();
        if(response != null) {
            return documentRevision;
        }
        return null;
    }
View Full Code Here

Examples of org.elasticsearch.action.index.IndexResponse

        builder.setId(id);
        builder.setType(this.checkpointDocumentType);
        builder.setSource(toBeIndexed);
        builder.setOpType(OpType.CREATE);

        IndexResponse response;
        ListenableActionFuture<IndexResponse> laf = builder.execute();
        if(laf != null) {
            response = laf.actionGet();
            if(!response.isCreated()) {
                logger.error("did not succeed creating uuid");
            }
        }
    }
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.