public static void termQuery(Client client, String index, String type) {
// Query
QueryBuilder queryBuilder = QueryBuilders.termQuery("college", "计算机学院");
// Search
SearchRequestBuilder searchRequestBuilder = client.prepareSearch(index);
searchRequestBuilder.setTypes(type);
searchRequestBuilder.setQuery(queryBuilder);
// 执行
SearchResponse searchResponse = searchRequestBuilder.execute().actionGet();
// 结果
queryResult(searchResponse);
}
搜索college为计算机学院 原始数据中有,却搜不到结果
原始数据:
11:34:22.674 [main] INFO com.sjf.open.api.Search - ----------hit source: id 9 source {college=计算机学院, school=西安电子科技大学, sex=boy, name=廖力生, age=21}
11:34:22.677 [main] INFO com.sjf.open.api.Search - ----------hit source: id 2 source {college=通信学院, school=西安电子科技大学, sex=boy, name=李源一, age=19}
11:34:22.677 [main] INFO com.sjf.open.api.Search - ----------hit source: id 4 source {college=电子工程学院, school=中国科技大学, sex=girl, name=王俊辉, age=21}
11:34:22.678 [main] INFO com.sjf.open.api.Search - ----------hit source: id 1 source {college=计算机学院, school=西安电子科技大学, sex=boy, name=徐欣, age=21}
11:34:22.678 [main] INFO com.sjf.open.api.Search - ----------hit source: id 3 source {college=电子工程学院, school=西安电子科技大学, sex=boy, name=陈哲超, age=18}