• Elasticsearch Search API说明


    一、Search API分类

    二、URI search 查询说明


    一、Search API分类

            Elasticsearch中 Search API分为 Search URI 和Request Body Search

            简单来说: Search URI就是在URL中使用查询参数,而Request Body Search则是基于Elasticsearch提供的JSON格式的查询方式

    二、Search URI 查询说明

            简单使用:

     /_search                                 集群上所有的索引
    index1/_search  index1           index1索引
    index1,index2/_search            index1和index2索引
    index*/_search                        以index开头      

     URI查询关键:使用q指定要查询的字符串

    curl -XGET "http://192.168.161.118:9200/kibana_sample_data_ecommerce/_search?q=customer_first_name:Selena"

    说明:索引为kibana_sample_data_ecommerce,查询的字段为customer_first_name,值为:Selena

     案例: curl -XGET http://192.168.161.118:9200/_search?q=2012&df=title&sort=year:desc&from=0&size=10&timeout=1s
    q: 指定查询语句
    df: 默认字段。不指定时,会对所有的字段进行查询
    sort: 排序。 
    from: 用于分页

    profile用于查看elasticsearch的查询过程

     案例:
    //URI查询,指定字段
    GET movies/_search?q=2010&df=title
    {
      "profile": "true"
    }

    //泛查询 不指定字段,意味是所有的字段
    GET movies/_search?q=2012
    {
      "profile": "true"
    }

    //不使用df字段,对指定字段进行查询
    GET movies/_search?q=title:2012
    {
      "profile": "true"
    }

     term Query

      //term query 表示的是OR关系
    GET movies/_search?q=title:Beautiful Mind
    {
      "profile": "true"
    }

     phrase Query

    //phrase query:表示是AND关系,且有前后顺序
    GET movies/_search?q=title:"Beautiful Mind"
    {
      "profile": "true"
    }

      布尔操作


    AND 
    OR 
    NOT
    说明: 必须大写
    分组:
    +: must
    -: must not

    案例:

    //
    GET movies/_search?q=title:(Beautiful AND  Mind)
    {
      "profile": "true"
    }

     范围查询

     范围查询
    区间表示: []闭合区间 {} 开区间
    year: {2019 TO 2018}
    year: {* TO 2020}

    //时间范围演示
    GET movies/_search?q=year:>=1990
    {
      "profile": "true"
    }
     

    数学运算

    数学运算符
    year:>2000
    year:(>2010 && <2018)
    year:(+>2010 +<=2018) 

    案例:

    GET movies/_search?q=year:>=1990
    {
      "profile": "true"
    }

     通配符

    ?代表1个字符
     * 代表0或多个字符

    //通配符查询:title中包含c字母
    GET movies/_search?q=title:c*
    {
      "profile": "true"
    }

    Request Body Search

     同时支持POST和GET查询方式

    curl -XGET "http://192.168.161.118:9200/kibana_sample_data_ecommerce/_search" -H 'Content-Type: application/json' -d '{"query": {"match_all": {}}}' 

     

  • 相关阅读:
    如何给API签名
    .net framework、.net standard、 .net core .net 5/6 区别
    【洛谷 P1115】最大子段和 题解(贪心算法)
    flink集群搭建
    Golang入门:协程(goroutine)
    [论文笔记]Sentence-BERT[v2]
    基于像素预测和位平面压缩的加密图像可逆数据隐藏附matlab代码(论文复现)
    计算机毕业设计Java艾灸减肥管理网站(源码+系统+mysql数据库+lw文档)
    水平居中元素
    计算机视觉算法——DETR / Deformable DETR / DETR 3D
  • 原文地址:https://blog.csdn.net/weixin_41910699/article/details/127839577