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


Java SearchRequest.source方法代码示例

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


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

示例1: selectTermAll

import org.elasticsearch.action.search.SearchRequest; //导入方法依赖的package包/类
public String selectTermAll(String indexs,String types,String field,String value){
	try {
		if(StringUtil.isEmpty(indexs))indexs="_all";
		if(xclient==null){
			init();
		}
		SearchSourceBuilder search = new SearchSourceBuilder();
		if(!StringUtil.isEmpty(field)&&!StringUtil.isEmpty(value)&&!(field.matches(regex)||field.matches(value))){
			search.query(QueryBuilders.termQuery(field, value));
		}
		search.aggregation(AggregationBuilders.terms("data").field(field+".keyword"));
		search.explain(false);
		SearchRequest request = new SearchRequest();
		request.searchType(SearchType.DFS_QUERY_THEN_FETCH);
		request.source(search);
		request.indices(indexs.split(","));
		request.types(types.split(","));
		SearchResponse response = xclient.search(request);
		return response.toString();
	} catch (Exception e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	return null;
}
 
开发者ID:dev-share,项目名称:database-transform-tool,代码行数:26,代码来源:ElasticsearchExtendHighRestFactory.java

示例2: selectMatchAll

import org.elasticsearch.action.search.SearchRequest; //导入方法依赖的package包/类
public String selectMatchAll(String indexs,String types,String field,String value){
	try {
		if(StringUtil.isEmpty(indexs))indexs="_all";
		if(xclient==null){
			init();
		}
		SearchSourceBuilder search = new SearchSourceBuilder();
		if(!StringUtil.isEmpty(field)&&!StringUtil.isEmpty(value)&&!(field.matches(regex)||field.matches(value))){
			search.query(QueryBuilders.matchQuery(field, value));
		}
		search.aggregation(AggregationBuilders.terms("data").field(field+".keyword"));
		search.explain(false);
		SearchRequest request = new SearchRequest();
		request.searchType(SearchType.DFS_QUERY_THEN_FETCH);
		request.source(search);
		request.indices(indexs.split(","));
		request.types(types.split(","));
		SearchResponse response = xclient.search(request);
		return response.toString();
	} catch (Exception e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	return null;
}
 
开发者ID:dev-share,项目名称:database-transform-tool,代码行数:26,代码来源:ElasticsearchHighRestFactory.java

示例3: setUp

import org.elasticsearch.action.search.SearchRequest; //导入方法依赖的package包/类
@Before
@Override
public void setUp() throws Exception {
    super.setUp();
    final ExecutorService directExecutor = EsExecutors.newDirectExecutorService();
    threadPool = new TestThreadPool(getTestName()) {
        @Override
        public ExecutorService executor(String name) {
            return directExecutor;
        }

        @Override
        public ScheduledFuture<?> schedule(TimeValue delay, String name, Runnable command) {
            command.run();
            return null;
        }
    };
    retries = 0;
    searchRequest = new SearchRequest();
    searchRequest.scroll(timeValueMinutes(5));
    searchRequest.source(new SearchSourceBuilder().size(10).version(true).sort("_doc").size(123));
    retriesAllowed = 0;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:24,代码来源:RemoteScrollableHitSourceTests.java

示例4: testInitialSearchEntity

import org.elasticsearch.action.search.SearchRequest; //导入方法依赖的package包/类
public void testInitialSearchEntity() throws IOException {
    SearchRequest searchRequest = new SearchRequest();
    searchRequest.source(new SearchSourceBuilder());
    String query = "{\"match_all\":{}}";
    HttpEntity entity = initialSearchEntity(searchRequest, new BytesArray(query));
    assertEquals(ContentType.APPLICATION_JSON.toString(), entity.getContentType().getValue());
    assertEquals("{\"query\":" + query + ",\"_source\":true}",
            Streams.copyToString(new InputStreamReader(entity.getContent(), StandardCharsets.UTF_8)));

    // Source filtering is included if set up
    searchRequest.source().fetchSource(new String[] {"in1", "in2"}, new String[] {"out"});
    entity = initialSearchEntity(searchRequest, new BytesArray(query));
    assertEquals(ContentType.APPLICATION_JSON.toString(), entity.getContentType().getValue());
    assertEquals("{\"query\":" + query + ",\"_source\":{\"includes\":[\"in1\",\"in2\"],\"excludes\":[\"out\"]}}",
            Streams.copyToString(new InputStreamReader(entity.getContent(), StandardCharsets.UTF_8)));

    // Invalid XContent fails
    RuntimeException e = expectThrows(RuntimeException.class,
            () -> initialSearchEntity(searchRequest, new BytesArray("{}, \"trailing\": {}")));
    assertThat(e.getCause().getMessage(), containsString("Unexpected character (',' (code 44))"));
    e = expectThrows(RuntimeException.class, () -> initialSearchEntity(searchRequest, new BytesArray("{")));
    assertThat(e.getCause().getMessage(), containsString("Unexpected end-of-input"));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:24,代码来源:RemoteRequestBuildersTests.java

示例5: selectAll

import org.elasticsearch.action.search.SearchRequest; //导入方法依赖的package包/类
public String selectAll(String indexs,String types,String condition){
	try {
		if(StringUtil.isEmpty(indexs))indexs="_all";
		if(xclient==null){
			init();
		}
		SearchSourceBuilder search = new SearchSourceBuilder();
		search.query(QueryBuilders.queryStringQuery(condition)); 
		search.explain(false);
		SearchRequest request = new SearchRequest();
		request.searchType(SearchType.DFS_QUERY_THEN_FETCH);
		request.source(search);
		request.indices(indexs.split(","));
		request.types(types.split(","));
		SearchResponse response = xclient.search(request);
		return response.toString();
	} catch (Exception e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	return null;
}
 
开发者ID:dev-share,项目名称:database-transform-tool,代码行数:23,代码来源:ElasticsearchHighRestFactory.java

示例6: find

import org.elasticsearch.action.search.SearchRequest; //导入方法依赖的package包/类
public String find() {
  try {
    final SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
    searchSourceBuilder.sort("_score");
    searchSourceBuilder.sort("_uid");

    final String queryText = "*";
    final SimpleQueryStringBuilder simpleQueryStringBuilder =
        new SimpleQueryStringBuilder(queryText);
    simpleQueryStringBuilder.defaultOperator(Operator.AND);
    searchSourceBuilder.query(simpleQueryStringBuilder);
    searchSourceBuilder.size(500);

    //LOGGER.info("Elasticsearch query: {}", searchSourceBuilder.toString());

    final SearchRequest searchRequest = new SearchRequest();
    searchRequest.indices("tweets");
    searchRequest.types("tweet");
    searchRequest.source(searchSourceBuilder);
    final SearchResponse searchResponse = restHighLevelClient.search(searchRequest);
    return searchResponse.toString();
  } catch (IOException e) {
    e.printStackTrace();
    return e.getMessage();
  }
}
 
开发者ID:jeqo,项目名称:talk-observing-distributed-systems,代码行数:27,代码来源:ElasticsearchTweetRepository.java

示例7: toSearchRequest

import org.elasticsearch.action.search.SearchRequest; //导入方法依赖的package包/类
public SearchRequest toSearchRequest() {
    SearchRequest searchRequest = new SearchRequest(indices());
    searchRequest.indicesOptions(indicesOptions());
    searchRequest.types(types());
    searchRequest.routing(routing());
    searchRequest.preference(preference());
    searchRequest.source(source());
    SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
    searchSourceBuilder.size(0);
    if (minScore() != DEFAULT_MIN_SCORE) {
        searchSourceBuilder.minScore(minScore());
    }
    if (terminateAfter() != DEFAULT_TERMINATE_AFTER) {
        searchSourceBuilder.terminateAfter(terminateAfter());
    }
    searchRequest.extraSource(searchSourceBuilder);
    return searchRequest;
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:19,代码来源:CountRequest.java

示例8: randomSearchRequest

import org.elasticsearch.action.search.SearchRequest; //导入方法依赖的package包/类
/**
 * Build a random search request.
 *
 * @param randomSearchSourceBuilder builds a random {@link SearchSourceBuilder}. You can use
 *        {@link #randomSearchSourceBuilder(Supplier, Supplier, Supplier, Supplier, Supplier)}.
 */
public static SearchRequest randomSearchRequest(Supplier<SearchSourceBuilder> randomSearchSourceBuilder) throws IOException {
    SearchRequest searchRequest = new SearchRequest();
    if (randomBoolean()) {
        searchRequest.indices(generateRandomStringArray(10, 10, false, false));
    }
    if (randomBoolean()) {
        searchRequest.indicesOptions(IndicesOptions.fromOptions(randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean()));
    }
    if (randomBoolean()) {
        searchRequest.types(generateRandomStringArray(10, 10, false, false));
    }
    if (randomBoolean()) {
        searchRequest.preference(randomAsciiOfLengthBetween(3, 10));
    }
    if (randomBoolean()) {
        searchRequest.requestCache(randomBoolean());
    }
    if (randomBoolean()) {
        searchRequest.routing(randomAsciiOfLengthBetween(3, 10));
    }
    if (randomBoolean()) {
        searchRequest.scroll(randomPositiveTimeValue());
    }
    if (randomBoolean()) {
        searchRequest.searchType(randomFrom(SearchType.values()));
    }
    if (randomBoolean()) {
        searchRequest.source(randomSearchSourceBuilder.get());
    }
    return searchRequest;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:38,代码来源:RandomSearchRequestGenerator.java

示例9: ShardSearchLocalRequest

import org.elasticsearch.action.search.SearchRequest; //导入方法依赖的package包/类
ShardSearchLocalRequest(SearchRequest searchRequest, ShardId shardId, int numberOfShards,
                        AliasFilter aliasFilter, float indexBoost, long nowInMillis) {
    this(shardId, numberOfShards, searchRequest.searchType(),
            searchRequest.source(), searchRequest.types(), searchRequest.requestCache(), aliasFilter, indexBoost);
    this.scroll = searchRequest.scroll();
    this.nowInMillis = nowInMillis;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:8,代码来源:ShardSearchLocalRequest.java

示例10: parseSearchRequest

import org.elasticsearch.action.search.SearchRequest; //导入方法依赖的package包/类
/**
 * Parses the rest request on top of the SearchRequest, preserving values that are not overridden by the rest request.
 *
 * @param requestContentParser body of the request to read. This method does not attempt to read the body from the {@code request}
 *        parameter
 */
public static void parseSearchRequest(SearchRequest searchRequest, RestRequest request,
                                      XContentParser requestContentParser) throws IOException {

    if (searchRequest.source() == null) {
        searchRequest.source(new SearchSourceBuilder());
    }
    searchRequest.indices(Strings.splitStringByCommaToArray(request.param("index")));
    if (requestContentParser != null) {
        QueryParseContext context = new QueryParseContext(requestContentParser);
        searchRequest.source().parseXContent(context);
    }

    final int batchedReduceSize = request.paramAsInt("batched_reduce_size", searchRequest.getBatchedReduceSize());
    searchRequest.setBatchedReduceSize(batchedReduceSize);

    // do not allow 'query_and_fetch' or 'dfs_query_and_fetch' search types
    // from the REST layer. these modes are an internal optimization and should
    // not be specified explicitly by the user.
    String searchType = request.param("search_type");
    if ("query_and_fetch".equals(searchType) ||
            "dfs_query_and_fetch".equals(searchType)) {
        throw new IllegalArgumentException("Unsupported search type [" + searchType + "]");
    } else {
        searchRequest.searchType(searchType);
    }
    parseSearchSource(searchRequest.source(), request);
    searchRequest.requestCache(request.paramAsBoolean("request_cache", null));

    String scroll = request.param("scroll");
    if (scroll != null) {
        searchRequest.scroll(new Scroll(parseTimeValue(scroll, null, "scroll")));
    }

    searchRequest.types(Strings.splitStringByCommaToArray(request.param("type")));
    searchRequest.routing(request.param("routing"));
    searchRequest.preference(request.param("preference"));
    searchRequest.indicesOptions(IndicesOptions.fromRequest(request, searchRequest.indicesOptions()));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:45,代码来源:RestSearchAction.java

示例11: doCatRequest

import org.elasticsearch.action.search.SearchRequest; //导入方法依赖的package包/类
@Override
public RestChannelConsumer doCatRequest(final RestRequest request, final NodeClient client) {
    String[] indices = Strings.splitStringByCommaToArray(request.param("index"));
    SearchRequest countRequest = new SearchRequest(indices);
    SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder().size(0);
    countRequest.source(searchSourceBuilder);
    try {
        request.withContentOrSourceParamParserOrNull(parser -> {
            if (parser == null) {
                QueryBuilder queryBuilder = RestActions.urlParamsToQueryBuilder(request);
                if (queryBuilder != null) {
                    searchSourceBuilder.query(queryBuilder);
                }
            } else {
                searchSourceBuilder.query(RestActions.getQueryContent(parser));
            }
        });
    } catch (IOException e) {
        throw new ElasticsearchException("Couldn't parse query", e);
    }
    return channel -> client.search(countRequest, new RestResponseListener<SearchResponse>(channel) {
        @Override
        public RestResponse buildResponse(SearchResponse countResponse) throws Exception {
            return RestTable.buildResponse(buildTable(request, countResponse), channel);
        }
    });
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:28,代码来源:RestCountAction.java

示例12: AbstractBulkByScrollRequest

import org.elasticsearch.action.search.SearchRequest; //导入方法依赖的package包/类
/**
 * Constructor for actual use.
 *
 * @param searchRequest the search request to execute to get the documents to process
 * @param setDefaults should this request set the defaults on the search request? Usually set to true but leave it false to support
 *        request slicing
 */
public AbstractBulkByScrollRequest(SearchRequest searchRequest, boolean setDefaults) {
    this.searchRequest = searchRequest;

    // Set the defaults which differ from SearchRequest's defaults.
    if (setDefaults) {
        searchRequest.scroll(DEFAULT_SCROLL_TIMEOUT);
        searchRequest.source(new SearchSourceBuilder());
        searchRequest.source().size(DEFAULT_SCROLL_SIZE);
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:18,代码来源:AbstractBulkByScrollRequest.java

示例13: sliceIntoSubRequests

import org.elasticsearch.action.search.SearchRequest; //导入方法依赖的package包/类
/**
 * Slice a search request into {@code times} separate search requests slicing on {@code field}. Note that the slices are *shallow*
 * copies of this request so don't change them.
 */
static SearchRequest[] sliceIntoSubRequests(SearchRequest request, String field, int times) {
    SearchRequest[] slices = new SearchRequest[times];
    for (int slice = 0; slice < times; slice++) {
        SliceBuilder sliceBuilder = new SliceBuilder(field, slice, times);
        SearchSourceBuilder slicedSource;
        if (request.source() == null) {
            slicedSource = new SearchSourceBuilder().slice(sliceBuilder);
        } else {
            if (request.source().slice() != null) {
                throw new IllegalStateException("Can't slice a request that already has a slice configuration");
            }
            slicedSource = request.source().copyWithNewSlice(sliceBuilder);
        }
        slices[slice] = new SearchRequest()
                .source(slicedSource)
                .searchType(request.searchType())
                .indices(request.indices())
                .types(request.types())
                .routing(request.routing())
                .preference(request.preference())
                .requestCache(request.requestCache())
                .scroll(request.scroll())
                .indicesOptions(request.indicesOptions());
    }
    return slices;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:31,代码来源:BulkByScrollParallelizationHelper.java

示例14: getShardDocNumByType

import org.elasticsearch.action.search.SearchRequest; //导入方法依赖的package包/类
public long getShardDocNumByType(String type) {
    String query = String.format(DOCNUM_QUERY_PATTERN, 1);
    SearchRequest searchRequest = generateLocalSearchRequest(query, shardId.getIndex(), type);
    ShardSearchLocalRequest request = new ShardSearchLocalRequest(shardId, 1, SearchType.QUERY_AND_FETCH,
            searchRequest.source(), searchRequest.types(), true);
    request.putHeader("search_source", "reindex");
    QueryFetchSearchResult result = shardSearchService.executeFetchPhase(request);
    return result.queryResult().topDocs().totalHits;
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:10,代码来源:IndexShard.java

示例15: generateLocalSearchRequest

import org.elasticsearch.action.search.SearchRequest; //导入方法依赖的package包/类
private static SearchRequest generateLocalSearchRequest(String source, String indexName, String type) {
    LocalRestRequest localRestRequest = new LocalRestRequest("/_search", Method.POST);
    localRestRequest.setContent(source, null);
    SearchRequest searchRequest = new SearchRequest();
    searchRequest.indices(Strings.splitStringByCommaToArray(indexName));
    // get the content, and put it in the body
    // add content/source as template if template flag is set
    searchRequest.source(localRestRequest.content());
    searchRequest.searchType(SearchType.QUERY_AND_FETCH);
    searchRequest.extraSource(RestSearchAction.parseSearchSource(localRestRequest));
    searchRequest.types(Strings.splitStringByCommaToArray(type));
    searchRequest.putHeader("search_source", "reindex");
    return searchRequest;
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:15,代码来源:IndexShard.java


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