1. 建立员工目录

ES数据库对象与关系型数据库对象对比

Relational DB -> Databases -> Tables -> Rows -> Columns
Elasticsearch -> Indices -> Types -> Documents -> Fields

语法

curl -X<VERB> '<PROTOCOL>://<HOST>/<PATH>?<QUERY_STRING>' -d '<BODY>'
  • VERB HTTP方法: GET , POST , PUT , HEAD , DELETE
  • PROTOCOL http或者https协议(只有在Elasticsearch前面有https代理的时候可用)
  • HOST Elasticsearch集群中的任何一个节点的主机名,如果是在本地的节点,那么就叫localhost
  • PORT Elasticsearch HTTP服务所在的端口,默认为9200
  • QUERY_STRING 一些可选的查询请求参数,例如 ?pretty 参数将使请求返回更加美观易读的JSON数据
  • BODY 一个JSON格式的请求主体(如果请求需要的话)
curl -XPUT "http://172.16.101.54:9200/megacorp/employee/1?pretty" -H 'Content-Type: application/json' -d '
{
"first_name" : "John",
"last_name" : "Smith",
"age" : ,
"about" : "I love to go rock climbing",
"interests" : [ "sports" , "music" ]
}
' curl -XPUT "http://172.16.101.54:9200/megacorp/employee/2?pretty" -H 'Content-Type: application/json' -d '
{
"first_name" : "Jane",
"last_name" : "Smith",
"age" : ,
"about" : "I like to collect rock albums",
"interests" : [ "music" ]
}
' curl -XPUT "http://172.16.101.54:9200/megacorp/employee/3?pretty" -H 'Content-Type: application/json' -d '
{
"first_name" : "Douglas",
"last_name" : "Fir",
"age" : ,
"about" : "I like to build cabinets",
"interests" : [ "forestry" ]
}
' $ curl -XGET "http://172.16.101.54:9200/_cat/indices?v"
health status index uuid pri rep docs.count docs.deleted store.size pri.store.size
yellow open megacorp GqtIJQM-RtiqJCxDtyj5Zg .8kb .8kb

2. 搜索文档

2.1 搜索单个文档内容

$ curl -XGET "http://172.16.101.54:9200/megacorp/employee/1?pretty"
{
"_index" : "megacorp",
"_type" : "employee",
"_id" : "",
"_version" : ,
"found" : true,
"_source" : {
"first_name" : "John",
"last_name" : "Smith",
"age" : ,
"about" : "I love to go rock climbing",
"interests" : [
"sports",
"music"
]
}
}

2.2 搜索全部文档内容

$ curl -XGET "http://172.16.101.54:9200/megacorp/employee/_search?pretty"
{
"took" : ,
"timed_out" : false,
"_shards" : {
"total" : ,
"successful" : ,
"failed" :
},
"hits" : {
"total" : ,
"max_score" : 1.0,
"hits" : [
{
"_index" : "megacorp",
"_type" : "employee",
"_id" : "",
"_score" : 1.0,
"_source" : {
"first_name" : "Jane",
"last_name" : "Smith",
"age" : ,
"about" : "I like to collect rock albums",
"interests" : [
"music"
]
}
},
{
"_index" : "megacorp",
"_type" : "employee",
"_id" : "",
"_score" : 1.0,
"_source" : {
"first_name" : "John",
"last_name" : "Smith",
"age" : ,
"about" : "I love to go rock climbing",
"interests" : [
"sports",
"music"
]
}
},
{
"_index" : "megacorp",
"_type" : "employee",
"_id" : "",
"_score" : 1.0,
"_source" : {
"first_name" : "Douglas",
"last_name" : "Fir",
"age" : ,
"about" : "I like to build cabinets",
"interests" : [
"forestry"
]
}
}
]
}
}

2.3 关键字查询

例如搜索员工姓氏中包含“Smith”的员工

