Java Code Examples for org.elasticsearch.action.search.SearchType#DFS_QUERY_THEN_FETCH

The following examples show how to use org.elasticsearch.action.search.SearchType#DFS_QUERY_THEN_FETCH . 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: ESConnector.java    From Siamese with GNU General Public License v3.0 6 votes vote down vote up
public long getMaxId(String index, boolean isDFS) throws Exception {
	SearchType searchType;

	if (isDFS)
		searchType = SearchType.DFS_QUERY_THEN_FETCH;
	else
		searchType = SearchType.QUERY_THEN_FETCH;

	SearchResponse response = client.prepareSearch(index).setSearchType(searchType)
			.addSort(SortBuilders.fieldSort("_score").order(SortOrder.DESC))
			.addSort(SortBuilders.fieldSort("file").order(SortOrder.DESC))
			.setQuery(QueryBuilders.matchAllQuery())
			.addAggregation(AggregationBuilders.max("max_id").field("id"))
			.execute()
			.actionGet();

	Double maxId = (Double) response.getAggregations().get("max_id").getProperty("value");

	return maxId.longValue();
}
 
Example 2
Source File: ESConnector.java    From Siamese with GNU General Public License v3.0 6 votes vote down vote up
public ArrayList<Document> search(String index, String type, String query, boolean isPrint
			, boolean isDFS, int resultOffset, int resultSize) throws Exception {
        SearchType searchType;

        if (isDFS)
            searchType = SearchType.DFS_QUERY_THEN_FETCH;
        else
            searchType = SearchType.QUERY_THEN_FETCH;

		SearchResponse response = client.prepareSearch(index).setSearchType(searchType)
				.addSort(SortBuilders.fieldSort("_score").order(SortOrder.DESC))
				.addSort(SortBuilders.fieldSort("file").order(SortOrder.DESC))
				.setQuery(QueryBuilders.matchQuery("tokenizedsrc", query))
//				.setQuery(QueryBuilders.matchQuery("src", query))
				.setFrom(resultOffset).setSize(resultSize).execute()
				.actionGet();
		SearchHit[] hits = response.getHits().getHits();

        return prepareResults(hits, resultSize, isPrint);
    }
 
Example 3
Source File: ESConnector.java    From Siamese with GNU General Public License v3.0 4 votes vote down vote up
public String delete(String index, String type, String field, String query, boolean isDFS, int amount) {
	SearchType searchType;
	String output = "";
	if (isDFS)
		searchType = SearchType.DFS_QUERY_THEN_FETCH;
	else
		searchType = SearchType.QUERY_THEN_FETCH;

	SearchResponse response = client.prepareSearch(index).setSearchType(searchType)
			.addSort(SortBuilders.fieldSort("_score").order(SortOrder.DESC))
			.addSort(SortBuilders.fieldSort("file").order(SortOrder.DESC))
			.setScroll(new TimeValue(60000))
			.setSize(amount)
			.setQuery(QueryBuilders.wildcardQuery(field, query)).execute()
			.actionGet();

	// Scroll until no hits are returned
	while (true) {

		SearchHit[] hits = response.getHits().getHits();

		BulkRequestBuilder bulkRequest = client.prepareBulk();
		Arrays.asList(hits).stream().forEach(h ->
				bulkRequest.add(client.prepareDelete()
						.setIndex(index)
						.setType(type)
						.setId(h.getId())));

		BulkResponse bulkResponse = bulkRequest.execute().actionGet();

		if (bulkResponse.hasFailures()) {
			throw new RuntimeException(bulkResponse.buildFailureMessage());
		} else {
			output += "Deleted " + hits.length + " docs in " + bulkResponse.getTook() + "\n";
		}

		response = client.prepareSearchScroll(response.getScrollId())
				.setScroll(new TimeValue(60000)).execute().actionGet();
		//Break condition: No hits are returned
		if (response.getHits().getHits().length == 0) {
			break;
		}
	}

	return output;
}
 
Example 4
Source File: ESConnector.java    From Siamese with GNU General Public License v3.0 4 votes vote down vote up
public ArrayList<Document> search(
          String index,
          String type,
          String origQuery,
          String query,
          String t2Query,
	String t1Query,
          int origBoost,
          int normBoost,
          int t2Boost,
	int t1Boost,
          boolean isPrint,
          boolean isDFS,
          int resultOffset,
          int resultSize,
	String computeSimilarity,
	String[] similarity) throws Exception {
      SearchType searchType;
      if (isDFS)
          searchType = SearchType.DFS_QUERY_THEN_FETCH;
      else
          searchType = SearchType.QUERY_THEN_FETCH;
QueryBuilder queryBuilder;
if (computeSimilarity.equals("none") || computeSimilarity.equals("fuzzywuzzy"))
	queryBuilder = getQueryBuilder(origQuery, origBoost, t2Query, t2Boost,
			t1Query, t1Boost, query, normBoost);
else if (computeSimilarity.equals("tokenratio"))
	queryBuilder = getQueryBuilder(origQuery, origBoost, t2Query, t2Boost,
			t1Query, t1Boost, query, normBoost, similarity);
else
	throw new Exception("ERROR: wrong similarity measure.");
      SearchResponse response = client.prepareSearch(index).setSearchType(searchType)
              .addSort(SortBuilders.fieldSort("_score").order(SortOrder.DESC))
              .addSort(SortBuilders.fieldSort("file").order(SortOrder.DESC))
              .setQuery(queryBuilder)
              .setFrom(resultOffset).setSize(resultSize).execute()
              .actionGet();
      SearchHit[] hits = response.getHits().getHits();

      return prepareResults(hits, resultSize, isPrint);
  }