es 全文查询
搜索匹配所有matchAllQuery、全文查询[matchQuery、multiMatchQuery、commonTerms...
- 匹配所有
最简单的查询,匹配所有文档,给它们一个_score 1.0。
QueryBuilder qb = matchAllQuery();
- 匹配查询:用于执行全文查询的标准查询,包括模糊匹配和短语或邻近查询。//查询出包含 value 的数据 或者包含不连续的字符
QueryBuilder qb = matchQuery("field","value" ); 示例:查询:QueryBuilder qb = matchQuery("name", "张三"); 结果 数据:{"address":"benjing","age":"12","name":"张三2"} 数据:{"address":"benjing","age":"12","name":"aa张三3","num":12} 数据:{"address":"benjing","age":"12","name":"张爱三","num":12} 数据:{"address":"benjing","age":"12","name":"张三3"} 数据:{"address":"benjing","age":"12","name":"李宏旭 张三3","num":12} 数据:{"address":"benjing","age":"12","name":"张四","num":12}
- 多匹配查询:multi_match查询,匹配查询的多字段版
QueryBuilder qb = multiMatchQuery(
"kimchy elasticsearch", //值
"user", "message" //字段
);
示例:查询:QueryBuilder qb = multiMatchQuery("张三 12", "name","age");
结果
数据:{"address":"benjing","age":"1","name":"张三"}
数据:{"address":"benjing","age":"12","name":"张三2"}
数据:{"address":"benjing","age":"12","name":"aa张三3","num":12}
数据:{"address":"benjing","age":"12","name":"张爱三","num":12}
数据:{"address":"benjing","age":"12","name":"张三3"}
数据:{"address":"benjing","age":"12","name":"李宏旭 张三3","num":12}
数据:{"address":"benjing","age":"12","name":"王五","num":3}
数据:{"address":"benjing","age":"12","name":"张四","num":12}
数据:{"address":"benjing","age":"12","name":"王五"}
-
common_terms查询:一个更专业的查询,它提供了对不常见单词的更多偏好
QueryBuilder qb = commonTermsQuery("field","value");
示例:查询:QueryBuilder qb = commonTermsQuery("name", "张三");
结果:
数据:{"address":"benjing","age":"1","name":"张三"}
数据:{"address":"benjing","age":"12","name":"张三2"}
数据:{"address":"benjing","age":"12","name":"aa张三3","num":12}
数据:{"address":"benjing","age":"12","name":"张爱三","num":12}
数据:{"address":"benjing","age":"12","name":"张三3"}
数据:{"address":"benjing","age":"12","name":"李宏旭 张三3","num":12}
-
query_string查询:支持紧凑的Lucene查询字符串语法,允许您在单个查询字符串中指定AND | OR | NOT条件和多字段搜索。仅限专家用户
QueryBuilder qb = queryStringQuery("+kimchy -elasticsearch"); //value
-
simple_query_string:query_string语法的更简单,更健壮的版本,适合直接向用户公开
QueryBuilder qb = simpleQueryStringQuery("+kimchy -elasticsearch");//value
故乡明