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. 3、Finished with error: FormatException: Bad UTF-8 encoding 0xc3 (at offset 169)

    这是由于 app 的版本为 release 找不到 keystore 文件, 我们只需要在 app 下的 build.gradle 文件中修改为 signingConfigs.debug 即可: bu ...

  2. 极验验证使用-滑动&选字验证码

    准备 SDK下载 首先在极验官网下载好SDK,附上官网链接,点此可直接下载python版zip包. 模块安装 使用该SDK时发现它依赖两个模块,分别是geetest和requests. pip ins ...

  3. 关于${pageContext.request.contextPath}的理解 (转载)

    ${pageContext.request.contextPath}是JSP取得绝对路径的方法,等价于<%=request.getContextPath()%> . 也就是取出部署的应用程 ...

  4. react 中的return 什么时候用小括号,什么时候用大括号啊

    return( <div>....</div> ) return( <Component/> ) return{...} 1:html 2:react 组件 3:j ...

  5. Fluxion无线攻击

    使用步骤 github地址 https://github.com/deltaxflux/fluxion 进入到fluxion目录下 ./fluxion 启动fluxion  启动之后会先检测没有安装的 ...

  6. Vue系列之 => computed实现求值

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name ...

  7. python头部 #!/usr/bin/env python

    *.py运行: python *.py OR ./*.py 对于*.py其首行应标明 #!/usr/bin/env python,定义python解释器调用路径,对比#!/usr/bin/python ...

  8. MongoSpark 28799错误

    Exception : . The full response is { , "codeName" : "Location28799" } at com.mon ...

  9. 写Java代码分别使堆溢出,栈溢出

    首先要搞清楚堆栈里放的什么东西: 栈存储运行时声明的变量——对象引用(或基础类型, primitive)内存空间,堆分配每一个对象内容(实例)内存空间. 一个变量可以先后指向多个对象实例:数组.链表等 ...

  10. Java 实现追加excle文件内容

    Java 实现追加excle文件内容 一.示例一:excle(.xlsx) //jar import java.io.BufferedReader; import java.io.File; impo ...