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


Java ActionFuture.actionGet方法代码示例

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


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

示例1: assertThrows

import org.elasticsearch.action.ActionFuture; //导入方法依赖的package包/类
public static void assertThrows(ActionFuture future, RestStatus status, String extraInfo) {
    boolean fail = false;
    extraInfo = extraInfo == null || extraInfo.isEmpty() ? "" : extraInfo + ": ";
    extraInfo += "expected a " + status + " status exception to be thrown";

    try {
        future.actionGet();
        fail = true;
    } catch (Exception e) {
        assertThat(extraInfo, ExceptionsHelper.status(e), equalTo(status));
    }
    // has to be outside catch clause to get a proper message
    if (fail) {
        throw new AssertionError(extraInfo);
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:17,代码来源:ElasticsearchAssertions.java

示例2: testExceptionThrownIfScaleLE0

import org.elasticsearch.action.ActionFuture; //导入方法依赖的package包/类
public void testExceptionThrownIfScaleLE0() throws Exception {
    assertAcked(prepareCreate("test").addMapping(
            "type1",
            jsonBuilder().startObject().startObject("type1").startObject("properties").startObject("test").field("type", "text")
                    .endObject().startObject("num1").field("type", "date").endObject().endObject().endObject().endObject()));
    client().index(
            indexRequest("test").type("type1").id("1")
                    .source(jsonBuilder().startObject().field("test", "value").field("num1", "2013-05-27").endObject())).actionGet();
    client().index(
            indexRequest("test").type("type1").id("2")
                    .source(jsonBuilder().startObject().field("test", "value").field("num1", "2013-05-28").endObject())).actionGet();
    refresh();

    ActionFuture<SearchResponse> response = client().search(
            searchRequest().searchType(SearchType.QUERY_THEN_FETCH).source(
                    searchSource().query(
                            functionScoreQuery(termQuery("test", "value"), gaussDecayFunction("num1", "2013-05-28", "-1d")))));
    try {
        response.actionGet();
        fail("Expected SearchPhaseExecutionException");
    } catch (SearchPhaseExecutionException e) {
        assertThat(e.getMessage(), is("all shards failed"));
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:25,代码来源:DecayFunctionScoreIT.java

示例3: testParsingExceptionIfFieldTypeDoesNotMatch

import org.elasticsearch.action.ActionFuture; //导入方法依赖的package包/类
public void testParsingExceptionIfFieldTypeDoesNotMatch() throws Exception {
    assertAcked(prepareCreate("test").addMapping(
            "type",
            jsonBuilder().startObject().startObject("type").startObject("properties").startObject("test").field("type", "text")
                    .endObject().startObject("num").field("type", "text").endObject().endObject().endObject().endObject()));
    client().index(
            indexRequest("test").type("type").source(
                    jsonBuilder().startObject().field("test", "value").field("num", Integer.toString(1)).endObject())).actionGet();
    refresh();
    // so, we indexed a string field, but now we try to score a num field
    ActionFuture<SearchResponse> response = client().search(searchRequest().searchType(SearchType.QUERY_THEN_FETCH)
            .source(searchSource().query(functionScoreQuery(termQuery("test", "value"), linearDecayFunction("num", 1.0, 0.5))
                    .scoreMode(ScoreMode.MULTIPLY))));
    try {
        response.actionGet();
        fail("Expected SearchPhaseExecutionException");
    } catch (SearchPhaseExecutionException e) {
        assertThat(e.getMessage(), is("all shards failed"));
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:21,代码来源:DecayFunctionScoreIT.java

示例4: testNoQueryGiven

import org.elasticsearch.action.ActionFuture; //导入方法依赖的package包/类
public void testNoQueryGiven() throws Exception {
    assertAcked(prepareCreate("test").addMapping(
            "type",
            jsonBuilder().startObject().startObject("type").startObject("properties").startObject("test").field("type", "text")
                    .endObject().startObject("num").field("type", "double").endObject().endObject().endObject().endObject()));
    client().index(
            indexRequest("test").type("type").source(jsonBuilder().startObject().field("test", "value").field("num", 1.0).endObject()))
            .actionGet();
    refresh();
    // so, we indexed a string field, but now we try to score a num field
    ActionFuture<SearchResponse> response = client().search(
            searchRequest().searchType(SearchType.QUERY_THEN_FETCH).source(
                    searchSource().query(
                            functionScoreQuery(linearDecayFunction("num", 1, 0.5)).scoreMode(
                                    FiltersFunctionScoreQuery.ScoreMode.MULTIPLY))));
    response.actionGet();
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:18,代码来源:DecayFunctionScoreIT.java

示例5: testParsingExceptionIfFieldDoesNotExist

import org.elasticsearch.action.ActionFuture; //导入方法依赖的package包/类
public void testParsingExceptionIfFieldDoesNotExist() throws Exception {
    assertAcked(prepareCreate("test").addMapping(
            "type",
            jsonBuilder().startObject().startObject("type").startObject("properties").startObject("test").field("type", "text")
                    .endObject().startObject("geo").field("type", "geo_point").endObject().endObject().endObject().endObject()));
    int numDocs = 2;
    client().index(
            indexRequest("test").type("type").source(
                    jsonBuilder().startObject().field("test", "value").startObject("geo").field("lat", 1).field("lon", 2).endObject()
                            .endObject())).actionGet();
    refresh();
    List<Float> lonlat = new ArrayList<>();
    lonlat.add(100f);
    lonlat.add(110f);
    ActionFuture<SearchResponse> response = client().search(
            searchRequest().searchType(SearchType.QUERY_THEN_FETCH).source(
                    searchSource()
                            .size(numDocs)
                            .query(functionScoreQuery(termQuery("test", "value"), linearDecayFunction("type.geo", lonlat, "1000km"))
                                    .scoreMode(FiltersFunctionScoreQuery.ScoreMode.MULTIPLY))));
    try {
        response.actionGet();
        fail("Expected SearchPhaseExecutionException");
    } catch (SearchPhaseExecutionException e) {
        assertThat(e.getMessage(), is("all shards failed"));
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:28,代码来源:DecayFunctionScoreIT.java

示例6: testPlugin

import org.elasticsearch.action.ActionFuture; //导入方法依赖的package包/类
public void testPlugin() throws Exception {
    client().admin()
            .indices()
            .prepareCreate("test")
            .addMapping(
                    "type1",
                    jsonBuilder().startObject().startObject("type1").startObject("properties").startObject("test")
                            .field("type", "text").endObject().startObject("num1").field("type", "date").endObject().endObject()
                            .endObject().endObject()).execute().actionGet();
    client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForYellowStatus().execute().actionGet();

    client().index(
            indexRequest("test").type("type1").id("1")
                    .source(jsonBuilder().startObject().field("test", "value").field("num1", "2013-05-26").endObject())).actionGet();
    client().index(
            indexRequest("test").type("type1").id("2")
                    .source(jsonBuilder().startObject().field("test", "value").field("num1", "2013-05-27").endObject())).actionGet();

    client().admin().indices().prepareRefresh().execute().actionGet();
    DecayFunctionBuilder<?> gfb = new CustomDistanceScoreBuilder("num1", "2013-05-28", "+1d");

    ActionFuture<SearchResponse> response = client().search(searchRequest().searchType(SearchType.QUERY_THEN_FETCH).source(
            searchSource().explain(false).query(functionScoreQuery(termQuery("test", "value"), gfb))));

    SearchResponse sr = response.actionGet();
    ElasticsearchAssertions.assertNoFailures(sr);
    SearchHits sh = sr.getHits();

    assertThat(sh.getHits().length, equalTo(2));
    assertThat(sh.getAt(0).getId(), equalTo("1"));
    assertThat(sh.getAt(1).getId(), equalTo("2"));

}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:34,代码来源:FunctionScorePluginIT.java

示例7: testDistanceScoreGeoLinGaussExpWithOffset

import org.elasticsearch.action.ActionFuture; //导入方法依赖的package包/类
public void testDistanceScoreGeoLinGaussExpWithOffset() throws Exception {
    assertAcked(prepareCreate("test").addMapping(
            "type1",
            jsonBuilder().startObject().startObject("type1").startObject("properties").startObject("test").field("type", "text")
                    .endObject().startObject("num").field("type", "double").endObject().endObject().endObject().endObject()));

    // add tw docs within offset
    List<IndexRequestBuilder> indexBuilders = new ArrayList<>();
    indexBuilders.add(client().prepareIndex().setType("type1").setId("1").setIndex("test")
            .setSource(jsonBuilder().startObject().field("test", "value").field("num", 0.5).endObject()));
    indexBuilders.add(client().prepareIndex().setType("type1").setId("2").setIndex("test")
            .setSource(jsonBuilder().startObject().field("test", "value").field("num", 1.7).endObject()));

    // add docs outside offset
    int numDummyDocs = 20;
    for (int i = 0; i < numDummyDocs; i++) {
        indexBuilders.add(client().prepareIndex().setType("type1").setId(Integer.toString(i + 3)).setIndex("test")
                .setSource(jsonBuilder().startObject().field("test", "value").field("num", 3.0 + i).endObject()));
    }

    indexRandom(true, indexBuilders);

    // Test Gauss

    ActionFuture<SearchResponse> response = client().search(
            searchRequest().searchType(SearchType.QUERY_THEN_FETCH).source(
                    searchSource()
                            .size(numDummyDocs + 2)
                            .query(functionScoreQuery(termQuery("test", "value"), gaussDecayFunction("num", 1.0, 5.0, 1.0))
                                    .boostMode(CombineFunction.REPLACE))));
    SearchResponse sr = response.actionGet();
    SearchHits sh = sr.getHits();
    assertThat(sh.getTotalHits(), equalTo((long) (numDummyDocs + 2)));
    assertThat(sh.getAt(0).getId(), anyOf(equalTo("1"), equalTo("2")));
    assertThat(sh.getAt(1).getId(), anyOf(equalTo("1"), equalTo("2")));
    assertThat(sh.getAt(1).getScore(), equalTo(sh.getAt(0).getScore()));
    for (int i = 0; i < numDummyDocs; i++) {
        assertThat(sh.getAt(i + 2).getId(), equalTo(Integer.toString(i + 3)));
    }

    // Test Exp

    response = client().search(
            searchRequest().searchType(SearchType.QUERY_THEN_FETCH).source(
                    searchSource()
                            .size(numDummyDocs + 2)
                            .query(functionScoreQuery(termQuery("test", "value"),
                                    exponentialDecayFunction("num", 1.0, 5.0, 1.0)).boostMode(
                                    CombineFunction.REPLACE))));
    sr = response.actionGet();
    sh = sr.getHits();
    assertThat(sh.getTotalHits(), equalTo((long) (numDummyDocs + 2)));
    assertThat(sh.getAt(0).getId(), anyOf(equalTo("1"), equalTo("2")));
    assertThat(sh.getAt(1).getId(), anyOf(equalTo("1"), equalTo("2")));
    assertThat(sh.getAt(1).getScore(), equalTo(sh.getAt(0).getScore()));
    for (int i = 0; i < numDummyDocs; i++) {
        assertThat(sh.getAt(i + 2).getId(), equalTo(Integer.toString(i + 3)));
    }
    // Test Lin
    response = client().search(
            searchRequest().searchType(SearchType.QUERY_THEN_FETCH).source(
                    searchSource()
                            .size(numDummyDocs + 2)
                            .query(functionScoreQuery(termQuery("test", "value"), linearDecayFunction("num", 1.0, 20.0, 1.0))
                                    .boostMode(CombineFunction.REPLACE))));
    sr = response.actionGet();
    sh = sr.getHits();
    assertThat(sh.getTotalHits(), equalTo((long) (numDummyDocs + 2)));
    assertThat(sh.getAt(0).getId(), anyOf(equalTo("1"), equalTo("2")));
    assertThat(sh.getAt(1).getId(), anyOf(equalTo("1"), equalTo("2")));
    assertThat(sh.getAt(1).getScore(), equalTo(sh.getAt(0).getScore()));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:73,代码来源:DecayFunctionScoreIT.java

示例8: testBoostModeSettingWorks

import org.elasticsearch.action.ActionFuture; //导入方法依赖的package包/类
public void testBoostModeSettingWorks() throws Exception {
    Settings settings = Settings.builder().put(IndexMetaData.INDEX_NUMBER_OF_SHARDS_SETTING.getKey(), 1).build();
    assertAcked(prepareCreate("test").setSettings(settings)
        .addMapping(
            "type1",
            jsonBuilder()
                .startObject()
                    .startObject("type1")
                        .startObject("properties")
                            .startObject("test").field("type", "text").endObject()
                            .startObject("loc").field("type", "geo_point").endObject()
                        .endObject()
                    .endObject()
                .endObject()));

    List<IndexRequestBuilder> indexBuilders = new ArrayList<>();
    indexBuilders.add(client().prepareIndex()
            .setType("type1")
            .setId("1")
            .setIndex("test")
            .setSource(
                    jsonBuilder().startObject().field("test", "value").startObject("loc").field("lat", 11).field("lon", 21).endObject()
                            .endObject()));
    indexBuilders.add(client().prepareIndex()
            .setType("type1")
            .setId("2")
            .setIndex("test")
            .setSource(
                    jsonBuilder().startObject().field("test", "value value").startObject("loc").field("lat", 11).field("lon", 20)
                            .endObject().endObject()));
    indexRandom(true, false, indexBuilders); // force no dummy docs

    // Test Gauss
    List<Float> lonlat = new ArrayList<>();
    lonlat.add(20f);
    lonlat.add(11f);

    ActionFuture<SearchResponse> response = client().search(
            searchRequest().searchType(SearchType.QUERY_THEN_FETCH).source(
                    searchSource().query(
                            functionScoreQuery(termQuery("test", "value"), gaussDecayFunction("loc", lonlat, "1000km")).boostMode(
                                    CombineFunction.MULTIPLY))));
    SearchResponse sr = response.actionGet();
    SearchHits sh = sr.getHits();
    assertThat(sh.getTotalHits(), equalTo((long) (2)));
    assertThat(sh.getAt(0).getId(), isOneOf("1"));
    assertThat(sh.getAt(1).getId(), equalTo("2"));

    // Test Exp
    response = client().search(
            searchRequest().searchType(SearchType.QUERY_THEN_FETCH).source(
                    searchSource().query(
                            functionScoreQuery(termQuery("test", "value"), gaussDecayFunction("loc", lonlat, "1000km")).boostMode(
                                    CombineFunction.REPLACE))));
    sr = response.actionGet();
    sh = sr.getHits();
    assertThat(sh.getTotalHits(), equalTo((long) (2)));
    assertThat(sh.getAt(0).getId(), equalTo("2"));
    assertThat(sh.getAt(1).getId(), equalTo("1"));

}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:62,代码来源:DecayFunctionScoreIT.java

示例9: testParseGeoPoint

import org.elasticsearch.action.ActionFuture; //导入方法依赖的package包/类
public void testParseGeoPoint() throws Exception {
    assertAcked(prepareCreate("test").addMapping(
            "type1",
            jsonBuilder().startObject().startObject("type1").startObject("properties").startObject("test").field("type", "text")
                    .endObject().startObject("loc").field("type", "geo_point").endObject().endObject().endObject().endObject()));

    client().prepareIndex()
            .setType("type1")
            .setId("1")
            .setIndex("test")
            .setSource(
                    jsonBuilder().startObject()
                        .field("test", "value")
                        .startObject("loc")
                            .field("lat", 20)
                            .field("lon", 11)
                        .endObject()
                    .endObject()).setRefreshPolicy(IMMEDIATE).get();
    FunctionScoreQueryBuilder baseQuery = functionScoreQuery(constantScoreQuery(termQuery("test", "value")),
            ScoreFunctionBuilders.weightFactorFunction(randomIntBetween(1, 10)));
    GeoPoint point = new GeoPoint(20, 11);
    ActionFuture<SearchResponse> response = client().search(
            searchRequest().searchType(SearchType.QUERY_THEN_FETCH).source(
                    searchSource().query(
                            functionScoreQuery(baseQuery, gaussDecayFunction("loc", point, "1000km")).boostMode(
                                    CombineFunction.REPLACE))));
    SearchResponse sr = response.actionGet();
    SearchHits sh = sr.getHits();
    assertThat(sh.getTotalHits(), equalTo((long) (1)));
    assertThat(sh.getAt(0).getId(), equalTo("1"));
    assertThat((double) sh.getAt(0).getScore(), closeTo(1.0, 1.e-5));
    // this is equivalent to new GeoPoint(20, 11); just flipped so scores must be same
    float[] coords = { 11, 20 };
    response = client().search(
            searchRequest().searchType(SearchType.QUERY_THEN_FETCH).source(
                    searchSource().query(
                            functionScoreQuery(baseQuery, gaussDecayFunction("loc", coords, "1000km")).boostMode(
                                    CombineFunction.REPLACE))));
    sr = response.actionGet();
    sh = sr.getHits();
    assertThat(sh.getTotalHits(), equalTo((long) (1)));
    assertThat(sh.getAt(0).getId(), equalTo("1"));
    assertThat((double) sh.getAt(0).getScore(), closeTo(1.0f, 1.e-5));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:45,代码来源:DecayFunctionScoreIT.java

示例10: testCombineModes

import org.elasticsearch.action.ActionFuture; //导入方法依赖的package包/类
public void testCombineModes() throws Exception {
    assertAcked(prepareCreate("test").addMapping(
            "type1",
            jsonBuilder().startObject().startObject("type1").startObject("properties").startObject("test").field("type", "text")
                    .endObject().startObject("num").field("type", "double").endObject().endObject().endObject().endObject()));

    client().prepareIndex().setType("type1").setId("1").setIndex("test").setRefreshPolicy(IMMEDIATE)
            .setSource(jsonBuilder().startObject().field("test", "value value").field("num", 1.0).endObject()).get();
    FunctionScoreQueryBuilder baseQuery = functionScoreQuery(constantScoreQuery(termQuery("test", "value")),
            ScoreFunctionBuilders.weightFactorFunction(2));
    // decay score should return 0.5 for this function and baseQuery should return 2.0f as it's score
    ActionFuture<SearchResponse> response = client().search(
            searchRequest().searchType(SearchType.QUERY_THEN_FETCH).source(
                    searchSource().query(
                            functionScoreQuery(baseQuery, gaussDecayFunction("num", 0.0, 1.0, null, 0.5))
                                .boostMode(CombineFunction.MULTIPLY))));
    SearchResponse sr = response.actionGet();
    SearchHits sh = sr.getHits();
    assertThat(sh.getTotalHits(), equalTo((long) (1)));
    assertThat(sh.getAt(0).getId(), equalTo("1"));
    assertThat((double) sh.getAt(0).getScore(), closeTo(1.0, 1.e-5));

    response = client().search(
            searchRequest().searchType(SearchType.QUERY_THEN_FETCH).source(
                    searchSource().query(
                            functionScoreQuery(baseQuery, gaussDecayFunction("num", 0.0, 1.0, null, 0.5))
                                .boostMode(CombineFunction.REPLACE))));
    sr = response.actionGet();
    sh = sr.getHits();
    assertThat(sh.getTotalHits(), equalTo((long) (1)));
    assertThat(sh.getAt(0).getId(), equalTo("1"));
    assertThat((double) sh.getAt(0).getScore(), closeTo(0.5, 1.e-5));

    response = client().search(
            searchRequest().searchType(SearchType.QUERY_THEN_FETCH).source(
                    searchSource().query(
                            functionScoreQuery(baseQuery, gaussDecayFunction("num", 0.0, 1.0, null, 0.5))
                                .boostMode(CombineFunction.SUM))));
    sr = response.actionGet();
    sh = sr.getHits();
    assertThat(sh.getTotalHits(), equalTo((long) (1)));
    assertThat(sh.getAt(0).getId(), equalTo("1"));
    assertThat((double) sh.getAt(0).getScore(), closeTo(2.0 + 0.5, 1.e-5));
    logger.info("--> Hit[0] {} Explanation:\n {}", sr.getHits().getAt(0).getId(), sr.getHits().getAt(0).getExplanation());

    response = client().search(
            searchRequest().searchType(SearchType.QUERY_THEN_FETCH).source(
                    searchSource().query(
                            functionScoreQuery(baseQuery, gaussDecayFunction("num", 0.0, 1.0, null, 0.5))
                                .boostMode(CombineFunction.AVG))));
    sr = response.actionGet();
    sh = sr.getHits();
    assertThat(sh.getTotalHits(), equalTo((long) (1)));
    assertThat(sh.getAt(0).getId(), equalTo("1"));
    assertThat((double) sh.getAt(0).getScore(), closeTo((2.0 + 0.5) / 2, 1.e-5));

    response = client().search(
            searchRequest().searchType(SearchType.QUERY_THEN_FETCH).source(
                    searchSource().query(
                            functionScoreQuery(baseQuery, gaussDecayFunction("num", 0.0, 1.0, null, 0.5))
                                .boostMode(CombineFunction.MIN))));
    sr = response.actionGet();
    sh = sr.getHits();
    assertThat(sh.getTotalHits(), equalTo((long) (1)));
    assertThat(sh.getAt(0).getId(), equalTo("1"));
    assertThat((double) sh.getAt(0).getScore(), closeTo(0.5, 1.e-5));

    response = client().search(
            searchRequest().searchType(SearchType.QUERY_THEN_FETCH).source(
                    searchSource().query(
                            functionScoreQuery(baseQuery, gaussDecayFunction("num", 0.0, 1.0, null, 0.5))
                                .boostMode(CombineFunction.MAX))));
    sr = response.actionGet();
    sh = sr.getHits();
    assertThat(sh.getTotalHits(), equalTo((long) (1)));
    assertThat(sh.getAt(0).getId(), equalTo("1"));
    assertThat((double) sh.getAt(0).getScore(), closeTo(2.0, 1.e-5));

}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:80,代码来源:DecayFunctionScoreIT.java

示例11: testValueMissingLin

import org.elasticsearch.action.ActionFuture; //导入方法依赖的package包/类
public void testValueMissingLin() throws Exception {
    assertAcked(prepareCreate("test").addMapping(
            "type1",
            jsonBuilder().startObject().startObject("type1").startObject("properties").startObject("test").field("type", "text")
                    .endObject().startObject("num1").field("type", "date").endObject().startObject("num2").field("type", "double")
                    .endObject().endObject().endObject().endObject())
    );


    client().index(
            indexRequest("test").type("type1").id("1")
                    .source(jsonBuilder().startObject().field("test", "value").field("num1", "2013-05-27").field("num2", "1.0")
                            .endObject())).actionGet();
    client().index(
            indexRequest("test").type("type1").id("2")
                    .source(jsonBuilder().startObject().field("test", "value").field("num2", "1.0").endObject())).actionGet();
    client().index(
            indexRequest("test").type("type1").id("3")
                    .source(jsonBuilder().startObject().field("test", "value").field("num1", "2013-05-30").field("num2", "1.0")
                            .endObject())).actionGet();
    client().index(
            indexRequest("test").type("type1").id("4")
                    .source(jsonBuilder().startObject().field("test", "value").field("num1", "2013-05-30").endObject())).actionGet();

    refresh();

    ActionFuture<SearchResponse> response = client().search(
            searchRequest().searchType(SearchType.QUERY_THEN_FETCH).source(
                    searchSource().query(
                            functionScoreQuery(baseQuery, new FilterFunctionBuilder[]{
                                    new FilterFunctionBuilder(linearDecayFunction("num1", "2013-05-28", "+3d")),
                                    new FilterFunctionBuilder(linearDecayFunction("num2", "0.0", "1"))
                            }).scoreMode(FiltersFunctionScoreQuery.ScoreMode.MULTIPLY))));

    SearchResponse sr = response.actionGet();

    assertNoFailures(sr);
    SearchHits sh = sr.getHits();
    assertThat(sh.getHits().length, equalTo(4));
    double[] scores = new double[4];
    for (int i = 0; i < sh.getHits().length; i++) {
        scores[Integer.parseInt(sh.getAt(i).getId()) - 1] = sh.getAt(i).getScore();
    }
    assertThat(scores[0], lessThan(scores[1]));
    assertThat(scores[2], lessThan(scores[3]));

}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:48,代码来源:DecayFunctionScoreIT.java

示例12: testDateWithoutOrigin

import org.elasticsearch.action.ActionFuture; //导入方法依赖的package包/类
public void testDateWithoutOrigin() throws Exception {
    DateTime dt = new DateTime(DateTimeZone.UTC);

    assertAcked(prepareCreate("test").addMapping(
            "type1",
            jsonBuilder().startObject().startObject("type1").startObject("properties").startObject("test").field("type", "text")
                    .endObject().startObject("num1").field("type", "date").endObject().endObject().endObject().endObject()));

    DateTime docDate = dt.minusDays(1);
    String docDateString = docDate.getYear() + "-" + String.format(Locale.ROOT, "%02d", docDate.getMonthOfYear()) + "-"
            + String.format(Locale.ROOT, "%02d", docDate.getDayOfMonth());
    client().index(
            indexRequest("test").type("type1").id("1")
                    .source(jsonBuilder().startObject().field("test", "value").field("num1", docDateString).endObject())).actionGet();
    docDate = dt.minusDays(2);
    docDateString = docDate.getYear() + "-" + String.format(Locale.ROOT, "%02d", docDate.getMonthOfYear()) + "-"
            + String.format(Locale.ROOT, "%02d", docDate.getDayOfMonth());
    client().index(
            indexRequest("test").type("type1").id("2")
                    .source(jsonBuilder().startObject().field("test", "value").field("num1", docDateString).endObject())).actionGet();
    docDate = dt.minusDays(3);
    docDateString = docDate.getYear() + "-" + String.format(Locale.ROOT, "%02d", docDate.getMonthOfYear()) + "-"
            + String.format(Locale.ROOT, "%02d", docDate.getDayOfMonth());
    client().index(
            indexRequest("test").type("type1").id("3")
                    .source(jsonBuilder().startObject().field("test", "value").field("num1", docDateString).endObject())).actionGet();

    refresh();

    ActionFuture<SearchResponse> response = client().search(
            searchRequest().searchType(SearchType.QUERY_THEN_FETCH).source(
                    searchSource().query(
                            functionScoreQuery(QueryBuilders.matchAllQuery(), new FilterFunctionBuilder[]{
                                    new FilterFunctionBuilder(linearDecayFunction("num1", null, "7000d")),
                                    new FilterFunctionBuilder(gaussDecayFunction("num1", null, "1d")),
                                    new FilterFunctionBuilder(exponentialDecayFunction("num1", null, "7000d"))
                            }).scoreMode(FiltersFunctionScoreQuery.ScoreMode.MULTIPLY))));

    SearchResponse sr = response.actionGet();
    assertNoFailures(sr);
    SearchHits sh = sr.getHits();
    assertThat(sh.getHits().length, equalTo(3));
    double[] scores = new double[4];
    for (int i = 0; i < sh.getHits().length; i++) {
        scores[Integer.parseInt(sh.getAt(i).getId()) - 1] = sh.getAt(i).getScore();
    }
    assertThat(scores[1], lessThan(scores[0]));
    assertThat(scores[2], lessThan(scores[1]));

}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:51,代码来源:DecayFunctionScoreIT.java

示例13: testManyDocsLin

import org.elasticsearch.action.ActionFuture; //导入方法依赖的package包/类
public void testManyDocsLin() throws Exception {
    Version version = VersionUtils.randomVersionBetween(random(), Version.V_5_0_0, Version.CURRENT);
    Settings settings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, version).build();
    XContentBuilder xContentBuilder = jsonBuilder().startObject().startObject("type").startObject("properties")
            .startObject("test").field("type", "text").endObject().startObject("date").field("type", "date")
            .field("doc_values", true).endObject().startObject("num").field("type", "double")
            .field("doc_values", true).endObject().startObject("geo").field("type", "geo_point")
            .field("ignore_malformed", true);
    xContentBuilder.endObject().endObject().endObject().endObject();
    assertAcked(prepareCreate("test").setSettings(settings).addMapping("type", xContentBuilder));
    int numDocs = 200;
    List<IndexRequestBuilder> indexBuilders = new ArrayList<>();

    for (int i = 0; i < numDocs; i++) {
        double lat = 100 + (int) (10.0 * (i) / (numDocs));
        double lon = 100;
        int day = (int) (29.0 * (i) / (numDocs)) + 1;
        String dayString = day < 10 ? "0" + Integer.toString(day) : Integer.toString(day);
        String date = "2013-05-" + dayString;

        indexBuilders.add(client().prepareIndex()
                .setType("type")
                .setId(Integer.toString(i))
                .setIndex("test")
                .setSource(
                        jsonBuilder().startObject().field("test", "value").field("date", date).field("num", i).startObject("geo")
                                .field("lat", lat).field("lon", lon).endObject().endObject()));
    }
    indexRandom(true, indexBuilders);
    List<Float> lonlat = new ArrayList<>();
    lonlat.add(100f);
    lonlat.add(110f);
    ActionFuture<SearchResponse> response = client().search(
            searchRequest().searchType(SearchType.QUERY_THEN_FETCH).source(
                    searchSource().size(numDocs).query(
                            functionScoreQuery(termQuery("test", "value"), new FilterFunctionBuilder[]{
                                    new FilterFunctionBuilder(linearDecayFunction("date", "2013-05-30", "+15d")),
                                    new FilterFunctionBuilder(linearDecayFunction("geo", lonlat, "1000km")),
                                    new FilterFunctionBuilder(linearDecayFunction("num", numDocs, numDocs / 2.0))
                            }).scoreMode(ScoreMode.MULTIPLY).boostMode(CombineFunction.REPLACE))));

    SearchResponse sr = response.actionGet();
    assertNoFailures(sr);
    SearchHits sh = sr.getHits();
    assertThat(sh.getHits().length, equalTo(numDocs));
    double[] scores = new double[numDocs];
    for (int i = 0; i < numDocs; i++) {
        scores[Integer.parseInt(sh.getAt(i).getId())] = sh.getAt(i).getScore();
    }
    for (int i = 0; i < numDocs - 1; i++) {
        assertThat(scores[i], lessThan(scores[i + 1]));
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:54,代码来源:DecayFunctionScoreIT.java

示例14: run

import org.elasticsearch.action.ActionFuture; //导入方法依赖的package包/类
@Override
public void run() {
    try {
        if (isPrimaryInRouting) {
            ActionFuture<IndexShardStatsResponse>  result = indexShardStatsAction.execute(new IndexShardStatsRequest(shardId.index().getName(), shardId.id()));
            IndexShardStatsResponse response = result.actionGet(10000);
            if (response.getTotalShards() == response.getSuccessfulShards() && response.getTotalShards() > 0) {
                DLSN miniumDlsn = new DLSN(Long.MAX_VALUE, 0, 0);
                boolean hasInvalidShardStats = false;
                for (ShardStats shardStats : response.getShards()) {
                    boolean isInvalid = true;
                    CommonStats commonStats = shardStats.getStats();
                    if (commonStats != null) {
                        DLStats dlStats = commonStats.getDLStats();
                        if (dlStats != null && !dlStats.getCommitDlsn().equals(DLSN.InvalidDLSN)) {
                            isInvalid = false;
                            if (dlStats.getCommitDlsn().compareTo(miniumDlsn) < 0) {
                                miniumDlsn = dlStats.getCommitDlsn();
                            }
                        } else {
                            logger.debug("dl [{}] status is invalid", dlStats);
                        }
                    } else {
                        logger.debug("common stats is null");
                    }
                    if (isInvalid) {
                        hasInvalidShardStats = true;
                        break;
                    }
                }
                if (!hasInvalidShardStats) {
                    if (!miniumDlsn.equals(DLSN.InitialDLSN)) {
                        logger.info("try to truncate log before [{}]", miniumDlsn);
                        dlTranslog.truncateLogBeforeDLSN(miniumDlsn);
                    }
                }
            } else {
                logger.warn("some shards failed to get stats: total shards [{}], shards give reponse [{}], failure exceptions [{}], maybe some shard is abnormal so skip truncate log", 
                        response.getTotalShards(), 
                        response.getSuccessfulShards(),
                        response.getShardFailures().length > 0 ? response.getShardFailures()[0] : "");
            }
        }
    } catch (Throwable t) {
        logger.error("catch exception when sleep to next lease check time", t);
    } finally {
        if (!isClosed.get()) {
            // check in 1 minutes
            threadPool.schedule(TimeValue.timeValueMinutes(1), ThreadPool.Names.GENERIC, this);
        }
    }
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:53,代码来源:DLBasedEngine.java


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