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


Java RefreshPolicy类代码示例

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


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

示例1: testAliasSearchRoutingWithConcreteAndAliasedIndices_issue2682

import org.elasticsearch.action.support.WriteRequest.RefreshPolicy; //导入依赖的package包/类
public void testAliasSearchRoutingWithConcreteAndAliasedIndices_issue2682() throws Exception {
    createIndex("index", "index_2");
    ensureGreen();
    assertAcked(admin().indices().prepareAliases()
            .addAliasAction(AliasActions.add().index("index").alias("index_1").routing("1")));

    logger.info("--> indexing on index_1 which is an alias for index with routing [1]");
    client().prepareIndex("index_1", "type1", "1").setSource("field", "value1").setRefreshPolicy(RefreshPolicy.IMMEDIATE).get();
    logger.info("--> indexing on index_2 which is a concrete index");
    client().prepareIndex("index_2", "type2", "2").setSource("field", "value2").setRefreshPolicy(RefreshPolicy.IMMEDIATE).get();


    logger.info("--> search all on index_* should find two");
    for (int i = 0; i < 5; i++) {
        assertThat(client().prepareSearch("index_*").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().getTotalHits(), equalTo(2L));
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:18,代码来源:AliasRoutingIT.java

示例2: testAliasSearchRoutingWithConcreteAndAliasedIndices_issue3268

import org.elasticsearch.action.support.WriteRequest.RefreshPolicy; //导入依赖的package包/类
public void testAliasSearchRoutingWithConcreteAndAliasedIndices_issue3268() throws Exception {
    createIndex("index", "index_2");
    ensureGreen();
    assertAcked(admin().indices().prepareAliases()
            .addAliasAction(AliasActions.add().index("index").alias("index_1").routing("1")));

    logger.info("--> indexing on index_1 which is an alias for index with routing [1]");
    client().prepareIndex("index_1", "type1", "1").setSource("field", "value1").setRefreshPolicy(RefreshPolicy.IMMEDIATE).get();
    logger.info("--> indexing on index_2 which is a concrete index");
    client().prepareIndex("index_2", "type2", "2").setSource("field", "value2").setRefreshPolicy(RefreshPolicy.IMMEDIATE).get();

    SearchResponse searchResponse = client().prepareSearch("index_*").setSearchType(SearchType.QUERY_THEN_FETCH).setSize(1).setQuery(QueryBuilders.matchAllQuery()).execute().actionGet();

    logger.info("--> search all on index_* should find two");
    assertThat(searchResponse.getHits().getTotalHits(), equalTo(2L));
    //Let's make sure that, even though 2 docs are available, only one is returned according to the size we set in the request
    //Therefore the reduce phase has taken place, which proves that the QUERY_AND_FETCH search type wasn't erroneously forced.
    assertThat(searchResponse.getHits().getHits().length, equalTo(1));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:20,代码来源:AliasRoutingIT.java

示例3: testBulk

import org.elasticsearch.action.support.WriteRequest.RefreshPolicy; //导入依赖的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

示例4: testPrimaryWaitForRefresh

import org.elasticsearch.action.support.WriteRequest.RefreshPolicy; //导入依赖的package包/类
public void testPrimaryWaitForRefresh() throws Exception {
    TestRequest request = new TestRequest();
    request.setRefreshPolicy(RefreshPolicy.WAIT_UNTIL);

    TestAction testAction = new TestAction();
    TransportWriteAction.WritePrimaryResult<TestRequest, TestResponse> result =
            testAction.shardOperationOnPrimary(request, indexShard);
    CapturingActionListener<TestResponse> listener = new CapturingActionListener<>();
    result.respond(listener);
    assertNull(listener.response); // Haven't reallresponded yet

    @SuppressWarnings({ "unchecked", "rawtypes" })
    ArgumentCaptor<Consumer<Boolean>> refreshListener = ArgumentCaptor.forClass((Class) Consumer.class);
    verify(indexShard, never()).refresh(any());
    verify(indexShard).addRefreshListener(any(), refreshListener.capture());

    // Now we can fire the listener manually and we'll get a response
    boolean forcedRefresh = randomBoolean();
    refreshListener.getValue().accept(forcedRefresh);
    assertNotNull(listener.response);
    assertNull(listener.failure);
    assertEquals(forcedRefresh, listener.response.forcedRefresh);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:24,代码来源:TransportWriteActionTests.java

示例5: testReplicaWaitForRefresh

import org.elasticsearch.action.support.WriteRequest.RefreshPolicy; //导入依赖的package包/类
public void testReplicaWaitForRefresh() throws Exception {
    TestRequest request = new TestRequest();
    request.setRefreshPolicy(RefreshPolicy.WAIT_UNTIL);
    TestAction testAction = new TestAction();
    TransportWriteAction.WriteReplicaResult<TestRequest> result = testAction.shardOperationOnReplica(request, indexShard);
    CapturingActionListener<TransportResponse.Empty> listener = new CapturingActionListener<>();
    result.respond(listener);
    assertNull(listener.response); // Haven't responded yet
    @SuppressWarnings({ "unchecked", "rawtypes" })
    ArgumentCaptor<Consumer<Boolean>> refreshListener = ArgumentCaptor.forClass((Class) Consumer.class);
    verify(indexShard, never()).refresh(any());
    verify(indexShard).addRefreshListener(any(), refreshListener.capture());

    // Now we can fire the listener manually and we'll get a response
    boolean forcedRefresh = randomBoolean();
    refreshListener.getValue().accept(forcedRefresh);
    assertNotNull(listener.response);
    assertNull(listener.failure);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:20,代码来源:TransportWriteActionTests.java

示例6: testExecuteBulkIndexRequestWithRejection

import org.elasticsearch.action.support.WriteRequest.RefreshPolicy; //导入依赖的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

示例7: testNoopUpdateReplicaRequest

import org.elasticsearch.action.support.WriteRequest.RefreshPolicy; //导入依赖的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

示例8: testBulkRequestWithRefresh

import org.elasticsearch.action.support.WriteRequest.RefreshPolicy; //导入依赖的package包/类
public void testBulkRequestWithRefresh() throws Exception {
    BulkRequest bulkRequest = new BulkRequest();
    // We force here a "id is missing" validation error
    bulkRequest.add(new DeleteRequest("index", "type", null).setRefreshPolicy(RefreshPolicy.IMMEDIATE));
    // We force here a "type is missing" validation error
    bulkRequest.add(new DeleteRequest("index", null, "id"));
    bulkRequest.add(new DeleteRequest("index", "type", "id").setRefreshPolicy(RefreshPolicy.IMMEDIATE));
    bulkRequest.add(new UpdateRequest("index", "type", "id").doc("{}", XContentType.JSON).setRefreshPolicy(RefreshPolicy.IMMEDIATE));
    bulkRequest.add(new IndexRequest("index", "type", "id").source("{}", XContentType.JSON).setRefreshPolicy(RefreshPolicy.IMMEDIATE));
    ActionRequestValidationException validate = bulkRequest.validate();
    assertThat(validate, notNullValue());
    assertThat(validate.validationErrors(), not(empty()));
    assertThat(validate.validationErrors(), contains(
            "RefreshPolicy is not supported on an item request. Set it on the BulkRequest instead.",
            "id is missing",
            "type is missing",
            "RefreshPolicy is not supported on an item request. Set it on the BulkRequest instead.",
            "RefreshPolicy is not supported on an item request. Set it on the BulkRequest instead.",
            "RefreshPolicy is not supported on an item request. Set it on the BulkRequest instead."));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:21,代码来源:BulkRequestTests.java

示例9: testThatMissingIndexDoesNotAbortFullBulkRequest

import org.elasticsearch.action.support.WriteRequest.RefreshPolicy; //导入依赖的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

示例10: testFailedRequestsOnClosedIndex

import org.elasticsearch.action.support.WriteRequest.RefreshPolicy; //导入依赖的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

示例11: processNext

import org.elasticsearch.action.support.WriteRequest.RefreshPolicy; //导入依赖的package包/类
private void processNext(final long position) {
    if (logger.isDebugEnabled()) {
        logger.debug("RequestSender(" + index + ") moves next files.");
    }
    final Map<String, Object> source = new HashMap<>();
    source.put(IndexingProxyPlugin.FILE_POSITION, position);
    source.put(IndexingProxyPlugin.TIMESTAMP, new Date());
    client.prepareUpdate(IndexingProxyPlugin.INDEX_NAME, IndexingProxyPlugin.TYPE_NAME, index).setVersion(version).setDoc(source)
            .setRefreshPolicy(RefreshPolicy.WAIT_UNTIL).execute(wrap(res -> {
                errorCount = 0;
                requestErrorCount = 0;
                threadPool.schedule(TimeValue.ZERO, Names.GENERIC, this);
                // retry: success
            }, e -> {
                logger.error("[Sender][" + index + "] Failed to update config data.", e);
                threadPool.schedule(TimeValue.ZERO, Names.GENERIC, this);
                // retry
            }));
}
 
开发者ID:codelibs,项目名称:elasticsearch-indexing-proxy,代码行数:20,代码来源:RequestSender.java

示例12: uploadFile

import org.elasticsearch.action.support.WriteRequest.RefreshPolicy; //导入依赖的package包/类
public static void uploadFile(Client tc, String filepath, String index, String id) throws Exception {
    LOGGER.info("Will update '" + id + "' with " + filepath);
    try (Reader reader = new FileReader(filepath)) {

        final String res = tc
                .index(new IndexRequest(index).type("sg").id(id).setRefreshPolicy(RefreshPolicy.IMMEDIATE)
                        .source(id, readXContent(reader, XContentType.YAML))).actionGet().getId();

        if (id.equals(res)) {
            //System.out.println("   SUCC: Configuration for '" + type + "' created or updated");
        } else {
            throw new Exception("   FAIL: Configuration for '" + id
                    + "' failed for unknown reasons. Pls. consult logfile of elasticsearch");
        }
    } catch (Exception e) {
        throw e;
    }
}
 
开发者ID:floragunncom,项目名称:search-guard,代码行数:19,代码来源:ConfigHelper.java

示例13: createOrGetTrial

import org.elasticsearch.action.support.WriteRequest.RefreshPolicy; //导入依赖的package包/类
private SearchGuardLicense createOrGetTrial(String msg) {
    long created = System.currentTimeMillis();
    ThreadContext threadContext = threadPool.getThreadContext();
    
    try(StoredContext ctx = threadContext.stashContext()) {
        threadContext.putHeader(ConfigConstants.SG_CONF_REQUEST_HEADER, "true");
        GetResponse get = client.prepareGet(searchguardIndex, "sg", "tattr").get();
        if(get.isExists()) {
            created = (long) get.getSource().get("val");
        } else {
            client.index(new IndexRequest(searchguardIndex)
            .type("sg")
            .id("tattr")
            .setRefreshPolicy(RefreshPolicy.IMMEDIATE)
            .source("{\"val\": "+System.currentTimeMillis()+"}", XContentType.JSON)).actionGet();
        }
    }
    
    return SearchGuardLicense.createTrialLicense(formatDate(created), clusterService, msg);
}
 
开发者ID:floragunncom,项目名称:search-guard,代码行数:21,代码来源:IndexBaseConfigurationRepository.java

示例14: testSingle

import org.elasticsearch.action.support.WriteRequest.RefreshPolicy; //导入依赖的package包/类
@Test
public void testSingle() throws Exception {

    setup();

    try (TransportClient tc = getInternalTransportClient()) {          
        tc.index(new IndexRequest("shakespeare").type("type").id("1").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON)).actionGet();
                  
        ConfigUpdateResponse cur = tc.execute(ConfigUpdateAction.INSTANCE, new ConfigUpdateRequest(new String[]{"config","roles","rolesmapping","internalusers","actiongroups"})).actionGet();
        Assert.assertEquals(3, cur.getNodes().size());
    }

    RestHelper rh = nonSslRestHelper();
    //sg_shakespeare -> picard

    HttpResponse resc = rh.executeGetRequest("shakespeare/_search", encodeBasicHeader("picard", "picard"));
    System.out.println(resc.getBody());
    Assert.assertEquals(HttpStatus.SC_OK, resc.getStatusCode());
    Assert.assertTrue(resc.getBody().contains("\"content\":1"));
    
    resc = rh.executeHeadRequest("shakespeare", encodeBasicHeader("picard", "picard"));
    Assert.assertEquals(HttpStatus.SC_OK, resc.getStatusCode());
    
}
 
开发者ID:floragunncom,项目名称:search-guard,代码行数:25,代码来源:IntegrationTests.java

示例15: store

import org.elasticsearch.action.support.WriteRequest.RefreshPolicy; //导入依赖的package包/类
public void store(final String path, final byte[] contentArray, final ActionListener<IndexResponse> listener) {
    checkIfIndexExists(wrap(response -> {
        try {
            final String id = getId(path);
            final XContentBuilder builder = JsonXContent.contentBuilder();
            builder.startObject();
            builder.field(PATH, path);
            builder.field(CONTENT, contentArray);
            builder.field(TIMESTAMP, new Date());
            builder.endObject();
            client.prepareIndex(index, type, id).setSource(builder).setRefreshPolicy(RefreshPolicy.IMMEDIATE).execute(listener);
        } catch (final IOException e) {
            throw new ElasticsearchException("Failed to register " + path, e);
        }
    }, listener::onFailure));
}
 
开发者ID:codelibs,项目名称:elasticsearch-configsync,代码行数:17,代码来源:ConfigSyncService.java


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