当前位置: 首页>>代码示例>>Java>>正文


Java Search类代码示例

本文整理汇总了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());
}
 
开发者ID:openmrs,项目名称:openmrs-contrib-addonindex,代码行数:23,代码来源:ElasticSearchIndexManualTest.java

示例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();
	}
}
 
开发者ID:conorheffron,项目名称:elastic-tester,代码行数:21,代码来源:ElasticApp.java

示例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);
		}

	}
 
开发者ID:molindo,项目名称:molindo-elasticsync,代码行数:25,代码来源:ElasticsearchJestIndex.java

示例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);
}
 
开发者ID:CMPUT301F17T15,项目名称:CIA,代码行数:23,代码来源:ElasticSearchUtilities.java

示例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;
}
 
开发者ID:CMPUT301F17T29,项目名称:HabitUp,代码行数:27,代码来源:ElasticSearchController.java

示例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;
}
 
开发者ID:CMPUT301F17T09,项目名称:GoalsAndHabits,代码行数:27,代码来源:ElasticSearchController.java

示例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);
   }
 
开发者ID:openmrs,项目名称:openmrs-contrib-addonindex,代码行数:18,代码来源:ElasticSearchIndex.java

示例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();
	}
}
 
开发者ID:conorheffron,项目名称:elastic-tester,代码行数:18,代码来源:ElasticApp.java

示例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();
        }
    }
}
 
开发者ID:CMPUT301F16T01,项目名称:Carrier,代码行数:29,代码来源:ElasticRequestController.java

示例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;
}
 
开发者ID:CMPUT301F16T01,项目名称:Carrier,代码行数:27,代码来源:ElasticUserController.java

示例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;
}
 
开发者ID:CMPUT301F16T02,项目名称:Dryver,代码行数:22,代码来源:ElasticSearchController.java

示例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;
    }
}
 
开发者ID:CMPUT301F16T04,项目名称:Ridr,代码行数:27,代码来源:AsyncDatabaseController.java

示例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);
}
 
开发者ID:paulcwarren,项目名称:spring-content,代码行数:17,代码来源:ElasticsearchSearcher.java

示例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);
}
 
开发者ID:paulcwarren,项目名称:spring-content,代码行数:17,代码来源:ElasticsearchSearcher.java


注:本文中的io.searchbox.core.Search类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。