$ curl -XGET "http://172.16.101.54:9200/megacorp/employee/_search?pretty=true&q=last_name:Smith"
{
"took" : ,
"timed_out" : false,
"_shards" : {
"total" : ,
"successful" : ,
"failed" :
},
"hits" : {
"total" : ,
"max_score" : 0.2876821,
"hits" : [
{
"_index" : "megacorp",
"_type" : "employee",
"_id" : "",
"_score" : 0.2876821,
"_source" : {
"first_name" : "Jane",
"last_name" : "Smith",
"age" : ,
"about" : "I like to collect rock albums",
"interests" : [
"music"
]
}
},
{
"_index" : "megacorp",
"_type" : "employee",
"_id" : "",
"_score" : 0.2876821,
"_source" : {
"first_name" : "John",
"last_name" : "Smith",
"age" : ,
"about" : "I love to go rock climbing",
"interests" : [
"sports",
"music"
]
}
}
]
}
}

采用DSL方式查询

$ curl -XGET 'http://172.16.101.54:9200/megacorp/employee/_search?pretty=true' -d '{
"query" : {
"query_string" : { "query" : "last_name:Smith" }
}
}
'
{
"took" : ,
"timed_out" : false,
"_shards" : {
"total" : ,
"successful" : ,
"failed" :
},
"hits" : {
"total" : ,
"max_score" : 0.2876821,
"hits" : [
{
"_index" : "megacorp",
"_type" : "employee",
"_id" : "",
"_score" : 0.2876821,
"_source" : {
"first_name" : "Jane",
"last_name" : "Smith",
"age" : ,
"about" : "I like to collect rock albums",
"interests" : [
"music"
]
}
},
{
"_index" : "megacorp",
"_type" : "employee",
"_id" : "",
"_score" : 0.2876821,
"_source" : {
"first_name" : "John",
"last_name" : "Smith",
"age" : ,
"about" : "I love to go rock climbing",
"interests" : [
"sports",
"music"
]
}
}
]
}
}
$ curl -XGET 'http://172.16.101.54:9200/megacorp/employee/_search?pretty=true' -d '{
"query" : {
"match" : { "last_name" : "Smith" }
}
}
'
{
"took" : ,
"timed_out" : false,
"_shards" : {
"total" : ,
"successful" : ,
"failed" :
},
"hits" : {
"total" : ,
"max_score" : 0.2876821,
"hits" : [
{
"_index" : "megacorp",
"_type" : "employee",
"_id" : "",
"_score" : 0.2876821,
"_source" : {
"first_name" : "Jane",
"last_name" : "Smith",
"age" : ,
"about" : "I like to collect rock albums",
"interests" : [
"music"
]
}
},
{
"_index" : "megacorp",
"_type" : "employee",
"_id" : "",
"_score" : 0.2876821,
"_source" : {
"first_name" : "John",
"last_name" : "Smith",
"age" : ,
"about" : "I love to go rock climbing",
"interests" : [
"sports",
"music"
]
}
}
]
}
}

