Java Code Examples for org.elasticsearch.action.search.SearchRequestBuilder#setMinScore()

The following examples show how to use org.elasticsearch.action.search.SearchRequestBuilder#setMinScore() . 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: QueryAction.java    From elasticsearch-sql with Apache License 2.0 5 votes vote down vote up
protected void updateRequestWithMinScore(Select select, SearchRequestBuilder request) {
    for (Hint hint : select.getHints()) {
        if (hint.getType() == HintType.MIN_SCORE && hint.getParams() != null && 0 < hint.getParams().length) {
            String param = hint.getParams()[0].toString();
            request.setMinScore(Float.parseFloat(param));
        }
    }
}
 
Example 2
Source File: EsAbstractConditionBean.java    From fess with Apache License 2.0 5 votes vote down vote up
public void build(SearchRequestBuilder builder) {
    if (explain != null) {
        builder.setExplain(explain);
    }
    if (minScore != null) {
        builder.setMinScore(minScore);
    }
    if (preference != null) {
        builder.setPreference(preference);
    }
    if (routing != null) {
        builder.setRouting(routing);
    }
    if (searchType != null) {
        builder.setSearchType(searchType);
    }
    if (timeoutInMillis != -1) {
        builder.setTimeout(new TimeValue(timeoutInMillis));
    }
    if (version != null) {
        builder.setVersion(version);
    }
    if (seqNoAndPrimaryTerm != null) {
        builder.seqNoAndPrimaryTerm(seqNoAndPrimaryTerm);
    }
    if (terminateAfter > 0) {
        builder.setTerminateAfter(terminateAfter);
    }
}
 
Example 3
Source File: EsAbstractConditionBean.java    From fess with Apache License 2.0 5 votes vote down vote up
public void build(SearchRequestBuilder builder) {
    if (explain != null) {
        builder.setExplain(explain);
    }
    if (minScore != null) {
        builder.setMinScore(minScore);
    }
    if (preference != null) {
        builder.setPreference(preference);
    }
    if (routing != null) {
        builder.setRouting(routing);
    }
    if (searchType != null) {
        builder.setSearchType(searchType);
    }
    if (timeoutInMillis != -1) {
        builder.setTimeout(new TimeValue(timeoutInMillis));
    }
    if (version != null) {
        builder.setVersion(version);
    }
    if (seqNoAndPrimaryTerm != null) {
        builder.seqNoAndPrimaryTerm(seqNoAndPrimaryTerm);
    }
    if (terminateAfter > 0) {
        builder.setTerminateAfter(terminateAfter);
    }
}
 
Example 4
Source File: EsAbstractConditionBean.java    From fess with Apache License 2.0 5 votes vote down vote up
public void build(SearchRequestBuilder builder) {
    if (explain != null) {
        builder.setExplain(explain);
    }
    if (minScore != null) {
        builder.setMinScore(minScore);
    }
    if (preference != null) {
        builder.setPreference(preference);
    }
    if (routing != null) {
        builder.setRouting(routing);
    }
    if (searchType != null) {
        builder.setSearchType(searchType);
    }
    if (timeoutInMillis != -1) {
        builder.setTimeout(new TimeValue(timeoutInMillis));
    }
    if (version != null) {
        builder.setVersion(version);
    }
    if (seqNoAndPrimaryTerm != null) {
        builder.seqNoAndPrimaryTerm(seqNoAndPrimaryTerm);
    }
    if (terminateAfter > 0) {
        builder.setTerminateAfter(terminateAfter);
    }
}
 
