• URI Search


    前言

    以movies结果集作为查询数据。
    可以参考我的文章 《使用 movielens + logstash 给 elasticsearch导入测试数据》。
    语句是在kibana中运行的

    URI

    即通过url的方式进行数据查询

    基本参数

    movies 代表索引
    _search 代表对索引进行查询
    q 查询条件 title:Beautiful title中包含 Beautiful
    from 数据偏移量 等价mysql offset
    size 每页显示条数 等价mysql limit
    sort 排序 year:desc 安装year desc 排
    profile true 显示查询过程

    GET /movies/_search?q=title:Beautiful&from=0&size=10&sort=year:desc
    {
      "profile": "true"
    }
    
    • 1
    • 2
    • 3
    • 4

    如果要求的是任意一个字段包含Beautiful就可以,那么去掉title就像了,默认泛查询

    GET /movies/_search?q=Beautiful&from=0&size=10&sort=year:desc
    
    • 1

    同一个查询条件在不同情况下的查询范围

    查询条件为 Beautiful Mind

    a.没有引号和()的情况下,查询的结果集由title包含Beautiful的结果集 + 某个字段包含Mind的结果集构成。也就是说对于Mind是泛查

    GET /movies/_search?q=title:Beautiful Mind
    {
      "profile": "true"
    }
    
    • 1
    • 2
    • 3
    • 4

    b.在有引号的情况下,返回的结果集title必须包含 Beautiful Mind

    GET /movies/_search?q=title:"Beautiful Mind"
    {
      "profile": "true"
    }
    
    • 1
    • 2
    • 3
    • 4

    c.在有()的情况下,返回的结果集由 title包含Beautiful的结果集 + title包含Mind的结果集构成

    GET /movies/_search?q=title:(Beautiful Mind)
    {
      "profile": "true"
    }
    
    • 1
    • 2
    • 3
    • 4

    提供了一些操作符

    AND

    要求必须包含Beautiful Mind

    GET /movies/_search?q=title:(Beautiful AND Mind)
    {
      "profile": "true"
    }
    
    • 1
    • 2
    • 3
    • 4
    OR

    包含Beautiful 或者 包含 Mind

    GET /movies/_search?q=title:(Beautiful OR Mind)
    {
      "profile": "true"
    }
    
    • 1
    • 2
    • 3
    • 4
    +

    必须有的意思,在url中 %2B 代表+号
    结果集由a,b两部分组成
    a:title包含Mind的部分
    b:title包含:Beautiful Mind 的部分(要求存在Beautiful 则必须有Mind)

    GET /movies/_search?q=title:(Beautiful %2BMind)
    {
      "profile": "true"
    }
    
    • 1
    • 2
    • 3
    • 4
    -

    必须没有的意思

    包含Beautiful 不包含 Mind

    GET /movies/_search?q=title:(Beautiful -Mind)
    {
      "profile": "true"
    }
    
    • 1
    • 2
    • 3
    • 4

    找电影,除了2018年的电影

    GET /movies/_search?q=year:(-2018)
    {
      "profile": "true"
    }
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    范围查询

    这里以>为例,还有(>=,<,<=),不等于用-
    查找2018年以后的电影

    GET /movies/_search?q=year:>2018
    
    • 1
    正则查找

    查找包含b开头词的电影

    GET /movies/_search?q=title:b*
    {
      "profile": "true"
    }
    
    • 1
    • 2
    • 3
    • 4

    类似于mysql的模糊查询,但又不同

    Bautiful~1有两种意思:
    a.Bautiful 中可能在某个位置缺少一个字母,需补充(可以补充成为 Beautiful)
    b.Bautiful 中可能在某个位置字母错了,需替换(可以替换成为 Biutiful)
    返回的结果集包含补充过,替换过的内容

    GET /movies/_search?q=title:Bautiful~1
    {
      "profile": "true"
    }
    
    • 1
    • 2
    • 3
    • 4

    加上双引号修饰后变成Lord Rings 两个单词之间可以缺少最多两个词,可以匹配 Lord of the Rings

    GET /movies/_search?q=title:"Lord Rings"~2
    {
      "profile": "true"
    }
    
    • 1
    • 2
    • 3
    • 4
  • 相关阅读:
    PocSuite 工具使用介绍和sqlmap工具使用介绍
    火山引擎边缘云助力智能科技赋予生活更多新意
    MySQL 基础篇(第04话):mysqld 和 mysql 命令的区别
    Node学习七 —— 创建和控制外部进程
    Ubuntu 23.10/24.04 LTS 放弃默认使用 snap 版 CUPS 打印堆栈
    Redis字典实现
    杨氏矩阵/杨图x杨表(知识点总结)
    SpringBoot教程五配置Mysql使用Mybatis-plus
    关于在Linux服务上安装nvm,踩坑步骤说明
    【路径规划-TSP问题】基于遗传算法求解旅行商问题附matlab代码
  • 原文地址:https://blog.csdn.net/qq_29744347/article/details/126499962