Elasticsearch5.5通过案例学习简单操作的更多相关文章

  1. neo4j初次使用学习简单操作-cypher语言使用

    Neo4j 使用cypher语言进行操作 Cypher语言是在学习Neo4j时用到数据库操作语言(DML),涵盖对图数据的增删改查  neo4j数据库简单除暴理解的概念: Neo4j中不存在表的概念, ...

  2. GitHub学习心得之 简单操作

    作者:枫雪庭 出处:http://www.cnblogs.com/FengXueTing-px/ 欢迎转载 前言 本文对Github的基本操作进行了总结, 主要基于以下文章: http://gitre ...

  3. Visual Studio 2017中使用正则修改部分内容 如何使用ILAsm与ILDasm修改.Net exe(dll)文件 C#学习-图解教程(1):格式化数字字符串 小程序开发之图片转Base64(C#、.Net) jquery遍历table为每一个单元格取值及赋值 。net加密解密相关方法 .net关于坐标之间一些简单操作

    Visual Studio 2017中使用正则修改部分内容   最近在项目中想实现一个小工具,需要根据类的属性<summary>的内容加上相应的[Description]特性,需要实现的效 ...

  4. selenium webdriver学习(二)————对浏览器的简单操作(转载JARVI)

    selenium webdriver学习(二)————对浏览器的简单操作 博客分类: Selenium-webdriver   selenium webdriver对浏览器的简单操作 打开一个测试浏览 ...

  5. MongoDB快速入门学习笔记2 MongoDB的概念及简单操作

    1.以下列举普通的关系型数据库和MongoDB数据库简单概念上的区别: 关系型数据库 MongoDB数据库 说明 database database 数据库 table collection 数据库表 ...

  6. Storm入门2-单词计数案例学习

     [本篇文章主要是通过一个单词计数的案例学习,来加深对storm的基本概念的理解以及基本的开发流程和如何提交并运行一个拓扑] 单词计数拓扑WordCountTopology实现的基本功能就是不停地读入 ...

  7. 通过 Autostereograms 案例学习 OpenGL 和 OpenCL 的互操作性

    引言 在过去的十年里, GPU (图形处理单元)已经从特殊硬件(特供)转变成能够在数值计算领域开辟新篇章的高性能计算机设备. 很多算法能够使用拥有巨大的处理能力的GPU来快速运行和处理大数据量.即使在 ...

  8. ArcGIS案例学习笔记1_1

    ArcGIS案例学习笔记1_1 联系方式:谢老师,135_4855_4328, xiexiaokui#qq.com 时间:第一天上午 准备 0.U盘复制ArcGIS培训*** 1.练习数据不要放到桌面 ...

  9. MongoDB数据库简单操作

    之前学过的有mysql数据库,现在我们学习一种非关系型数据库 一.简介 MongoDB是一款强大.灵活.且易于扩展的通用型数据库 MongoDB 是由C++语言编写的,是一个基于分布式文件存储的开源数 ...

随机推荐

  1. Android字符串判断是否包含中文

    // 判断一个字符是否是中文 public boolean isChinese(char c) { return c >= 0x4E00 && c <= 0x9FA5;// ...

  2. XP支持AHCI硬盘工作模式

    故障 装XP系统后开启AHCI模式会出现开机蓝屏重启的问题,如何在XP下加载AHCI驱动,以便开启BIOS中AHCI选项来发挥硬盘的最佳性能. 问题分析XP系统无法直接支持AHCI硬盘高速模式,需要加 ...

  3. 【UML】NO.55.EBook.8.UML.3.001-【UML和模式应用 第3版】

    1.0.0 Summary Tittle:[UML]NO.54.EBook.8.UML.3.001-[UML和模式应用 第3版] Style:DesignPattern Series:DesignPa ...

  4. MySQL服务安全加固

    数据库管理人员可以参考本文档进行 MySQL 数据库系统的安全配置加固,提高数据库的安全性,确保数据库服务稳定.安全.可靠地运行. 漏洞发现 您可以使用安骑士企业版自动检测您的服务器上是否存在 MyS ...

  5. Python基础(十) __init__与__new__区别

    __init__与__new__区别: __init__在python,其实是,在实例化之后执行的,用来初始化一些属性,相当于构造函数,但是又不一样 细心一些,通过参数会有所发现,其实__init__ ...

  6. .NET Core 全新认识(转载)

    .NET Core 全新认识   cnblogs.com/yubinfeng/p/6626694.html 一.概述      .NET 经历14年,在Windows平台上的表现已经相当优秀,但是“跨 ...

  7. U盘安装Windows Server 2008 r2失败,改用磁盘安装

    一.使用UltraISO制作系统安装启动U盘提示错误“缺少所需的CD/DVD驱动器设备驱动程序.…………”试了各种方法都不能通过U盘进行安装. 二.直接使用磁盘安装0.使用PE先将磁盘格式化.分区.1 ...

  8. 抓包工具 GOOGLE

    chrome://net-internals/#events GOOGLE浏览器直接输入

  9. 【Spark-core学习之五】 RDD宽窄依赖 & Stage

    环境 虚拟机:VMware 10 Linux版本:CentOS-6.5-x86_64 客户端:Xshell4 FTP:Xftp4 jdk1.8 scala-2.10.4(依赖jdk1.8) spark ...

  10. John Deere Service Advisor EDL V2 Diagnostic Kit

    Support Languages: English, French, German, Italian, Portuguese, Russian, Spanish. John Deere Servic ...