Example 5
Source File: ElasticsearchSearchQueryBase.java    From vertexium with Apache License 2.0 4 votes vote down vote up
private SearchRequestBuilder buildQuery(EnumSet<ElasticsearchDocumentType> elementType, FetchHints fetchHints, boolean includeAggregations) {
    if (QUERY_LOGGER.isTraceEnabled()) {
        QUERY_LOGGER.trace("searching for: " + toString());
    }
    List<QueryBuilder> filters = getFilters(elementType, fetchHints);
    QueryBuilder query = createQuery(getParameters());

    QueryBuilder filterBuilder = getFilterBuilder(filters, fetchHints);
    String[] indicesToQuery = getIndexSelectionStrategy().getIndicesToQuery(this, elementType);
    if (QUERY_LOGGER.isTraceEnabled()) {
        QUERY_LOGGER.trace("indicesToQuery: %s", Joiner.on(", ").join(indicesToQuery));
    }
    if (getSearchIndex().shouldRefreshIndexOnQuery()) {
        getSearchIndex().getIndexRefreshTracker().refresh(client, indicesToQuery);
    }

    SearchRequestBuilder searchRequestBuilder = getClient()
        .prepareSearch(indicesToQuery)
        .setQuery(QueryBuilders.boolQuery().must(query).filter(filterBuilder))
        .storedFields(
            Elasticsearch7SearchIndex.ELEMENT_ID_FIELD_NAME,
            Elasticsearch7SearchIndex.ELEMENT_TYPE_FIELD_NAME,
            Elasticsearch7SearchIndex.EXTENDED_DATA_TABLE_NAME_FIELD_NAME,
            Elasticsearch7SearchIndex.EXTENDED_DATA_TABLE_ROW_ID_FIELD_NAME
        );
    if (fetchHints.equals(FetchHints.NONE)) {
        searchRequestBuilder.storedFields(
            Elasticsearch7SearchIndex.OUT_VERTEX_ID_FIELD_NAME,
            Elasticsearch7SearchIndex.IN_VERTEX_ID_FIELD_NAME,
            Elasticsearch7SearchIndex.EDGE_LABEL_FIELD_NAME
        );
    }
    if (getParameters().getMinScore() != null) {
        searchRequestBuilder.setMinScore(getParameters().getMinScore().floatValue());
    }
    if (includeAggregations) {
        List<AggregationBuilder> aggs = getElasticsearchAggregations(getAggregations());
        for (AggregationBuilder aggregationBuilder : aggs) {
            searchRequestBuilder.addAggregation(aggregationBuilder);
        }
    }

    applySort(searchRequestBuilder);

    return searchRequestBuilder;
}
 
Example 6
Source File: ElasticsearchSearchQueryBase.java    From vertexium with Apache License 2.0 4 votes vote down vote up
private SearchRequestBuilder buildQuery(EnumSet<ElasticsearchDocumentType> elementType, FetchHints fetchHints, boolean includeAggregations) {
    if (QUERY_LOGGER.isTraceEnabled()) {
        QUERY_LOGGER.trace("searching for: " + toString());
    }
    List<QueryBuilder> filters = getFilters(elementType, fetchHints);
    QueryBuilder query = createQuery(getParameters());

    QueryBuilder filterBuilder = getFilterBuilder(filters, fetchHints);
    String[] indicesToQuery = getIndexSelectionStrategy().getIndicesToQuery(this, elementType);
    if (QUERY_LOGGER.isTraceEnabled()) {
        QUERY_LOGGER.trace("indicesToQuery: %s", Joiner.on(", ").join(indicesToQuery));
    }
    if (getSearchIndex().shouldRefreshIndexOnQuery()) {
        getSearchIndex().getIndexRefreshTracker().refresh(client, indicesToQuery);
    }

    SearchRequestBuilder searchRequestBuilder = getClient()
        .prepareSearch(indicesToQuery)
        .setTypes(getSearchIndex().getIdStrategy().getType())
        .setQuery(QueryBuilders.boolQuery().must(query).filter(filterBuilder))
        .storedFields(
            Elasticsearch5SearchIndex.ELEMENT_ID_FIELD_NAME,
            Elasticsearch5SearchIndex.ELEMENT_TYPE_FIELD_NAME,
            Elasticsearch5SearchIndex.EXTENDED_DATA_TABLE_NAME_FIELD_NAME,
            Elasticsearch5SearchIndex.EXTENDED_DATA_TABLE_ROW_ID_FIELD_NAME
        );
    if (fetchHints.equals(FetchHints.NONE)) {
        searchRequestBuilder.storedFields(
            Elasticsearch5SearchIndex.OUT_VERTEX_ID_FIELD_NAME,
            Elasticsearch5SearchIndex.IN_VERTEX_ID_FIELD_NAME,
            Elasticsearch5SearchIndex.EDGE_LABEL_FIELD_NAME
        );
    }
    if (getParameters().getMinScore() != null) {
        searchRequestBuilder.setMinScore(getParameters().getMinScore().floatValue());
    }
    if (includeAggregations) {
        List<AggregationBuilder> aggs = getElasticsearchAggregations(getAggregations());
        for (AggregationBuilder aggregationBuilder : aggs) {
            searchRequestBuilder.addAggregation(aggregationBuilder);
        }
    }

    applySort(searchRequestBuilder);

    return searchRequestBuilder;
}