当前位置: 首页>>代码示例>>Java>>正文


Java Requests类代码示例

本文整理汇总了Java中org.elasticsearch.client.Requests的典型用法代码示例。如果您正苦于以下问题:Java Requests类的具体用法?Java Requests怎么用?Java Requests使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Requests类属于org.elasticsearch.client包,在下文中一共展示了Requests类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: upsertProduct

import org.elasticsearch.client.Requests; //导入依赖的package包/类
@Test
public void upsertProduct() throws Exception {
  Product product = Product.newBuilder()
      .setProductId(faker.number().randomNumber())
      .setProductName(faker.company().name())
      .setProductPrice(faker.number().randomDouble(2, 10, 100))
      .setProductStatus(ProductStatus.InStock)
      .build();
  productDao.upsertProduct(product);
  esClient.admin().indices().flush(Requests.flushRequest(INDEX)).actionGet();

  GetResponse getResponse = esClient.prepareGet(INDEX, TYPE, String.valueOf(product.getProductId())).get();
  JsonFormat.Parser jsonParser = injector.getInstance(JsonFormat.Parser.class);
  Product.Builder builder = Product.newBuilder();
  jsonParser.merge(getResponse.getSourceAsString(), builder);
  assertThat(builder.build()).isEqualTo(product);
}
 
开发者ID:email2liyang,项目名称:grpc-mate,代码行数:18,代码来源:ProductDaoTest.java

示例2: process

import org.elasticsearch.client.Requests; //导入依赖的package包/类
@Override
  public void process(DeviceEvent element, RuntimeContext ctx, RequestIndexer indexer) {
  	Map<String, Object> json = new HashMap<>();
json.put("phoneNumber", element.getPhoneNumber());
json.put("bin", element.getBin());
json.put("bout", element.getBout());
json.put("timestamp", element.getTimestamp());

System.out.println(json);

      IndexRequest source = Requests.indexRequest()
              .index("flink-test")
              .type("flink-log")
              .source(json);
      
      indexer.add(source);
  }
 
开发者ID:PacktPublishing,项目名称:Practical-Real-time-Processing-and-Analytics,代码行数:18,代码来源:FlinkESConnector.java

示例3: prepareRequest

import org.elasticsearch.client.Requests; //导入依赖的package包/类
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
    BulkRequest bulkRequest = Requests.bulkRequest();
    String defaultIndex = request.param("index");
    String defaultType = request.param("type");
    String defaultRouting = request.param("routing");
    String fieldsParam = request.param("fields");
    String defaultPipeline = request.param("pipeline");
    String[] defaultFields = fieldsParam != null ? Strings.commaDelimitedListToStringArray(fieldsParam) : null;

    String waitForActiveShards = request.param("wait_for_active_shards");
    if (waitForActiveShards != null) {
        bulkRequest.waitForActiveShards(ActiveShardCount.parseString(waitForActiveShards));
    }
    bulkRequest.timeout(request.paramAsTime("timeout", BulkShardRequest.DEFAULT_TIMEOUT));
    bulkRequest.setRefreshPolicy(request.param("refresh"));
    bulkRequest.add(request.content(), defaultIndex, defaultType, defaultRouting, defaultFields, null, defaultPipeline, null, true,
        request.getXContentType());

    // short circuit the call to the transport layer
    return channel -> {
        BulkRestBuilderListener listener = new BulkRestBuilderListener(channel, request);
        listener.onResponse(bulkRequest);
    };
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:26,代码来源:RestNoopBulkAction.java

示例4: waitForRelocation

import org.elasticsearch.client.Requests; //导入依赖的package包/类
/**
 * Waits for all relocating shards to become active and the cluster has reached the given health status
 * using the cluster health API.
 */
