当前位置: 首页>>代码示例>>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;未经允许,请勿转载。