Java Code Examples for org.elasticsearch.index.query.MultiMatchQueryBuilder#boost()
The following examples show how to use
org.elasticsearch.index.query.MultiMatchQueryBuilder#boost() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MultiMatchQueryDemo.java From elasticsearch-full with Apache License 2.0 | 5 votes |
@Test public void testForClient() throws Exception { /** * @see <a href='https://www.elastic.co/guide/en/elasticsearch/reference/5.6/query-dsl-multi-match-query.html'></a> * MultiMatchQuery依赖于match query ,也就是其核心是基于MatchQuery构建的 * */ MultiMatchQueryBuilder multiMatchQueryBuilder = QueryBuilders.multiMatchQuery("elasticsearch match query","title", "descrption"); multiMatchQueryBuilder.analyzer("standard"); multiMatchQueryBuilder.cutoffFrequency(0.001f); multiMatchQueryBuilder.field("title",20); multiMatchQueryBuilder.fuzziness(Fuzziness.TWO); multiMatchQueryBuilder.maxExpansions(100); multiMatchQueryBuilder.prefixLength(10); multiMatchQueryBuilder.tieBreaker(20); multiMatchQueryBuilder.type(MultiMatchQueryBuilder.Type.BEST_FIELDS); multiMatchQueryBuilder.boost(20); SearchResponse searchResponse = client.prepareSearch() .setIndices("blogs") .setTypes("blog") .setQuery(multiMatchQueryBuilder) .execute() .actionGet(); }
Example 2
Source File: Paramer.java From elasticsearch-sql with Apache License 2.0 | 5 votes |
public static ToXContent fullParamer(MultiMatchQueryBuilder query, Paramer paramer) { if (paramer.analysis != null) { query.analyzer(paramer.analysis); } if (paramer.boost != null) { query.boost(paramer.boost); } if (paramer.slop != null) { query.slop(paramer.slop); } if (paramer.type != null) { query.type(paramer.type); } if (paramer.tieBreaker != null) { query.tieBreaker(paramer.tieBreaker); } if (paramer.operator != null) { query.operator(paramer.operator); } if (paramer.minimumShouldMatch != null) { query.minimumShouldMatch(paramer.minimumShouldMatch); } query.fields(paramer.fieldsBoosts); return query; }
Example 3
Source File: IndexSearchDaoImpl.java From herd with Apache License 2.0 | 4 votes |
/** * Private method to build a multi match query. * * @param searchTerm the term on which to search * @param queryType the query type for this multi match query * @param queryBoost the query boost for this multi match query * @param fieldType the field type for this multi match query * @param match the set of match fields that are to be searched upon in the index search * * @return the multi match query */ private MultiMatchQueryBuilder buildMultiMatchQuery(final String searchTerm, final MultiMatchQueryBuilder.Type queryType, final float queryBoost, final String fieldType, Set<String> match) { // Get the slop value for this multi match query Integer phraseQuerySlop = configurationHelper.getProperty(ConfigurationValue.ELASTICSEARCH_PHRASE_QUERY_SLOP, Integer.class); MultiMatchQueryBuilder multiMatchQueryBuilder = QueryBuilders.multiMatchQuery(searchTerm).type(queryType); multiMatchQueryBuilder.boost(queryBoost); if (fieldType.equals(FIELD_TYPE_STEMMED)) { // Get the configured value for 'stemmed' fields and their respective boosts if any String stemmedFieldsValue = configurationHelper.getProperty(ConfigurationValue.ELASTICSEARCH_SEARCHABLE_FIELDS_STEMMED); // build the query buildMultiMatchQueryWithBoosts(multiMatchQueryBuilder, stemmedFieldsValue, match); if (queryType.equals(PHRASE)) { // Set a "slop" value to allow the matched phrase to be slightly different from an exact phrase match // The slop parameter tells the match phrase query how far apart terms are allowed to be while still considering the document a match multiMatchQueryBuilder.slop(phraseQuerySlop); } } if (fieldType.equals(FIELD_TYPE_NGRAMS)) { // Get the configured value for 'ngrams' fields and their respective boosts if any String ngramsFieldsValue = configurationHelper.getProperty(ConfigurationValue.ELASTICSEARCH_SEARCHABLE_FIELDS_NGRAMS); // build the query buildMultiMatchQueryWithBoosts(multiMatchQueryBuilder, ngramsFieldsValue, match); } if (fieldType.equals(FIELD_TYPE_SHINGLES)) { // Set a "slop" value to allow the matched phrase to be slightly different from an exact phrase match // The slop parameter tells the match phrase query how far apart terms are allowed to be while still considering the document a match multiMatchQueryBuilder.slop(phraseQuerySlop); // Get the configured value for 'shingles' fields and their respective boosts if any String shinglesFieldsValue = configurationHelper.getProperty(ConfigurationValue.ELASTICSEARCH_SEARCHABLE_FIELDS_SHINGLES); // build the query buildMultiMatchQueryWithBoosts(multiMatchQueryBuilder, shinglesFieldsValue, match); } return multiMatchQueryBuilder; }