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


Java IndexRequestBuilder.setRouting方法代码示例

本文整理汇总了Java中org.elasticsearch.action.index.IndexRequestBuilder.setRouting方法的典型用法代码示例。如果您正苦于以下问题:Java IndexRequestBuilder.setRouting方法的具体用法?Java IndexRequestBuilder.setRouting怎么用?Java IndexRequestBuilder.setRouting使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.elasticsearch.action.index.IndexRequestBuilder的用法示例。


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

示例1: testCommonTerms

import org.elasticsearch.action.index.IndexRequestBuilder; //导入方法依赖的package包/类
public void testCommonTerms() throws ExecutionException, InterruptedException {
    String route = "commonTermsTest";
    List<IndexRequestBuilder> builders = getDocs();
    for (IndexRequestBuilder indexRequet : builders) {
        // route all docs to same shard for this test
        indexRequet.setRouting(route);
    }
    indexRandom(true, false, builders);

    // do a search with no cutoff frequency to show which docs should match
    SearchResponse searchResponse = client().prepareSearch(INDEX)
        .setRouting(route)
        .setQuery(QueryBuilders.matchQuery("field", "bar three happened")
            .operator(Operator.OR)).get();

    assertHitCount(searchResponse, 4L);
    assertSearchHits(searchResponse, "1", "2", "5", "6");

    // do same search with cutoff and see less documents match
    // in this case, essentially everything but "happened" gets excluded
    searchResponse = client().prepareSearch(INDEX)
        .setRouting(route)
        .setQuery(QueryBuilders.matchQuery("field", "bar three happened")
            .operator(Operator.OR).cutoffFrequency(1f)).get();

    assertHitCount(searchResponse, 1L);
    assertSearchHits(searchResponse, "1");
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:29,代码来源:MatchQueryIT.java

示例2: create

import org.elasticsearch.action.index.IndexRequestBuilder; //导入方法依赖的package包/类
private TestContext create(SearchType... searchTypes) throws Exception {
    assertAcked(prepareCreate("index").addMapping("type", jsonBuilder().startObject().startObject("type").startObject("properties")
            .startObject("field1")
                .field("type", "long")
            .endObject()
            .startObject("field2")
                .field("type", "keyword")
            .endObject()
            .startObject("nested")
                .field("type", "nested")
                .startObject("properties")
                    .startObject("field3")
                        .field("type", "long")
                    .endObject()
                    .startObject("field4")
                        .field("type", "keyword")
                    .endObject()
                .endObject()
            .endObject()
            .endObject().endObject().endObject()));

    int numDocs = 2 + randomInt(512);
    int scrollRequestSize = randomIntBetween(1, rarely() ? numDocs : numDocs / 2);
    boolean unevenRouting = randomBoolean();

    int numMissingDocs = scaledRandomIntBetween(0, numDocs / 100);
    IntHashSet missingDocs = new IntHashSet(numMissingDocs);
    for (int i = 0; i < numMissingDocs; i++) {
        while (!missingDocs.add(randomInt(numDocs))) {}
    }

    for (int i = 1; i <= numDocs; i++) {
        IndexRequestBuilder indexRequestBuilder = client()
                .prepareIndex("index", "type", String.valueOf(i));
        if (missingDocs.contains(i)) {
            indexRequestBuilder.setSource("x", "y");
        } else {
            indexRequestBuilder.setSource(jsonBuilder().startObject()
                    .field("field1", i)
                    .field("field2", String.valueOf(i))
                    .startObject("nested")
                        .field("field3", i)
                        .field("field4", String.valueOf(i))
                    .endObject()
                    .endObject());
        }

        if (unevenRouting && randomInt(3) <= 2) {
            indexRequestBuilder.setRouting("a");
        }
        indexRandom(false, indexRequestBuilder);
    }
    refresh();

    final SortBuilder sort;
    if (randomBoolean()) {
        if (randomBoolean()) {
            sort = SortBuilders.fieldSort("field1").missing(1);
        } else {
            sort = SortBuilders.fieldSort("field2")
                    .missing("1");
        }
    } else {
        if (randomBoolean()) {
            sort = SortBuilders.fieldSort("nested.field3").missing(1);
        } else {
            sort = SortBuilders.fieldSort("nested.field4").missing("1");
        }
    }
    sort.order(randomBoolean() ? SortOrder.ASC : SortOrder.DESC);

    SearchType searchType = RandomPicks.randomFrom(random(), Arrays.asList(searchTypes));

    logger.info("numDocs={}, scrollRequestSize={}, sort={}, searchType={}", numDocs, scrollRequestSize, sort, searchType);
    return new TestContext(numDocs, scrollRequestSize, sort, searchType);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:77,代码来源:DuelScrollIT.java


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