Elasticsearch Query:提升特定字段

时间:2017-01-31 12:50:45

标签: elasticsearch field boosting

我正在使用Elasticsearch 2.4.3并希望在我的查询中增加特定字段。这可能吗?我只看到如何提升指数。

问候!

更新

映射:

"firstName":{"type":"string",
     "analyzer":"customNGram"
},
"lastName":{
     "type":"string",
     "analyzer":"customNGram"
},
"note":{
     "type":"string",
     "analyzer":"customNGram"
}

查询(Java API):

    QueryBuilder qb = new BoolQueryBuilder()
        .must(QueryBuilders.matchQuery("_all", term)
                .analyzer("atsCustomSearchAnalyzer")
                .operator(Operator.AND));

    SearchRequestBuilder searchRequestBuilder = elasticsearchClient.prepareSearch("persons", "activities").setTypes("person", "activity")
            .setQuery(qb)
            .addHighlightedField("*").setHighlighterRequireFieldMatch(false)
            .setHighlighterOrder("score")
            .setHighlighterFragmentSize(150)
            .setHighlighterForceSource(true)
            .setSize(100)
            .addIndexBoost("persons", 200)
            .setFrom(offset); 

    return searchRequestBuilder.execute().get();

1 个答案:

答案 0 :(得分:1)

如果您将匹配查询拆分为匹配单个字段,例如使用多匹配查询(https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-multi-match-query.html),则可以增加您喜欢的字段。如下所示:

@Override
public void onConnected(Bundle bundle) {
    Log.i(MainActivity.class.getSimpleName(), "Connected to Google Play Services!");

    if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION)
            == PackageManager.PERMISSION_GRANTED) {
        Location lastLocation = LocationServices.FusedLocationApi.getLastLocation(googleApiClient);

        lat = lastLocation.getLatitude();
        lon = lastLocation.getLongitude();
        txtLat = (TextView) findViewById(R.id.textView1);
        txtLat.setText(lat + " " + lon);
    }

}

应相对于note字段提升firstName和lastName 3次。