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


Java Search.Builder方法代码示例

本文整理汇总了Java中io.searchbox.core.Search.Builder方法的典型用法代码示例。如果您正苦于以下问题:Java Search.Builder方法的具体用法?Java Search.Builder怎么用?Java Search.Builder使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在io.searchbox.core.Search的用法示例。


在下文中一共展示了Search.Builder方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: 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

示例2: 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

示例3: searchObj

import io.searchbox.core.Search; //导入方法依赖的package包/类
@Override
public <T> WSearchResult<T> searchObj(String index, String type, SearchQuery query, Class<T> cls) throws
		Exception {
	Search.Builder builder = new Search.Builder(convert.toText(query));
	if (index != null) {
		builder.addIndex(index);
	}
	if (type != null) {
		builder.addType(type);
	}
	SearchResult result = _exec(builder.build());
	if (result != null) {
		WSearchResult<T> wresult = new WSearchResult<>();
		WSearchResultHits<T> hits = new WSearchResultHits<>();
		hits.setTotal(result.getTotal());
		List<SearchResult.Hit<T, Void>> allHist = result.getHits(cls);
		List<WEsDoc<T>> data = new ArrayList<>();
		for (SearchResult.Hit<T, Void> hit : allHist) {
			WEsDoc<T> doc = new WEsDoc<>();
			doc.setIndex(hit.index);
			doc.setType(hit.type);
			doc.setIndex(hit.index);
			doc.setSource(hit.source);
			doc.setScore(hit.score);
			data.add(doc);
		}
		hits.setHits(data);
		wresult.setHits(hits);
		return wresult;
	}
	return null;
}
 
开发者ID:DataSays,项目名称:wES,代码行数:33,代码来源:JestClient.java

示例4: submit

import io.searchbox.core.Search; //导入方法依赖的package包/类
public JsonObject submit(List<String> indexes, String query) throws IOException {
    log.info("Query {}", query);
    Search.Builder searchBuilder = new Search.Builder(query);

    indexes.stream().forEach(searchBuilder::addIndex);

    Search search = searchBuilder
            // multiple index or types can be added.
            .build();

    JestResult result = client.execute(search);
    return result.getJsonObject();
}
 
开发者ID:balamaci,项目名称:muninn,代码行数:14,代码来源:ElasticSearchGateway.java

示例5: scrollSearchResultsIntoBusinessObjectDefinitionDto

import io.searchbox.core.Search; //导入方法依赖的package包/类
/**
 * Private method to handle scrolling through the results from the search request and adding them to a business object definition entity list.
 *
 * @param searchRequestBuilder the the search request to scroll through
 * @param indexName the index name
 * @return list of business object definition entities
 */
private List<BusinessObjectDefinitionIndexSearchResponseDto> scrollSearchResultsIntoBusinessObjectDefinitionDto(
    final SearchRequestBuilder searchRequestBuilder, String indexName)
{
    // Retrieve the search response
    final Search.Builder searchBuilder = new Search.Builder(searchRequestBuilder.toString()).addIndex(indexName);

    searchBuilder.setParameter(Parameters.SIZE, ELASTIC_SEARCH_SCROLL_PAGE_SIZE);
    searchBuilder.setParameter(Parameters.SCROLL, new TimeValue(ELASTIC_SEARCH_SCROLL_KEEP_ALIVE_TIME).toString());

    JestResult jestResult = jestClientHelper.searchExecute(searchBuilder.build());

    List<BusinessObjectDefinitionIndexSearchResponseDto> businessObjectDefinitionIndexSearchResponseDtoList = new ArrayList<>();
    List<BusinessObjectDefinitionIndexSearchResponseDto> resultList =
        jestResult.getSourceAsObjectList(BusinessObjectDefinitionIndexSearchResponseDto.class);

    while (resultList.size() != 0)
    {
        businessObjectDefinitionIndexSearchResponseDtoList.addAll(resultList);
        String scrollId = jestResult.getJsonObject().get(SCROLL_ID).getAsString();
        SearchScroll scroll = new SearchScroll.Builder(scrollId, new TimeValue(ELASTIC_SEARCH_SCROLL_KEEP_ALIVE_TIME).toString()).build();
        jestResult = jestClientHelper.searchScrollExecute(scroll);
        resultList = jestResult.getSourceAsObjectList(BusinessObjectDefinitionIndexSearchResponseDto.class);
    }

    return businessObjectDefinitionIndexSearchResponseDtoList;
}
 
开发者ID:FINRAOS,项目名称:herd,代码行数:34,代码来源:BusinessObjectDefinitionIndexSearchDaoImpl.java

示例6: searchResponseIntoFacetInformation

