use of org.elasticsearch.action.search.SearchRequestBuilder in project stash-codesearch-plugin by palantir.
the class SearchUpdateJobImpl method doReindex.
@Override
public void doReindex(Client client, GitScm gitScm, GlobalSettings globalSettings) {
if (!globalSettings.getIndexingEnabled()) {
return;
}
deleteLatestIndexedNote(client);
while (true) {
try {
SearchRequestBuilder esReq = client.prepareSearch(ES_UPDATEALIAS).setSize(1000).setFetchSource(false).setRouting(getRepoDesc()).setQuery(filteredQuery(matchAllQuery(), andFilter(sfu.projectRepositoryFilter(repository.getProject().getKey(), repository.getSlug()), sfu.exactRefFilter(ref))));
BulkRequestBuilder bulkDelete = client.prepareBulk().setRefresh(true);
for (SearchHit hit : esReq.get().getHits().getHits()) {
bulkDelete.add(buildDeleteFromRef(client, hit.getType(), hit.getId()));
}
if (bulkDelete.numberOfActions() == 0) {
break;
}
bulkDelete.get();
} catch (Exception e) {
log.error("Could not delete documents for {}, aborting", toString(), e);
return;
}
}
doUpdate(client, gitScm, globalSettings);
}
use of org.elasticsearch.action.search.SearchRequestBuilder in project elasticsearch-opennlp-plugin by spinscale.
the class OpenNlpPluginIntegrationTest method testThatFacetingIsWorking.
@Test
public void testThatFacetingIsWorking() throws Exception {
putMapping("/test-mapping-analyzers.json");
String sampleText = copyToStringFromClasspath("/sample-text.txt");
IndexResponse indexResponse = indexElement(sampleText);
SearchResponse searchResponse = new SearchRequestBuilder(node.client()).setIndices(index).setTypes(type).setQuery(QueryBuilders.matchAllQuery()).addFacet(new TermsFacetBuilder("names").field("someFieldAnalyzed.name").order(TermsFacet.ComparatorType.TERM)).execute().actionGet();
assertThat(searchResponse.getHits().totalHits(), is(1L));
assertThat(searchResponse.getHits().getAt(0).id(), is(indexResponse.getId()));
TermsFacet termsFacet = searchResponse.getFacets().facet(TermsFacet.class, "names");
assertThat(termsFacet.getTotalCount(), is(2L));
assertThat(termsFacet.getEntries().get(0).getTerm().string(), is("Jack Nicholson"));
assertThat(termsFacet.getEntries().get(1).getTerm().string(), is("Kobe Bryant"));
}
use of org.elasticsearch.action.search.SearchRequestBuilder in project titan by thinkaurelius.
the class ElasticSearchIndex method query.
@Override
public Iterable<RawQuery.Result<String>> query(RawQuery query, KeyInformation.IndexRetriever informations, BaseTransaction tx) throws BackendException {
SearchRequestBuilder srb = client.prepareSearch(indexName);
srb.setTypes(query.getStore());
srb.setQuery(QueryBuilders.queryStringQuery(query.getQuery()));
srb.setFrom(query.getOffset());
if (query.hasLimit())
srb.setSize(query.getLimit());
else
srb.setSize(maxResultsSize);
srb.setNoFields();
//srb.setExplain(true);
SearchResponse response = srb.execute().actionGet();
log.debug("Executed query [{}] in {} ms", query.getQuery(), response.getTookInMillis());
SearchHits hits = response.getHits();
if (!query.hasLimit() && hits.totalHits() >= maxResultsSize)
log.warn("Query result set truncated to first [{}] elements for query: {}", maxResultsSize, query);
List<RawQuery.Result<String>> result = new ArrayList<RawQuery.Result<String>>(hits.hits().length);
for (SearchHit hit : hits) {
result.add(new RawQuery.Result<String>(hit.id(), hit.getScore()));
}
return result;
}
use of org.elasticsearch.action.search.SearchRequestBuilder in project metacat by Netflix.
the class ElasticSearchUtilImpl method getIdsByQualifiedName.
/**
* List of names.
*
* @param type type
* @param qualifiedName name
* @return list of names
*/
public List<String> getIdsByQualifiedName(final String type, final QualifiedName qualifiedName) {
List<String> result = Lists.newArrayList();
// Run the query and get the response.
final QueryBuilder queryBuilder = QueryBuilders.boolQuery().must(QueryBuilders.termQuery("name.qualifiedName.tree", qualifiedName)).must(QueryBuilders.termQuery("deleted_", false));
final SearchRequestBuilder request = client.prepareSearch(esIndex).setTypes(type).setSearchType(SearchType.QUERY_THEN_FETCH).setQuery(queryBuilder).setSize(Integer.MAX_VALUE).setNoFields();
final SearchResponse response = request.execute().actionGet();
if (response.getHits().hits().length != 0) {
result = getIds(response);
}
return result;
}
use of org.elasticsearch.action.search.SearchRequestBuilder in project metacat by Netflix.
the class ElasticSearchUtilImpl method getTableIdsByUri.
/**
* List table names by uri.
*
* @param type doc type
* @param dataUri uri
* @return list of table names
*/
public List<String> getTableIdsByUri(final String type, final String dataUri) {
List<String> ids = Lists.newArrayList();
if (dataUri != null) {
//
// Run the query and get the response.
final SearchRequestBuilder request = client.prepareSearch(esIndex).setTypes(type).setSearchType(SearchType.QUERY_THEN_FETCH).setQuery(QueryBuilders.termQuery("serde.uri", dataUri)).setSize(Integer.MAX_VALUE).setNoFields();
final SearchResponse response = request.execute().actionGet();
if (response.getHits().hits().length != 0) {
ids = getIds(response);
}
}
return ids;
}
Aggregations