Java Code Examples for org.elasticsearch.action.search.SearchResponse#getTookInMillis()

The following examples show how to use org.elasticsearch.action.search.SearchResponse#getTookInMillis() . 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: FilterJoinBenchmark.java    From siren-join with GNU Affero General Public License v3.0 6 votes vote down vote up
public long runQuery(String name, int testNum, String index, long expectedHits, QueryBuilder query) {
    SearchResponse searchResponse = new CoordinateSearchRequestBuilder(client)
    .setIndices(index)
            .setQuery(query)
            .execute().actionGet();

    if (searchResponse.getFailedShards() > 0) {
        log("Search Failures " + Arrays.toString(searchResponse.getShardFailures()));
    }

    long hits = searchResponse.getHits().totalHits();
    if (hits != expectedHits) {
        log("[" + name + "][#" + testNum + "] Hits Mismatch:  expected [" + expectedHits + "], got [" + hits + "]");
    }

    return searchResponse.getTookInMillis();
}
 
Example 2
Source File: Search.java    From elasticsearch-rest-command with The Unlicense 4 votes vote down vote up
public void executeQuery(final ActionListener<QueryResponse> listener,
		int from, final int size, String[] sortFields) {

	// jobHandler,执行期才知道要排序
	for (String field : sortFields) {
		if(field != null)	addSortToQuery(field);
	}

	querySearch.setSearchType(SearchType.QUERY_THEN_FETCH).setFrom(from)
			.setSize(size);
	dumpSearchScript(querySearch, logger);

	SearchResponse response = querySearch.execute().actionGet();
	logger.info(String.format("query took %d", response.getTookInMillis()));
	long milli = System.currentTimeMillis();

	final QueryResponse queryResponse = new QueryResponse(size);

	queryResponse.totalHits = response.getHits().getTotalHits();
	queryResponse.failedShards = response.getFailedShards();
	queryResponse.successfulShards = response.getSuccessfulShards();
	queryResponse.totalShards = response.getTotalShards();
	Iterator<SearchHit> iterator = response.getHits().iterator();

	while (iterator.hasNext()) {
		SearchHit _hit = iterator.next();
		Map<String, Object> hit = _hit.sourceAsMap();
		hit.put("_id", _hit.id());
		hit.put("_index", _hit.index());
		hit.put("_type", _hit.type());

		queryResponse.searchHits.add(hit);
	}

	for (Join join : joinSearchs) {
		try {
			JoinQuery.executeJoin(join, size, queryResponse.searchHits,
					client, logger);
		} catch (CommandException e) {
			logger.error("executeJoin", e);
			listener.onFailure(e);
			return;
		}
	}

	queryResponse.took = response.getTookInMillis()
			+ (System.currentTimeMillis() - milli);
	listener.onResponse(queryResponse);
}