• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java RefreshPolicy类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: testParentChildQueriesCanHandleNoRelevantTypesInIndex

import org.elasticsearch.action.support.WriteRequest.RefreshPolicy; //导入依赖的package包/类
public void testParentChildQueriesCanHandleNoRelevantTypesInIndex() throws Exception {
    assertAcked(prepareCreate("test")
            .addMapping("parent")
            .addMapping("child", "_parent", "type=parent"));
    ensureGreen();

    SearchResponse response = client().prepareSearch("test")
            .setQuery(QueryBuilders.hasChildQuery("child", matchQuery("text", "value"), ScoreMode.None)).get();
    assertNoFailures(response);
    assertThat(response.getHits().getTotalHits(), equalTo(0L));

    client().prepareIndex("test", "child1").setSource(jsonBuilder().startObject().field("text", "value").endObject())
            .setRefreshPolicy(RefreshPolicy.IMMEDIATE).get();

    response = client().prepareSearch("test")
            .setQuery(QueryBuilders.hasChildQuery("child", matchQuery("text", "value"), ScoreMode.None)).get();
    assertNoFailures(response);
    assertThat(response.getHits().getTotalHits(), equalTo(0L));

    response = client().prepareSearch("test").setQuery(QueryBuilders.hasChildQuery("child", matchQuery("text", "value"), ScoreMode.Max))
            .get();
    assertNoFailures(response);
    assertThat(response.getHits().getTotalHits(), equalTo(0L));

    response = client().prepareSearch("test").setQuery(QueryBuilders.hasParentQuery("parent", matchQuery("text", "value"), false)).get();
    assertNoFailures(response);
    assertThat(response.getHits().getTotalHits(), equalTo(0L));

    response = client().prepareSearch("test").setQuery(QueryBuilders.hasParentQuery("parent", matchQuery("text", "value"), true))
            .get();
    assertNoFailures(response);
    assertThat(response.getHits().getTotalHits(), equalTo(0L));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:34,代码来源:ChildQuerySearchIT.java


示例17: assertPositionIncrementGapDefaults

import org.elasticsearch.action.support.WriteRequest.RefreshPolicy; //导入依赖的package包/类
void assertPositionIncrementGapDefaults(String indexName, Version version) throws Exception {
    client().prepareIndex(indexName, "doc", "position_gap_test").setSource("string", Arrays.asList("one", "two three"))
        .setRefreshPolicy(RefreshPolicy.IMMEDIATE).get();

    // Baseline - phrase query finds matches in the same field value
    assertHitCount(client().prepareSearch(indexName).setQuery(matchPhraseQuery("string", "two three")).get(), 1);

    // No match across gaps when slop < position gap
    assertHitCount(
            client().prepareSearch(indexName).setQuery(matchPhraseQuery("string", "one two").slop(99)).get(),
            0);

    // Match across gaps when slop >= position gap
    assertHitCount(client().prepareSearch(indexName).setQuery(matchPhraseQuery("string", "one two").slop(100)).get(), 1);
    assertHitCount(client().prepareSearch(indexName).setQuery(matchPhraseQuery("string", "one two").slop(101)).get(),
            1);

    // No match across gap using default slop with default positionIncrementGap
    assertHitCount(client().prepareSearch(indexName).setQuery(matchPhraseQuery("string", "one two")).get(), 0);

    // Nor with small-ish values
    assertHitCount(client().prepareSearch(indexName).setQuery(matchPhraseQuery("string", "one two").slop(5)).get(), 0);
    assertHitCount(client().prepareSearch(indexName).setQuery(matchPhraseQuery("string", "one two").slop(50)).get(), 0);

    // But huge-ish values still match
    assertHitCount(client().prepareSearch(indexName).setQuery(matchPhraseQuery("string", "one two").slop(500)).get(), 1);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:28,代码来源:OldIndexBackwardsCompatibilityIT.java


示例18: testIndex

import org.elasticsearch.action.support.WriteRequest.RefreshPolicy; //导入依赖的package包/类
public void testIndex() {
    IndexResponse index = client().prepareIndex("test", "index", "1").setSource("foo", "bar").setRefreshPolicy(RefreshPolicy.WAIT_UNTIL)
            .get();
    assertEquals(RestStatus.CREATED, index.status());
    assertFalse("request shouldn't have forced a refresh", index.forcedRefresh());
    assertSearchHits(client().prepareSearch("test").setQuery(matchQuery("foo", "bar")).get(), "1");
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:8,代码来源:WaitUntilRefreshIT.java


示例19: testDelete

import org.elasticsearch.action.support.WriteRequest.RefreshPolicy; //导入依赖的package包/类
public void testDelete() throws InterruptedException, ExecutionException {
    // Index normally
    indexRandom(true, client().prepareIndex("test", "test", "1").setSource("foo", "bar"));
    assertSearchHits(client().prepareSearch("test").setQuery(matchQuery("foo", "bar")).get(), "1");

    // Now delete with blockUntilRefresh
    DeleteResponse delete = client().prepareDelete("test", "test", "1").setRefreshPolicy(RefreshPolicy.WAIT_UNTIL).get();
    assertEquals(DocWriteResponse.Result.DELETED, delete.getResult());
    assertFalse("request shouldn't have forced a refresh", delete.forcedRefresh());
    assertNoSearchHits(client().prepareSearch("test").setQuery(matchQuery("foo", "bar")).get());
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:12,代码来源:WaitUntilRefreshIT.java


示例20: testUpdate

import org.elasticsearch.action.support.WriteRequest.RefreshPolicy; //导入依赖的package包/类
public void testUpdate() throws InterruptedException, ExecutionException {
    // Index normally
    indexRandom(true, client().prepareIndex("test", "test", "1").setSource("foo", "bar"));
    assertSearchHits(client().prepareSearch("test").setQuery(matchQuery("foo", "bar")).get(), "1");

    // Update with RefreshPolicy.WAIT_UNTIL
    UpdateResponse update = client().prepareUpdate("test", "test", "1")
        .setDoc(Requests.INDEX_CONTENT_TYPE, "foo", "baz").setRefreshPolicy(RefreshPolicy.WAIT_UNTIL)
            .get();
    assertEquals(2, update.getVersion());
    assertFalse("request shouldn't have forced a refresh", update.forcedRefresh());
    assertSearchHits(client().prepareSearch("test").setQuery(matchQuery("foo", "baz")).get(), "1");

    // Upsert with RefreshPolicy.WAIT_UNTIL
    update = client().prepareUpdate("test", "test", "2").setDocAsUpsert(true).setDoc(Requests.INDEX_CONTENT_TYPE, "foo", "cat")
            .setRefreshPolicy(RefreshPolicy.WAIT_UNTIL).get();
    assertEquals(1, update.getVersion());
    assertFalse("request shouldn't have forced a refresh", update.forcedRefresh());
    assertSearchHits(client().prepareSearch("test").setQuery(matchQuery("foo", "cat")).get(), "2");

    // Update-becomes-delete with RefreshPolicy.WAIT_UNTIL
    update = client().prepareUpdate("test", "test", "2").setScript(new Script(ScriptType.INLINE, "native", "delete_plz", emptyMap()))
            .setRefreshPolicy(RefreshPolicy.WAIT_UNTIL).get();
    assertEquals(2, update.getVersion());
    assertFalse("request shouldn't have forced a refresh", update.forcedRefresh());
    assertNoSearchHits(client().prepareSearch("test").setQuery(matchQuery("foo", "cat")).get());
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:28,代码来源:WaitUntilRefreshIT.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java ITransactionalSpout类代码示例发布时间:2022-05-22
下一篇:
Java NodeMismatch类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap