本文整理汇总了Java中io.searchbox.core.Search类的典型用法代码示例。如果您正苦于以下问题:Java Search类的具体用法?Java Search怎么用?Java Search使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Search类属于io.searchbox.core包,在下文中一共展示了Search类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testGetByModulePackage
import io.searchbox.core.Search; //导入依赖的package包/类
@Test
public void testGetByModulePackage() throws Exception {
SearchResult result = client.execute(new Search.Builder(new SearchSourceBuilder()
.size(1)
.query(QueryBuilders.matchQuery("modulePackage", "testing-mod")).toString())
.addIndex(AddOnInfoAndVersions.ES_INDEX)
.build());
SearchResult resultNotFound = client.execute(new Search.Builder(new SearchSourceBuilder()
.size(1)
.query(QueryBuilders.matchQuery("modulePackage", "fake-mod")).toString())
.addIndex(AddOnInfoAndVersions.ES_INDEX)
.build());
List<AddOnInfoAndVersions> searchResult = result.getHits(AddOnInfoAndVersions.class).stream()
.map(sr -> sr.source)
.collect(Collectors.toList());
List<AddOnInfoAndVersions> searchResultNotFound = resultNotFound.getHits(AddOnInfoAndVersions.class).stream()
.map(sr -> sr.source)
.collect(Collectors.toList());
assertNotNull(searchResult);
assertThat(searchResultNotFound, IsEmptyCollection.empty());
System.out.println("Module Package Name: "+searchResult.get(0).getModulePackage());
}
示例2: elasticSearch
import io.searchbox.core.Search; //导入依赖的package包/类
private static void elasticSearch(JestClient client, String indexName, String type, String query) {
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
QueryStringQueryBuilder queryStringQueryBuilder = QueryBuilders.queryStringQuery(query);
searchSourceBuilder.query(queryStringQueryBuilder);
Search searchElastic = (Search) new Search.Builder(searchSourceBuilder.toString())
// multiple index or types can be added.
.addIndex(indexName).addType(type).build();
try {
SearchResult elasticRs = client.execute(searchElastic);
List<Hit<Article, Void>> hits = elasticRs.getHits(Article.class);
for (Hit<Article, Void> hit : hits) {
Article talk = hit.source;
System.out.println("Elastic hits: " + talk.toString());
}
} catch (IOException e) {
e.printStackTrace();
}
}
示例3: getDateHistogram
import io.searchbox.core.Search; //导入依赖的package包/类
public List<Pair<String, Long>> getDateHistogram(UsageLogSearchQuery searchQuery) {
String query = getQuery(searchQuery);
Search search = new Search.Builder(query)
.addIndex(StatisticConstant.INDEX_NAME)
.addType(StatisticConstant.INDEX_TYPE)
.build();
List<Pair<String, Long>> data = new ArrayList<>();
try {
SearchResult result = client.execute(search);
MetricAggregation aggregation = result.getAggregations();
DateHistogramAggregation dateHistogram = aggregation.getDateHistogramAggregation("event_over_time");
for (DateHistogramAggregation.DateHistogram unit : dateHistogram.getBuckets()) {
data.add(new Pair(unit.getTimeAsString(), unit.getCount()));
}
} catch (IOException ioe) {
logger.log(Level.INFO, null, ioe);
}
return data;
}
开发者ID:pengchengluo,项目名称:Peking-University-Open-Research-Data-Platform,代码行数:20,代码来源:UsageLogSearchServiceBean.java
示例4: startScroll
import io.searchbox.core.Search; //导入依赖的package包/类
String startScroll(String type) {
Builder builder = new Search.Builder(versionHelper.createQuery(query));
builder.addIndex(indexName);
builder.addType(type);
builder.setParameter(Parameters.SIZE, BATCH_SIZE);
builder.setParameter(Parameters.EXPLAIN, false);
// searchRequestBuilder.setNoFields();
builder.setParameter(Parameters.VERSION, true);
builder.setSearchType(SearchType.SCAN);
builder.setParameter(Parameters.SCROLL, SCROLL_TIME_IN_MINUTES + "m");
try {
JestResult result = client.execute(builder.build());
if (result.isSucceeded()) {
return result.getJsonObject().get("_scroll_id").getAsString();
} else {
throw new RuntimeException("failed to start scroll operation: " + result.getJsonObject());
}
} catch (Exception e) {
throw new RuntimeException("failed to start scroll operation", e);
}
}
示例5: doInBackground
import io.searchbox.core.Search; //导入依赖的package包/类
@Override
protected Pair<SearchResult, Boolean> doInBackground(String... search_parameters) {
verifySettings();
String typeId = search_parameters[0];
Search search = new Search.Builder("{ \"size\" : 100 } ").addIndex(INDEX).addType(typeId).build();
try {
SearchResult result = client.execute(search);
if (result.isSucceeded()) {
return new Pair<>(result, Boolean.TRUE);
} else {
Log.i("Error", "the search query failed to find any objects that matched");
}
}
catch (Exception e) {
Log.i("Error", "Something went wrong when we tried to communicate with the elasticsearch server!");
return new Pair<>(null, Boolean.FALSE);
}
return new Pair<>(null, Boolean.TRUE);
}
示例6: doInBackground
import io.searchbox.core.Search; //导入依赖的package包/类
@Override
protected ArrayList<HabitEvent> doInBackground(String... eids) {
verifySettings();
ArrayList<HabitEvent> habitEvents = new ArrayList<HabitEvent>();
String query = "{\"query\": {\"match\" : { \"eid\" : \"" + eids[0] + "\" }}}";
Search search = new Search.Builder(query).addIndex(db).addType(habitEventType).build();
try {
SearchResult result = client.execute(search);
if (result.isSucceeded()) {
List<HabitEvent> foundHabitEvent = result.getSourceAsObjectList(HabitEvent.class);
habitEvents.addAll(foundHabitEvent);
} else {
Log.i("Error2", "Something went wrong when we tried to communicate with the elasticsearch server");
}
}
catch (Exception e) {
Log.i("Error1", "Something went wrong when we tried to communicate with the elasticsearch server!");
}
return habitEvents;
}
示例7: doInBackground
import io.searchbox.core.Search; //导入依赖的package包/类
@Override
protected ArrayList<Profile> doInBackground(String... search_parameters){
verifySettings();
ArrayList<Profile> profiles = new ArrayList<Profile>();
String query = "{\n"
+ " \"query\" : {\n"
+ " \"term\" : { \"username\" : \""+search_parameters[0]+"\"}\n"
+ " }\n"
+ "}";
Search search = new Search.Builder(query).addIndex(appESIndex).addType("profile").build();
try{
SearchResult result = client.execute(search);
if (result.isSucceeded()){
List<Profile> foundProfiles = result.getSourceAsObjectList(Profile.class);
profiles.addAll(foundProfiles);
}else{
Log.i("Error","ElasticSearch search query failed");
}
}catch (Exception e){
Log.i("Error","ElasticSearch filed to find profiles");
}
return profiles;
}
示例8: getByModulePackage
import io.searchbox.core.Search; //导入依赖的package包/类
@Override
public AddOnInfoAndVersions getByModulePackage(String modulePackage) throws IOException {
SearchResult result = client.execute(new Search.Builder(new SearchSourceBuilder()
.size(1)
.query(QueryBuilders.matchQuery("modulePackage", modulePackage)).toString())
.addIndex(AddOnInfoAndVersions.ES_INDEX)
.build());
List<AddOnInfoAndVersions> modules = result.getHits(AddOnInfoAndVersions.class).stream()
.map(sr -> sr.source)
.collect(Collectors.toList());
if (modules.isEmpty()) {
return null;
}
return modules.get(0);
}
示例9: jestSearchModel
import io.searchbox.core.Search; //导入依赖的package包/类
private static void jestSearchModel(JestClient client, String indexName, String type, String query) {
Search.Builder searchBuilder = new Search.Builder(query).addIndex(indexName).addType(type);
try {
SearchResult result = client.execute(searchBuilder.build());
System.out.println(result.getJsonObject());
List<Hit<Article, Void>> hits = result.getHits(Article.class);
for (Hit<Article, Void> hit : hits) {
Article talk = hit.source;
System.out.println("JEST Search model hit: " + talk.toString());
}
} catch (IOException e) {
e.printStackTrace();
}
}
示例10: getOffers
import io.searchbox.core.Search; //导入依赖的package包/类
/**
* Sub-task: grab the offers for a request and then populate a request with them.
* @see #populate(Request, List)
*/
private static void getOffers(RequestList foundRequests) {
for( Request request : foundRequests ) {
// TODO filter requests that will not have offering drivers?
String query =
"{ \"from\":0, \"size\":1000,\n" +
" \"query\": { \"match\": { \"requestID\" : \"" + request.getId() + "\" } }\n" +
"}";
Search search = new Search.Builder(query)
.addIndex("cmput301f16t01")
.addType("offer")
.build();
try {
SearchResult result = client.execute(search);
if (result.isSucceeded()) {
List<Offer> offers = result.getSourceAsObjectList(Offer.class);
populate( request, offers );
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
示例11: doInBackground
import io.searchbox.core.Search; //导入依赖的package包/类
@Override
protected User doInBackground(String... search_parameters) {
verifySettings();
String search_string = "{\"from\": 0, \"size\": 1, \"query\": {\"match\": {\"username\": \"" + search_parameters[0] + "\"}}}";
Search search = new Search.Builder(search_string)
.addIndex("cmput301f16t01")
.addType("user")
.build();
User foundUser = null;
try {
SearchResult result = client.execute(search);
if (result.isSucceeded()) {
foundUser = result.getSourceAsObject(User.class);
} else {
return null;
}
} catch (IOException e) {
e.printStackTrace();
Log.i("Error", "Something went wrong when we tried to talk to elastic search");
}
return foundUser;
}
示例12: doInBackground
import io.searchbox.core.Search; //导入依赖的package包/类
@Override
protected ArrayList<User> doInBackground(String... search_parameters) {
verifySettings();
ArrayList<User> users = new ArrayList<User>();
Search search = new Search.Builder(search_parameters[0]).addIndex(INDEX).addType(USER).build();
try {
SearchResult result = client.execute(search);
if (result.isSucceeded()) {
List<User> foundUsers = result.getSourceAsObjectList(User.class);
users.addAll(foundUsers);
} else {
Log.i("Error", "The search query failed to find users");
}
} catch (Exception e) {
Log.i("Error", "Something went wrong when communicating with the server!");
}
return users;
}
示例13: getRequest
import io.searchbox.core.Search; //导入依赖的package包/类
@Nullable
/**
* A generic function that performs a get request to the elastic search databases
* @param type
* @param searchString
* @throws IOException
* @return result
* @nullable
*/
private JestResult getRequest(String type, String searchString) throws IOException {
// As the name implies builds a search object and returns the result
Search search = new Search.Builder(searchString)
.addIndex(databaseName)
.addType(type)
.build();
JestResult result = client.execute(search);
System.out.println(search.toString());
System.out.println(result.getJsonObject());
if (result.isSucceeded()) {
return result;
}
else {
Log.i("Error", "The search query failed to find the Class that matched.");
return null;
}
}
示例14: findAllKeywords
import io.searchbox.core.Search; //导入依赖的package包/类
@Override
public Iterable<Serializable> findAllKeywords(String... terms) {
StringBuilder qb = join("AND", terms);
Search search = getSearch(qb.toString());
SearchResult result;
try {
result = client.execute(search);
} catch (IOException e) {
throw new StoreAccessException(String.format("Exception while searching for %s", qb), e);
}
return getIDs(result);
}
示例15: findAnyKeywords
import io.searchbox.core.Search; //导入依赖的package包/类
@Override
public Iterable<Serializable> findAnyKeywords(String... terms) {
StringBuilder qb = join("OR", terms);
Search search = getSearch(qb.toString());
SearchResult result;
try {
result = client.execute(search);
} catch (IOException e) {
throw new StoreAccessException(String.format("Exception while searching for %s", qb), e);
}
return getIDs(result);
}