Search API
search API允许执行搜索查询并返回匹配查询的搜索结果。它可以跨一个或多个索引和一个或多个类型执行。可以使用查询Java API提供查询。搜索请求的主体是使用SearchSourceBuilder构建的。举个例子:
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.action.search.SearchType;
import org.elasticsearch.index.query.QueryBuilders.*;
SearchResponse response = client.prepareSearch("index1", "index2")
.setTypes("type1", "type2")
.setSearchType(SearchType.DFS_QUERY_THEN_FETCH)
.setQuery(QueryBuilders.termQuery("multi", "test")) // Query
.setPostFilter(QueryBuilders.rangeQuery("age").from(12).to(18)) // Filter
.setFrom(0).setSize(60).setExplain(true)
.get();
注意,所有参数都是可选的。
// MatchAll on the whole cluster with all default options
SearchResponse response = client.prepareSearch().get();
虽然Java API定义了额外的搜索类型QUERY_AND_FETCH和DFS_QUERY_AND_FETCH,但是这些模式是内部优化,不应该由API的用户显式地指定。
» 订阅本站:https://www.kgraph.cn