本文整理汇总了Java中org.elasticsearch.action.search.SearchRequest.indices方法的典型用法代码示例。如果您正苦于以下问题:Java SearchRequest.indices方法的具体用法?Java SearchRequest.indices怎么用?Java SearchRequest.indices使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.elasticsearch.action.search.SearchRequest
的用法示例。
在下文中一共展示了SearchRequest.indices方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例2: testTemplateQueryAsEscapedStringStartingWithConditionalClause
import org.elasticsearch.action.search.SearchRequest; //导入方法依赖的package包/类
/**
* Test that template can contain conditional clause. In this case it is at
* the beginning of the string.
*/
public void testTemplateQueryAsEscapedStringStartingWithConditionalClause() throws Exception {
SearchRequest searchRequest = new SearchRequest();
searchRequest.indices("_all");
String templateString =
"{"
+ " \"inline\" : \"{ {{#use_size}} \\\"size\\\": \\\"{{size}}\\\", {{/use_size}} \\\"query\\\":{\\\"match_all\\\":{}}}\","
+ " \"params\":{"
+ " \"size\": 1,"
+ " \"use_size\": true"
+ " }"
+ "}";
SearchTemplateRequest request = RestSearchTemplateAction.parse(createParser(JsonXContent.jsonXContent, templateString));
request.setRequest(searchRequest);
SearchTemplateResponse searchResponse = client().execute(SearchTemplateAction.INSTANCE, request).get();
assertThat(searchResponse.getResponse().getHits().getHits().length, equalTo(1));
}
示例3: testSearchRequestFail
import org.elasticsearch.action.search.SearchRequest; //导入方法依赖的package包/类
public void testSearchRequestFail() throws Exception {
String query = "{ \"query\": {\"match_all\": {}}, \"size\" : \"{{my_size}}\" }";
SearchRequest searchRequest = new SearchRequest();
searchRequest.indices("_all");
expectThrows(Exception.class, () -> new SearchTemplateRequestBuilder(client())
.setRequest(searchRequest)
.setScript(query)
.setScriptType(ScriptType.INLINE)
.setScriptParams(randomBoolean() ? null : Collections.emptyMap())
.get());
SearchTemplateResponse searchResponse = new SearchTemplateRequestBuilder(client())
.setRequest(searchRequest)
.setScript(query)
.setScriptType(ScriptType.INLINE)
.setScriptParams(Collections.singletonMap("my_size", 1))
.get();
assertThat(searchResponse.getResponse().getHits().getHits().length, equalTo(1));
}
示例4: 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;
}
示例5: testTemplateQueryAsEscapedStringWithConditionalClauseAtEnd
import org.elasticsearch.action.search.SearchRequest; //导入方法依赖的package包/类
/**
* Test that template can contain conditional clause. In this case it is at
* the end of the string.
*/
public void testTemplateQueryAsEscapedStringWithConditionalClauseAtEnd() throws Exception {
SearchRequest searchRequest = new SearchRequest();
searchRequest.indices("_all");
String templateString =
"{"
+ " \"inline\" : \"{ \\\"query\\\":{\\\"match_all\\\":{}} {{#use_size}}, \\\"size\\\": \\\"{{size}}\\\" {{/use_size}} }\","
+ " \"params\":{"
+ " \"size\": 1,"
+ " \"use_size\": true"
+ " }"
+ "}";
SearchTemplateRequest request = RestSearchTemplateAction.parse(createParser(JsonXContent.jsonXContent, templateString));
request.setRequest(searchRequest);
SearchTemplateResponse searchResponse = client().execute(SearchTemplateAction.INSTANCE, request).get();
assertThat(searchResponse.getResponse().getHits().getHits().length, equalTo(1));
}
示例6: 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;
}
示例7: 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();
}
}
示例8: testTemplateQueryAsEscapedString
import org.elasticsearch.action.search.SearchRequest; //导入方法依赖的package包/类
/**
* Test that template can be expressed as a single escaped string.
*/
public void testTemplateQueryAsEscapedString() throws Exception {
SearchRequest searchRequest = new SearchRequest();
searchRequest.indices("_all");
String query =
"{" + " \"inline\" : \"{ \\\"size\\\": \\\"{{size}}\\\", \\\"query\\\":{\\\"match_all\\\":{}}}\","
+ " \"params\":{"
+ " \"size\": 1"
+ " }"
+ "}";
SearchTemplateRequest request = RestSearchTemplateAction.parse(createParser(JsonXContent.jsonXContent, query));
request.setRequest(searchRequest);
SearchTemplateResponse searchResponse = client().execute(SearchTemplateAction.INSTANCE, request).get();
assertThat(searchResponse.getResponse().getHits().getHits().length, equalTo(1));
}
示例9: testIntialSearchPath
import org.elasticsearch.action.search.SearchRequest; //导入方法依赖的package包/类
public void testIntialSearchPath() {
SearchRequest searchRequest = new SearchRequest().source(new SearchSourceBuilder());
assertEquals("/_search", initialSearchPath(searchRequest));
searchRequest.indices("a");
searchRequest.types("b");
assertEquals("/a/b/_search", initialSearchPath(searchRequest));
searchRequest.indices("a", "b");
searchRequest.types("c", "d");
assertEquals("/a,b/c,d/_search", initialSearchPath(searchRequest));
searchRequest.indices("cat,");
expectBadStartRequest(searchRequest, "Index", ",", "cat,");
searchRequest.indices("cat,", "dog");
expectBadStartRequest(searchRequest, "Index", ",", "cat,");
searchRequest.indices("dog", "cat,");
expectBadStartRequest(searchRequest, "Index", ",", "cat,");
searchRequest.indices("cat/");
expectBadStartRequest(searchRequest, "Index", "/", "cat/");
searchRequest.indices("cat/", "dog");
expectBadStartRequest(searchRequest, "Index", "/", "cat/");
searchRequest.indices("dog", "cat/");
expectBadStartRequest(searchRequest, "Index", "/", "cat/");
searchRequest.indices("ok");
searchRequest.types("cat,");
expectBadStartRequest(searchRequest, "Type", ",", "cat,");
searchRequest.types("cat,", "dog");
expectBadStartRequest(searchRequest, "Type", ",", "cat,");
searchRequest.types("dog", "cat,");
expectBadStartRequest(searchRequest, "Type", ",", "cat,");
searchRequest.types("cat/");
expectBadStartRequest(searchRequest, "Type", "/", "cat/");
searchRequest.types("cat/", "dog");
expectBadStartRequest(searchRequest, "Type", "/", "cat/");
searchRequest.types("dog", "cat/");
expectBadStartRequest(searchRequest, "Type", "/", "cat/");
}
示例10: 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;
}
示例11: 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()));
}
示例12: copyRequest
import org.elasticsearch.action.search.SearchRequest; //导入方法依赖的package包/类
private static SearchRequest copyRequest(SearchRequest searchRequest) throws IOException {
SearchRequest result = new SearchRequest();
result.indices(searchRequest.indices());
result.indicesOptions(searchRequest.indicesOptions());
result.types(searchRequest.types());
result.searchType(searchRequest.searchType());
result.preference(searchRequest.preference());
result.routing(searchRequest.routing());
result.requestCache(searchRequest.requestCache());
result.scroll(searchRequest.scroll());
if (searchRequest.source() != null) {
result.source(searchRequest.source());
}
return result;
}
示例13: 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;
}
示例14: parseSearchRequest
import org.elasticsearch.action.search.SearchRequest; //导入方法依赖的package包/类
public static void parseSearchRequest(SearchRequest searchRequest, RestRequest request, ParseFieldMatcher parseFieldMatcher,
BytesReference bodyContent) {
searchRequest.indices(Strings.splitStringByCommaToArray(request.param("index")));
// get the content, and put it in the body
// add content/source as template if template flag is set
boolean isTemplateRequest = request.path().endsWith("/template");
if (bodyContent == null) {
if (RestActions.hasBodyContent(request)) {
bodyContent = RestActions.getRestContent(request);
}
}
if (bodyContent != null) {
if (isTemplateRequest) {
searchRequest.templateSource(bodyContent);
} else {
searchRequest.source(bodyContent);
}
}
// 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 (SearchType.fromString(searchType, parseFieldMatcher).equals(SearchType.QUERY_AND_FETCH) ||
SearchType.fromString(searchType, parseFieldMatcher).equals(SearchType.DFS_QUERY_AND_FETCH)) {
throw new IllegalArgumentException("Unsupported search type [" + searchType + "]");
} else {
searchRequest.searchType(searchType);
}
searchRequest.extraSource(parseSearchSource(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()));
}