0

我正在使用 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();
4

1 回答 1

1

如果您拆分匹配查询以匹配单个字段,例如使用多重匹配查询(https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-multi-match-query. html),你可以提升你喜欢的领域。所以像:

QueryBuilder qb = new BoolQueryBuilder()
    .must(QueryBuilders.multiMatchQuery(term, "firstName^3",
    "lastName^3", "note")
            .analyzer("atsCustomSearchAnalyzer")
            .operator(Operator.AND));

应该将 firstName 和 lastName 相对于 note 字段提升 3 倍。

于 2017-01-31T15:13:55.560 回答