• 012-elasticsearch5.4.3【五】-搜索API【一】搜索匹配所有matchAllQuery、全文查询[matchQuery、multiMatchQuery、commonTermsQuery、queryStringQuery、simpleQueryStringQuery]


    一、概述

      查询所使用的 QueryBuilders来源于以下

    import static org.elasticsearch.index.query.QueryBuilders.*;

      请注意,您可以使用QueryBuilder对象上的toString()方法轻松打印(也称为调试)JSON生成的查询。

    1.1、匹配所有

      最简单的查询,匹配所有文档,给它们一个_score 1.0。

    QueryBuilder qb = matchAllQuery();

    1.2、全文查询

      高级全文查询通常用于在全文字段(如电子邮件正文)上运行全文查询。他们了解如何分析被查询的字段,并在执行之前将每个字段的分析器(或search_analyzer)应用于查询字符串。

      该组中的查询是:

    1)匹配查询:用于执行全文查询的标准查询,包括模糊匹配和短语或邻近查询。//查询出包含 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}

    2)多匹配查询: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":"王五"}

    3)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}

    4)query_string查询:支持紧凑的Lucene查询字符串语法,允许您在单个查询字符串中指定AND | OR | NOT条件和多字段搜索。仅限专家用户。

    QueryBuilder qb = queryStringQuery("+kimchy -elasticsearch"); //value

    5)simple_query_string:query_string语法的更简单,更健壮的版本,适合直接向用户公开。

    QueryBuilder qb = simpleQueryStringQuery("+kimchy -elasticsearch");//value

    github:https://github.com/bjlhx15/spring-cloud-base/tree/master/service6-es 

  • 相关阅读:
    [CocosCreator]-06-文字渲染
    [CocosCreator]-05-图片渲染
    [CocosCreator]-04-使用对象池
    [CocosCreator]-03-使用计时器
    [CocosCreator]-02-设备重力传感事件
    [CocosCreator]-01-键盘事件
    [h5棋牌项目]-08-请安装所需的版本的 Windows SDK 或者在项目属性页的问题解决方案
    JS规则 较量较量(比较操作符) 两个操作数通过比较操作符进行比较,得到值为真(true)和假(false)。【>; <; >=; <=; !=;==】
    JS规则 自加一,自减一 ( ++和- -) 【mynum = mynum + 1;//等同于mynum++;】
    JS规则 我还有其它用途( +号操作符)例如,算术操作符(+、-、*、/等),比较操作符(<、>、>=、<=等),逻辑操作符(&&、||、!)
  • 原文地址:https://www.cnblogs.com/bjlhx/p/8514299.html
Copyright © 2020-2023  润新知