Examples of SearchRequestBuilder


Examples of org.elasticsearch.action.search.SearchRequestBuilder

            queryBuilder = QueryBuilders.matchAllQuery();
        } else {
            queryBuilder = QueryBuilders.queryString(query);
        }

        SearchRequestBuilder srb = client.prepareSearch(srcGraph.getIndexName())
                .setTypes("vertex")
                .setQuery(queryBuilder)
                .setSize(SIZE)
                .setSearchType(SearchType.SCAN)
                .setScroll(new TimeValue(60000));
View Full Code Here

Examples of org.elasticsearch.action.search.SearchRequestBuilder

    String indexName = jiraIssueIndexStructureBuilder.getIssuesSearchIndexName(projectKey);
    esIntegrationComponent.refreshSearchIndex(indexName);

    logger.debug("go to delete indexed issues for project {} not updated after {}", projectKey, boundDate);
    SearchRequestBuilder srb = esIntegrationComponent.prepareESScrollSearchRequestBuilder(indexName);
    jiraIssueIndexStructureBuilder.buildSearchForIndexedDocumentsNotUpdatedAfter(srb, projectKey, boundDate);

    SearchResponse scrollResp = esIntegrationComponent.executeESSearchRequest(srb);

    if (scrollResp.getHits().getTotalHits() > 0) {
View Full Code Here

Examples of org.elasticsearch.action.search.SearchRequestBuilder

                                                       Integer firstResult, Integer maxResults,
                                                       Map<String, Object> variables )
            throws EntityFinderException
        {
            // Prepare request
            SearchRequestBuilder request = support.client().prepareSearch( support.index() );

            AndFilterBuilder filterBuilder = baseFilters( resultType );
            QueryBuilder queryBuilder = processWhereSpecification( filterBuilder, whereClause, variables );

            request.setQuery( filteredQuery( queryBuilder, filterBuilder ) );
            if( firstResult != null )
            {
                request.setFrom( firstResult );
            }
            if( maxResults != null )
            {
                request.setSize( maxResults );
            }
            else
            {
                //request.setSize( Integer.MAX_VALUE ); // TODO Use scrolls?
            }
            if( orderBySegments != null )
            {
                for( OrderBy order : orderBySegments )
                {
                    request.addSort( order.property().toString(),
                                     order.order() == OrderBy.Order.ASCENDING ? SortOrder.ASC : SortOrder.DESC );
                }
            }

            // Log
            LOGGER.debug( "Will search Entities: {}", request );

            // Execute
            SearchResponse response = request.execute().actionGet();

            return Iterables.map( new Function<SearchHit, EntityReference>()
            {
                @Override
                public EntityReference map( SearchHit from )
View Full Code Here

Examples of org.elasticsearch.action.search.SearchRequestBuilder

                                           Specification<Composite> whereClause,
                                           Map<String, Object> variables )
            throws EntityFinderException
        {
            // Prepare request
            SearchRequestBuilder request = support.client().prepareSearch( support.index() );

            AndFilterBuilder filterBuilder = baseFilters( resultType );
            QueryBuilder queryBuilder = processWhereSpecification( filterBuilder, whereClause, variables );

            request.setQuery( filteredQuery( queryBuilder, filterBuilder ) );
            request.setSize( 1 );

            // Log
            LOGGER.debug( "Will search Entity: {}", request );

            // Execute
            SearchResponse response = request.execute().actionGet();

            if( response.getHits().totalHits() == 1 )
            {
                return EntityReference.parseEntityReference( response.getHits().getAt( 0 ).id() );
            }
View Full Code Here

Examples of org.elasticsearch.action.search.SearchRequestBuilder

    }

    private SearchResponse getSearchResponse(final String sessionId,
            final QueryBuilder queryBuilder, final Integer from,
            final Integer size, final SortBuilder sortBuilder) {
        final SearchRequestBuilder builder = riverConfig.getClient()
                .prepareSearch(index).setTypes(type);
        if (StringUtil.isNotBlank(sessionId)) {
            builder.setPostFilter(FilterBuilders.queryFilter(QueryBuilders
                    .queryString(SESSION_ID + ":" + sessionId)));
        }
        if (queryBuilder != null) {
            builder.setQuery(queryBuilder);
        } else {
            builder.setQuery(QueryBuilders.matchAllQuery());
        }
        if (sortBuilder != null) {
            builder.addSort(sortBuilder);
        }
        if (from != null) {
            builder.setFrom(from);
        }
        if (size != null) {
            builder.setSize(size);
        }
        final SearchResponse response = builder.execute().actionGet();
        return response;
    }
View Full Code Here

Examples of org.elasticsearch.action.search.SearchRequestBuilder

            }

            ActionFuture<SearchResponse> responseFuture;
            if (_scrollId == null) {
              // first request
              SearchRequestBuilder builder = new SearchRequestBuilder(_client)
                  .setIndices(mapping.getTypeAlias()).setFilter(FilterBuilders.matchAllFilter())
                  .setScroll(TimeValue.timeValueSeconds(_scrollTimeoutSeconds))
                  .addSort("_id", SortOrder.ASC).setSize(batchSize);

              responseFuture = _client.search(builder.request());
            } else {
              responseFuture = _client.searchScroll(new SearchScrollRequestBuilder(_client, _scrollId)
                  .request());
            }
View Full Code Here

Examples of org.elasticsearch.action.search.SearchRequestBuilder

            for (int i = 0; i < indices.size(); i++) {
                list.add(indices.<String>get(i));
            }
        }

        SearchRequestBuilder builder = client.prepareSearch(list.toArray(new String[list.size()]));

        // Get types to be searched
        String type = body.getString(CONST_TYPE);
        JsonArray types = body.getArray("_types");
        list.clear();
        if (type != null) {
            list.add(type);
        }
        if (types != null) {
            for (int i = 0; i < types.size(); i++) {
                list.add(types.<String>get(i));
            }
        }
        if (!list.isEmpty()) {
            builder.setTypes(list.toArray(new String[list.size()]));
        }

        // Set the query
        JsonObject query = body.getObject("query");
        if (query != null) {
            builder.setQuery(query.encode());
        }

        // Set the filter
        JsonObject filter = body.getObject("filter");
        if (filter != null) {
            builder.setPostFilter(filter.encode());
        }

        // Set facets
        JsonObject facets = body.getObject("facets");
        if (facets != null) {
            builder.setFacets(facets.encode().getBytes(CHARSET_UTF8));
        }

        // Set search type
        String searchType = body.getString("search_type");
        if (searchType != null) {
            builder.setSearchType(searchType);
        }

        // Set scroll keep alive time
        String scroll = body.getString("scroll");
        if (scroll != null) {
            builder.setScroll(scroll);
        }

        // Set Size
        Integer size = body.getInteger("size");
        if (size != null) {
            builder.setSize(size);
        }

        //Set requested fields
        JsonArray fields = body.getArray("fields");
        if (fields != null) {
            for (int i = 0; i < fields.size(); i++) {
                builder.addField(fields.<String>get(i));
            }
        }

        //Set query timeout
        Long queryTimeout = body.getLong("timeout");
        if (queryTimeout != null) {
            builder.setTimeout(new TimeValue(queryTimeout));
        }

        builder.execute(new ActionListener<SearchResponse>() {
            @Override
            public void onResponse(SearchResponse searchResponse) {
                handleActionResponse(searchResponse, message);
            }
View Full Code Here

Examples of org.elasticsearch.action.search.SearchRequestBuilder

public class ReIndexActionESTest extends ReIndexActionTester {

    @Override
    protected MySearchResponse scrollSearch(String index, String type, String query, int hits,
            boolean withVersion, int keepMinutes) {
        SearchRequestBuilder srb = action.createScrollSearch(index, type, query, hits, withVersion, keepMinutes);
        return new MySearchResponseES(client, srb.execute().actionGet(), keepMinutes);
    }
View Full Code Here

Examples of org.elasticsearch.action.search.SearchRequestBuilder

                }
                return res;
            }
        };
        // first query, further scroll-queries in reindex!
        SearchRequestBuilder srb = action.createScrollSearch(searchIndexName, searchType, filter,
                hitsPerPage, withVersion, keepTimeInMinutes);
        SearchResponse sr = srb.execute().actionGet();
        MySearchResponse rsp = new MySearchResponseES(client, sr, keepTimeInMinutes);

        // now feed and call callback
        action.reindex(rsp, newIndexName, newType, withVersion, waitInSeconds);
View Full Code Here

Examples of org.elasticsearch.action.search.SearchRequestBuilder

            float waitInSeconds = request.paramAsFloat("waitInSeconds", 0);
            String basicAuthCredentials = request.param("credentials", "");
            String filter = request.content().toUtf8();
            MySearchResponse rsp;
            if (localAction) {
                SearchRequestBuilder srb = createScrollSearch(searchIndexName, searchType, filter,
                        hitsPerPage, withVersion, keepTimeInMinutes);
                SearchResponse sr = srb.execute().actionGet();
                rsp = new MySearchResponseES(client, sr, keepTimeInMinutes);
            } else {
                // TODO make it possible to restrict to a cluster
                rsp = new MySearchResponseJson(searchHost, searchPort, searchIndexName, searchType, filter,
                        basicAuthCredentials, hitsPerPage, withVersion, keepTimeInMinutes);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.