- 不能用通配符, 不知道干啥用
*/
@Test
public void testFuzzyQuery() {
QueryBuilder queryBuilder = QueryBuilders.fuzzyQuery(“user”, “kimch”);
searchFunction(queryBuilder);
}
/**
- 父或子的文档查询
*/
@Test
public void testChildQuery() {
QueryBuilder queryBuilder = QueryBuilders.hasChildQuery(“sonDoc”, QueryBuilders.termQuery(“name”, “vini”));
searchFunction(queryBuilder);
}
/**
-
moreLikeThisQuery: 实现基于内容推荐, 支持实现一句话相似文章查询
-
{
“more_like_this” : {
“fields” : [“title”, “content”], // 要匹配的字段, 不填默认_all
“like_text” : “text like this one”, // 匹配的文本
}
}
percent_terms_to_match:匹配项(term)的百分比,默认是0.3
min_term_freq:一篇文档中一个词语至少出现次数,小于这个值的词将被忽略,默认是2
max_query_terms:一条查询语句中允许最多查询词语的个数,默认是25
stop_words:设置停止词,匹配时会忽略停止词
min_doc_freq:一个词语最少在多少篇文档中出现,小于这个值的词会将被忽略,默认是无限制
max_doc_freq:一个词语最多在多少篇文档中出现,大于这个值的词会将被忽略,默认是无限制
min_word_len:最小的词语长度,默认是0
max_word_len:最多的词语长度,默认无限制
boost_terms:设置词语权重,默认是1
boost:设置查询权重,默认是1
analyzer:设置使用的分词器,默认是使用该字段指定的分词器
*/
@Test
public void testMoreLikeThisQuery() {
QueryBuilder queryBuilder = QueryBuilders.moreLikeThisQuery(“user”)
.like(“kimchy”);
// .minTermFreq(1) //最少出现的次数
// .maxQueryTerms(12); // 最多允许查询的词语
searchFunction(queryBuilder);
}
/**
- 前缀查询
*/
@Test
public void testPrefixQuery() {
QueryBuilder queryBuilder = QueryBuilders.matchQuery(“user”, “kimchy”);
searchFunction(queryBuilder);
}
/**
- 查询解析查询字符串
*/
@Test
public void testQueryString() {
QueryBuilder queryBuilder = QueryBuilders.queryStringQuery(“+kimchy”);
searchFunction(queryBuilder);
}
/**
- 范围内查询
*/
public void testRangeQuery() {
QueryBuilder queryBuilder = QueryBuilders.rangeQuery(“user”)
.from(“kimchy”)
.to(“wenbronk”)
.includeLower(true) // 包含上界
.includeUpper(true); // 包含下届
searchFunction(queryBuilder);
}
/**
- 跨度查询
*/
@Test
public void testSpanQueries() {
QueryBuilder queryBuilder1 = QueryBuilders.spanFirstQuery(QueryBuilders.spanTermQuery(“name”, “葫芦580娃”), 30000); // Max查询范围的结束位置
QueryBuilder queryBuilder2 = QueryBuilders.spanNearQuery()
.clause(QueryBuilders.spanTermQuery(“name”, “葫芦580娃”)) // Span Term Queries
.clause(QueryBuilders.spanTermQuery(“name”, “葫芦3812娃”))
.clause(QueryBuilders.spanTermQuery(“name”, “葫芦7139娃”))
.slop(30000) // Slop factor
.inOrder(false)
.collectPayloads(false);
// Span Not
QueryBuilder queryBuilder3 = QueryBuilders.spanNotQuery()
.include(QueryBuilders.spanTermQuery(“name”, “葫芦580娃”))
.exclude(QueryBuilders.spanTermQuery(“home”, “山西省太原市2552街道”));
// Span Or
QueryBuilder queryBuilder4 = QueryBuilders.spanOrQuery()
.clause(QueryBuilders.spanTermQuery(“name”, “葫芦580娃”))
.clause(QueryBuilders.spanTermQuery(“name”, “葫芦3812娃”))
.clause(QueryBuilders.spanTermQuery(“name”, “葫芦7139娃”));
// Span Term
QueryBuilder queryBuilder5 = QueryBuilders.spanTermQuery(“name”, “葫芦580娃”);
}
/**
- 测试子查询
*/
@Test
public void testTopChildrenQuery() {
QueryBuilders.hasChildQuery(“tweet”,
QueryBuilders.termQuery(“user”, “kimchy”))
.scoreMode(“max”);
}
/**
-
通配符查询, 支持 *
-
匹配任何字符序列, 包括空
-
避免* 开始, 会检索大量内容造成效率缓慢
*/
@Test
public void te