當前位置: 首頁>>代碼示例>>Java>>正文


Java QueryBuilders.functionScoreQuery方法代碼示例

本文整理匯總了Java中org.elasticsearch.index.query.QueryBuilders.functionScoreQuery方法的典型用法代碼示例。如果您正苦於以下問題:Java QueryBuilders.functionScoreQuery方法的具體用法?Java QueryBuilders.functionScoreQuery怎麽用?Java QueryBuilders.functionScoreQuery使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.elasticsearch.index.query.QueryBuilders的用法示例。


在下文中一共展示了QueryBuilders.functionScoreQuery方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testGeoFieldHighlightingWhenQueryGetsRewritten

import org.elasticsearch.index.query.QueryBuilders; //導入方法依賴的package包/類
public void testGeoFieldHighlightingWhenQueryGetsRewritten() throws IOException {
    // same as above but in this example the query gets rewritten during highlighting
    // see https://github.com/elastic/elasticsearch/issues/17537#issuecomment-244939633
    XContentBuilder mappings = jsonBuilder();
    mappings.startObject();
    mappings.startObject("jobs")
        .startObject("properties")
        .startObject("loc")
        .field("type", "geo_point")
        .endObject()
        .startObject("jd")
        .field("type", "text")
        .endObject()
        .endObject()
        .endObject();
    mappings.endObject();
    assertAcked(prepareCreate("test")
        .addMapping("jobs", mappings));
    ensureYellow();

    client().prepareIndex("test", "jobs", "1")
        .setSource(jsonBuilder().startObject().field("jd", "some आवश्यकता है- आर्य समाज अनाथालय, 68 सिविल लाइन्स, बरेली को एक पुरूष" +
            " रस text")
            .field("loc", "12.934059,77.610741").endObject())
        .get();
    refresh();

    QueryBuilder query = QueryBuilders.functionScoreQuery(QueryBuilders.boolQuery().filter(QueryBuilders.geoBoundingBoxQuery("loc")
        .setCorners(new GeoPoint(48.934059, 41.610741), new GeoPoint(-23.065941, 113.610741))));
    SearchResponse search = client().prepareSearch().setSource(
        new SearchSourceBuilder().query(query).highlighter(new HighlightBuilder().highlighterType("plain").field("jd"))).get();
    assertNoFailures(search);
    assertThat(search.getHits().getTotalHits(), equalTo(1L));
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:35,代碼來源:HighlighterSearchIT.java

示例2: testForClient

import org.elasticsearch.index.query.QueryBuilders; //導入方法依賴的package包/類
@Test
public void testForClient() throws Exception {
    FunctionScoreQueryBuilder.FilterFunctionBuilder[] functions = {
            new FunctionScoreQueryBuilder.FilterFunctionBuilder(
                    QueryBuilders.matchQuery("name", "kimchy"),
                    ScoreFunctionBuilders. randomFunction("ABCDEF")),
            new FunctionScoreQueryBuilder.FilterFunctionBuilder(
                    ScoreFunctionBuilders.exponentialDecayFunction("age", 0L, 1L))
    };
    QueryBuilder qb = QueryBuilders.functionScoreQuery(functions);
    client.prepareSearch().setQuery(qb).execute().actionGet();
}
 
開發者ID:felayman,項目名稱:elasticsearch-full,代碼行數:13,代碼來源:FunctionScoreQueryDemo.java


注:本文中的org.elasticsearch.index.query.QueryBuilders.functionScoreQuery方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。