import io.searchbox.core.Search; //导入方法依赖的package包/类
private List<TagTypeIndexSearchResponseDto> searchResponseIntoFacetInformation(final SearchRequestBuilder searchRequestBuilder, String indexName)
{
    // Retrieve the search response
    final Search.Builder searchBuilder = new Search.Builder(searchRequestBuilder.toString()).addIndex(indexName);
    SearchResult searchResult = jestClientHelper.searchExecute(searchBuilder.build());
    return elasticsearchHelper.getNestedTagTagIndexSearchResponseDto(searchResult);
}
 
开发者ID:FINRAOS,项目名称:herd,代码行数:8,代码来源:BusinessObjectDefinitionIndexSearchDaoImpl.java

示例7: getIdsInIndex

import io.searchbox.core.Search; //导入方法依赖的package包/类
/**
 * The ids in index function will take as arguments the index name and the document type and will return a list of all the ids in the index.
 */
@Override
public final List<String> getIdsInIndex(String indexName, String documentType)
{
    // Create an array list for storing the ids
    List<String> idList = new ArrayList<>();

    SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
    searchSourceBuilder.query(QueryBuilders.matchAllQuery());
    // Create a search request and set the scroll time and scroll size
    final SearchRequestBuilder searchRequestBuilder = new SearchRequestBuilder(new ElasticsearchClientImpl(), SearchAction.INSTANCE);
    searchRequestBuilder.setIndices(indexName).setTypes(documentType).setScroll(new TimeValue(ELASTIC_SEARCH_SCROLL_KEEP_ALIVE_TIME))
        .setSize(ELASTIC_SEARCH_SCROLL_PAGE_SIZE).setSource(searchSourceBuilder);

    // Retrieve the search response
    final Search.Builder searchBuilder = new Search.Builder(searchRequestBuilder.toString()).addIndex(indexName);

    searchBuilder.setParameter(Parameters.SIZE, ELASTIC_SEARCH_SCROLL_PAGE_SIZE);
    searchBuilder.setParameter(Parameters.SCROLL, new TimeValue(ELASTIC_SEARCH_SCROLL_KEEP_ALIVE_TIME).toString());

    JestResult jestResult = jestClientHelper.searchExecute(searchBuilder.build());

    // While there are hits available, page through the results and add them to the id list
    while (jestResult.getSourceAsStringList().size() != 0)
    {
        for (String jsonString : jestResult.getSourceAsStringList())
        {
            JsonElement root = new JsonParser().parse(jsonString);
            idList.add(root.getAsJsonObject().get("id").getAsString());
        }
        String scrollId = jestResult.getJsonObject().get("_scroll_id").getAsString();
        SearchScroll scroll = new SearchScroll.Builder(scrollId, new TimeValue(ELASTIC_SEARCH_SCROLL_KEEP_ALIVE_TIME).toString()).build();
        jestResult = jestClientHelper.searchScrollExecute(scroll);

    }
    return idList;
}
 
开发者ID:FINRAOS,项目名称:herd,代码行数:40,代码来源:IndexFunctionsDaoImpl.java

示例8: fullTextSearch

import io.searchbox.core.Search; //导入方法依赖的package包/类
static Search.Builder fullTextSearch(String queryTerm, Pageable pageable, List<String> filters) {

        BoolQueryBuilder query = QueryBuilders.boolQuery()
                .must(matchTitleContentAndAuthor(queryTerm))
                .should(matchMarkedAsCurrent())
                .should(matchProjectPages())
                .should(matchPhrase(queryTerm).boost(3f));

        String search = buildSearch(query, filters, pageable);

        return new Search.Builder(search);
    }
 
开发者ID:spring-io,项目名称:sagan,代码行数:13,代码来源:SaganQueryBuilders.java

示例9: fullTextSearch

import io.searchbox.core.Search; //导入方法依赖的package包/类
@Test
public void fullTextSearch() throws Exception {

    String query = "spring boot";
    List<String> filters = Arrays.asList("Projects/Api", "Projects/Reference", "Blog/Engineering", "Projects/Reactor Project/1.1.0.RELEASE");

    Search.Builder builder = SaganQueryBuilders.fullTextSearch(query, new PageRequest(0, 10), filters);

    String expected = StreamUtils.copyToString(
            new ClassPathResource("/fulltext-query.json", getClass()).getInputStream(),
            Charset.forName("UTF-8"));
    String actual = builder.build().getData(new Gson());

    assertThat(actual.replaceAll("[\\s|\\r|\\n]",""), equalTo(expected.replaceAll("[\\s|\\r|\\n]","")));
}
 
开发者ID:spring-io,项目名称:sagan,代码行数:16,代码来源:SaganQueryBuildersTests.java

示例10: forEmptyQuery

import io.searchbox.core.Search; //导入方法依赖的package包/类
static Search.Builder forEmptyQuery(Pageable pageable, List<String> filters) {
    QueryBuilder query = QueryBuilders.boolQuery().should(QueryBuilders.matchAllQuery());

    String search = buildSearch(query, filters, pageable);
    return new Search.Builder(search);
}
 
开发者ID:spring-io,项目名称:sagan,代码行数:7,代码来源:SaganQueryBuilders.java


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