实时搜索引擎Elasticsearch(3)——查询API的使用

上一篇文章介绍了ES中的Rest API,本章将重点介绍ES中的查询API的使用。由于笔者在实际项目仅仅将ES用作索引数据库,并没有深入研究过ES的搜索功能。而且鉴于笔者的搜索引擎知识有限,本文将仅仅介绍ES简单(非全文)的查询API。

笔者原本打算在本文中介绍聚合API的内容,但是写着写着发现文章有点过长,不便于阅读,故将聚合API的内容移至下一篇博客中。

引言

单单介绍理论和API是乏味和低效率的,本文将结合一个实际的例子来介绍这些API。下表是本文数据表的表结构,表名(type)为“student”。注意,studentNo是本表的id,也就是_id字段的值与studentNo的值保持一致。

字段名 字段含义 类型 是否能被索引 备注
studentNo 学号 string id
name 姓名 string
sex 性别 string
age 年龄 integer
birthday 出生年月 date
address 家庭住址 string
classNo 班级 string
isLeader 是否为班干部 boolean

上面的表结构所对应的mapping如下,将数据保存在索引名为“student”的索引中。

{
  "student": {
    "properties": {
      "studentNo": {
        "type": "string",
        "index": "not_analyzed"
      },
      "name": {
        "type": "string",
        "index": "not_analyzed"
      },
      "male": {
        "type": "string",
        "index": "not_analyzed"
      },
      "age": {
        "type": "integer"
      },
      "birthday": {
        "type": "date",
        "format": "yyyy-MM-dd"
      },
      "address": {
        "type": "string",
        "index": "not_analyzed"
      },
      "classNo": {
        "type": "string",
        "index": "not_analyzed "
      },
      "isLeader": {
        "type": "boolean"
      }
    }
  }
}

索引中保存的数据如下,下面介绍的所有API都将基于这个数据表。

studentNo name male age birthday classNo address isLeader
1 刘备 24 1985-02-03 1 湖南省长沙市 true
2 关羽 22 1987-08-23 2 四川省成都市 false
3 糜夫人 19 1990-06-12 1 上海市 false
4
  • 12
    点赞
  • 35
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值