刚接触 es,目前使用 7.0 版本 在查阅最新的 api 时,没找到哪个方法可以设置 type
SearchRequest searchRequest = new SearchRequest();
searchRequest.indices("post");
searchRequest.types("doc"); //该方法已经被废弃
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
searchSourceBuilder.query(QueryBuilders.termQuery("ap", "3500"));
searchSourceBuilder.timeout(new TimeValue(60, TimeUnit.SECONDS));
searchRequest.source(searchSourceBuilder);
SearchResponse request = client.search(searchRequest, RequestOptions.DEFAULT);
不管是否使用 searchRequest.types("doc");设置 type 最后都可以正常返回结果,但同时还是会抛如下异常: “ org.elasticsearch.action.ActionRequestValidationException: Validation Failed: 1: index is missing;2: source is missing;3: content type is missing;”
1
fishioon 2019-04-24 17:32:52 +08:00
新版本 type 已经被废弃了
|
2
freebird1994 2019-04-24 17:49:14 +08:00
SearchRequest searchRequest = new SearchRequest(index).types(type).source(sourceBuilder);
|