本文整理汇总了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));
}
示例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();
}