public ClusterHealthStatus waitForRelocation(ClusterHealthStatus status) {
    ClusterHealthRequest request = Requests.clusterHealthRequest().waitForNoRelocatingShards(true);
    if (status != null) {
        request.waitForStatus(status);
    }
    ClusterHealthResponse actionGet = client().admin().cluster()
        .health(request).actionGet();
    if (actionGet.isTimedOut()) {
        logger.info("waitForRelocation timed out (status={}), cluster state:\n{}\n{}", status,
            client().admin().cluster().prepareState().get().getState(), client().admin().cluster().preparePendingClusterTasks().get());
        assertThat("timed out waiting for relocation", actionGet.isTimedOut(), equalTo(false));
    }
    if (status != null) {
        assertThat(actionGet.getStatus(), equalTo(status));
    }
    return actionGet.getStatus();
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:22,代码来源:ESIntegTestCase.java

示例5: prepareRequest

import org.elasticsearch.client.Requests; //导入依赖的package包/类
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
    BulkRequest bulkRequest = Requests.bulkRequest();
    String defaultIndex = request.param("index");
    String defaultType = request.param("type");
    String defaultRouting = request.param("routing");
    FetchSourceContext defaultFetchSourceContext = FetchSourceContext.parseFromRestRequest(request);
    String fieldsParam = request.param("fields");
    if (fieldsParam != null) {
        DEPRECATION_LOGGER.deprecated("Deprecated field [fields] used, expected [_source] instead");
    }
    String[] defaultFields = fieldsParam != null ? Strings.commaDelimitedListToStringArray(fieldsParam) : null;
    String defaultPipeline = request.param("pipeline");
    String waitForActiveShards = request.param("wait_for_active_shards");
    if (waitForActiveShards != null) {
        bulkRequest.waitForActiveShards(ActiveShardCount.parseString(waitForActiveShards));
    }
    bulkRequest.timeout(request.paramAsTime("timeout", BulkShardRequest.DEFAULT_TIMEOUT));
    bulkRequest.setRefreshPolicy(request.param("refresh"));
    bulkRequest.add(request.content(), defaultIndex, defaultType, defaultRouting, defaultFields,
        defaultFetchSourceContext, defaultPipeline, null, allowExplicitIndex, request.getXContentType());

    return channel -> client.bulk(bulkRequest, new RestStatusToXContentListener<>(channel));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:25,代码来源:RestBulkAction.java

示例6: assertRealtimeGetWorks

import org.elasticsearch.client.Requests; //导入依赖的package包/类
void assertRealtimeGetWorks(String indexName) {
    assertAcked(client().admin().indices().prepareUpdateSettings(indexName).setSettings(Settings.builder()
            .put("refresh_interval", -1)
            .build()));
    SearchRequestBuilder searchReq = client().prepareSearch(indexName).setQuery(QueryBuilders.matchAllQuery());
    SearchHit hit = searchReq.get().getHits().getAt(0);
    String docId = hit.getId();
    // foo is new, it is not a field in the generated index
    client().prepareUpdate(indexName, "doc", docId).setDoc(Requests.INDEX_CONTENT_TYPE, "foo", "bar").get();
    GetResponse getRsp = client().prepareGet(indexName, "doc", docId).get();
    Map<String, Object> source = getRsp.getSourceAsMap();
    assertThat(source, Matchers.hasKey("foo"));

    assertAcked(client().admin().indices().prepareUpdateSettings(indexName).setSettings(Settings.builder()
            .put("refresh_interval", IndexSettings.DEFAULT_REFRESH_INTERVAL)
            .build()));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:18,代码来源:OldIndexBackwardsCompatibilityIT.java

示例7: testBulkRequestExecution

import org.elasticsearch.client.Requests; //导入依赖的package包/类
public void testBulkRequestExecution() throws Exception {
    BulkRequest bulkRequest = new BulkRequest();
    String pipelineId = "_id";

    int numRequest = scaledRandomIntBetween(8, 64);
    for (int i = 0; i < numRequest; i++) {
        IndexRequest indexRequest = new IndexRequest("_index", "_type", "_id").setPipeline(pipelineId);
        indexRequest.source(Requests.INDEX_CONTENT_TYPE, "field1", "value1");
        bulkRequest.add(indexRequest);
    }

    when(store.get(pipelineId)).thenReturn(new Pipeline(pipelineId, null, version, new CompoundProcessor()));

    @SuppressWarnings("unchecked")
    BiConsumer<IndexRequest, Exception> requestItemErrorHandler = mock(BiConsumer.class);
    @SuppressWarnings("unchecked")
    Consumer<Exception> completionHandler = mock(Consumer.class);
    executionService.executeBulkRequest(bulkRequest.requests(), requestItemErrorHandler, completionHandler);

    verify(requestItemErrorHandler, never()).accept(any(), any());
    verify(completionHandler, times(1)).accept(null);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:23,代码来源:PipelineExecutionServiceTests.java

示例8: testBulk

import org.elasticsearch.client.Requests; //导入依赖的package包/类
public void testBulk() {
    // Index by bulk with RefreshPolicy.WAIT_UNTIL
    BulkRequestBuilder bulk = client().prepareBulk().setRefreshPolicy(RefreshPolicy.WAIT_UNTIL);
    bulk.add(client().prepareIndex("test", "test", "1").setSource("foo", "bar"));
    assertBulkSuccess(bulk.get());
    assertSearchHits(client().prepareSearch("test").setQuery(matchQuery("foo", "bar")).get(), "1");

    // Update by bulk with RefreshPolicy.WAIT_UNTIL
    bulk = client().prepareBulk().setRefreshPolicy(RefreshPolicy.WAIT_UNTIL);
    bulk.add(client().prepareUpdate("test", "test", "1").setDoc(Requests.INDEX_CONTENT_TYPE, "foo", "baz"));
    assertBulkSuccess(bulk.get());
    assertSearchHits(client().prepareSearch("test").setQuery(matchQuery("foo", "baz")).get(), "1");

    // Delete by bulk with RefreshPolicy.WAIT_UNTIL
    bulk = client().prepareBulk().setRefreshPolicy(RefreshPolicy.WAIT_UNTIL);
    bulk.add(client().prepareDelete("test", "test", "1"));
    assertBulkSuccess(bulk.get());
    assertNoSearchHits(client().prepareSearch("test").setQuery(matchQuery("foo", "bar")).get());

    // Update makes a noop
    bulk = client().prepareBulk().setRefreshPolicy(RefreshPolicy.WAIT_UNTIL);
    bulk.add(client().prepareDelete("test", "test", "1"));
    assertBulkSuccess(bulk.get());
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:25,代码来源:WaitUntilRefreshIT.java

示例9: testDynamicDisabled

import org.elasticsearch.client.Requests; //导入依赖的package包/类
public void testDynamicDisabled() {
    IndexRequest request = new IndexRequest("index", "type", "1");
    request.source(Requests.INDEX_CONTENT_TYPE, "foo", 3);
    BulkRequest bulkRequest = new BulkRequest();
    bulkRequest.add(request);
    final AtomicBoolean onFailureCalled = new AtomicBoolean();

    transportBulkAction.execute(bulkRequest, new ActionListener<BulkResponse>() {
        @Override
        public void onResponse(BulkResponse bulkResponse) {
            fail("onResponse shouldn't be called");
        }

        @Override
        public void onFailure(Exception e) {
            onFailureCalled.set(true);
            assertThat(e, instanceOf(IndexNotFoundException.class));
            assertEquals("no such index and [index.mapper.dynamic] is [false]", e.getMessage());
        }
    });

    assertTrue(onFailureCalled.get());
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:24,代码来源:DynamicMappingDisabledTests.java

示例10: testThreadedListeners

import org.elasticsearch.client.Requests; //导入依赖的package包/类
public void testThreadedListeners() throws Throwable {
    final CountDownLatch latch = new CountDownLatch(1);
    final AtomicReference<Throwable> failure = new AtomicReference<>();
    final AtomicReference<String> threadName = new AtomicReference<>();
    Client client = client();

    IndexRequest request = new IndexRequest("test", "type", "1");
    if (randomBoolean()) {
        // set the source, without it, we will have a verification failure
        request.source(Requests.INDEX_CONTENT_TYPE, "field1", "value1");
    }

    client.index(request, new ActionListener<IndexResponse>() {
        @Override
        public void onResponse(IndexResponse indexResponse) {
            threadName.set(Thread.currentThread().getName());
            latch.countDown();
        }

        @Override
        public void onFailure(Exception e) {
            threadName.set(Thread.currentThread().getName());
            failure.set(e);
            latch.countDown();
        }
    });

    latch.await();

    boolean shouldBeThreaded = TransportClient.CLIENT_TYPE.equals(Client.CLIENT_TYPE_SETTING_S.get(client.settings()));
    if (shouldBeThreaded) {
        assertTrue(threadName.get().contains("listener"));
    } else {
        assertFalse(threadName.get().contains("listener"));
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:37,代码来源:ListenerActionIT.java

示例11: testExecuteBulkIndexRequestWithRejection

import org.elasticsearch.client.Requests; //导入依赖的package包/类
public void testExecuteBulkIndexRequestWithRejection() throws Exception {
    IndexMetaData metaData = indexMetaData();
    IndexShard shard = newStartedShard(true);

    BulkItemRequest[] items = new BulkItemRequest[1];
    DocWriteRequest writeRequest = new IndexRequest("index", "type", "id").source(Requests.INDEX_CONTENT_TYPE, "foo", "bar");
    items[0] = new BulkItemRequest(0, writeRequest);
    BulkShardRequest bulkShardRequest = new BulkShardRequest(shardId, RefreshPolicy.NONE, items);

    Translog.Location location = new Translog.Location(0, 0, 0);
    UpdateHelper updateHelper = null;

    // Pretend the mappings haven't made it to the node yet, and throw  a rejection
    Exception err = new ReplicationOperation.RetryOnPrimaryException(shardId, "rejection");

    try {
        TransportShardBulkAction.executeBulkItemRequest(metaData, shard, bulkShardRequest, location,
                0, updateHelper, threadPool::absoluteTimeInMillis, new ThrowingMappingUpdatePerformer(err));
        fail("should have thrown a retry exception");
    } catch (ReplicationOperation.RetryOnPrimaryException e) {
        assertThat(e, equalTo(err));
    }

    closeShards(shard);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:26,代码来源:TransportShardBulkActionTests.java

示例12: testNoopUpdateReplicaRequest

import org.elasticsearch.client.Requests; //导入依赖的package包/类
public void testNoopUpdateReplicaRequest() throws Exception {
    DocWriteRequest writeRequest = new IndexRequest("index", "type", "id").source(Requests.INDEX_CONTENT_TYPE, "field", "value");
    BulkItemRequest replicaRequest = new BulkItemRequest(0, writeRequest);

    DocWriteResponse noopUpdateResponse = new UpdateResponse(shardId, "index", "id", 0, DocWriteResponse.Result.NOOP);
    BulkItemResultHolder noopResults = new BulkItemResultHolder(noopUpdateResponse, null, replicaRequest);

    Translog.Location location = new Translog.Location(0, 0, 0);
    BulkItemRequest[] items = new BulkItemRequest[0];
    BulkShardRequest bulkShardRequest = new BulkShardRequest(shardId, RefreshPolicy.NONE, items);
    Translog.Location newLocation = TransportShardBulkAction.updateReplicaRequest(noopResults,
            DocWriteRequest.OpType.UPDATE, location, bulkShardRequest);

    BulkItemResponse primaryResponse = replicaRequest.getPrimaryResponse();

    // Basically nothing changes in the request since it's a noop
    assertThat(newLocation, equalTo(location));
    assertThat(primaryResponse.getItemId(), equalTo(0));
    assertThat(primaryResponse.getId(), equalTo("id"));
    assertThat(primaryResponse.getOpType(), equalTo(DocWriteRequest.OpType.UPDATE));
    assertThat(primaryResponse.getResponse(), equalTo(noopUpdateResponse));
    assertThat(primaryResponse.getResponse().getResult(), equalTo(DocWriteResponse.Result.NOOP));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:24,代码来源:TransportShardBulkActionTests.java

示例13: testThatMissingIndexDoesNotAbortFullBulkRequest

import org.elasticsearch.client.Requests; //导入依赖的package包/类
public void testThatMissingIndexDoesNotAbortFullBulkRequest() throws Exception{
    createIndex("bulkindex1", "bulkindex2");
    BulkRequest bulkRequest = new BulkRequest();
    bulkRequest.add(new IndexRequest("bulkindex1", "index1_type", "1").source(Requests.INDEX_CONTENT_TYPE, "text", "hallo1"))
               .add(new IndexRequest("bulkindex2", "index2_type", "1").source(Requests.INDEX_CONTENT_TYPE, "text", "hallo2"))
               .add(new IndexRequest("bulkindex2", "index2_type").source(Requests.INDEX_CONTENT_TYPE, "text", "hallo2"))
               .add(new UpdateRequest("bulkindex2", "index2_type", "2").doc(Requests.INDEX_CONTENT_TYPE, "foo", "bar"))
               .add(new DeleteRequest("bulkindex2", "index2_type", "3"))
               .setRefreshPolicy(RefreshPolicy.IMMEDIATE);

    client().bulk(bulkRequest).get();
    SearchResponse searchResponse = client().prepareSearch("bulkindex*").get();
    assertHitCount(searchResponse, 3);

    assertAcked(client().admin().indices().prepareClose("bulkindex2"));

    BulkResponse bulkResponse = client().bulk(bulkRequest).get();
    assertThat(bulkResponse.hasFailures(), is(true));
    assertThat(bulkResponse.getItems().length, is(5));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:21,代码来源:BulkWithUpdatesIT.java

示例14: testFailedRequestsOnClosedIndex

import org.elasticsearch.client.Requests; //导入依赖的package包/类
public void testFailedRequestsOnClosedIndex() throws Exception {
    createIndex("bulkindex1");

    client().prepareIndex("bulkindex1", "index1_type", "1").setSource("text", "test").get();
    assertAcked(client().admin().indices().prepareClose("bulkindex1"));

    BulkRequest bulkRequest = new BulkRequest().setRefreshPolicy(RefreshPolicy.IMMEDIATE);
    bulkRequest.add(new IndexRequest("bulkindex1", "index1_type", "1").source(Requests.INDEX_CONTENT_TYPE, "text", "hallo1"))
            .add(new UpdateRequest("bulkindex1", "index1_type", "1").doc(Requests.INDEX_CONTENT_TYPE, "foo", "bar"))
            .add(new DeleteRequest("bulkindex1", "index1_type", "1"));

    BulkResponse bulkResponse = client().bulk(bulkRequest).get();
    assertThat(bulkResponse.hasFailures(), is(true));
    BulkItemResponse[] responseItems = bulkResponse.getItems();
    assertThat(responseItems.length, is(3));
    assertThat(responseItems[0].getOpType(), is(OpType.INDEX));
    assertThat(responseItems[1].getOpType(), is(OpType.UPDATE));
    assertThat(responseItems[2].getOpType(), is(OpType.DELETE));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:20,代码来源:BulkWithUpdatesIT.java

示例15: handleRequest

import org.elasticsearch.client.Requests; //导入依赖的package包/类
@Override
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
    ClusterStateRequest clusterStateRequest = Requests.clusterStateRequest()
            .routingTable(false)
            .nodes(false);
    clusterStateRequest.local(request.paramAsBoolean("local", clusterStateRequest.local()));
    client.admin().cluster().state(clusterStateRequest, new RestBuilderListener<ClusterStateResponse>(channel) {
        @Override
        public RestResponse buildResponse(ClusterStateResponse response, XContentBuilder builder) throws Exception {
            builder.startObject();

            builder.startObject("persistent");
            response.getState().metaData().persistentSettings().toXContent(builder, request);
            builder.endObject();

            builder.startObject("transient");
            response.getState().metaData().transientSettings().toXContent(builder, request);
            builder.endObject();

            builder.endObject();

            return new BytesRestResponse(RestStatus.OK, builder);
        }
    });
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:26,代码来源:RestClusterGetSettingsAction.java


注:本文中的org.elasticsearch.client.Requests类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。