本文整理匯總了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();
}