HTTP 协议本身语义:
GET 获取资源。
POST 新建资源(也可以用于更新资源)。
PUT 更新资源。
DELETE 删除资源。

ES通过HTTP Restful方式管理数据:
1.格式:#操作 /index/type/id
2.操作:可以进行
    添加(POST)
    修改(PUT)
    删除(DELETE)
    查询(GET)
    批量插入(_bulk)
    批量获取(_mget)
3.分词器需要在service的plugins导入响应插件

curl http://192.168.8.200:9200/index/type/id
# index 索引
# type 类型
# id 当前索引内唯一标
curl -X GET "http://10.100.172.116:9200/index_name?pretty"
# 查看索引
curl -X POST  -H "Content-Type: application/json" "http://192.168.8.200:9200/su/i" --data '{"name":"s","age":19}'
# 添加
# 没有id则自动创建
# curl -XDELETE "http://10.100.172.116:9200/indexname"
# 删除索引
curl -X DELETE "http://192.168.8.200:9200/su/i/AWwtxGO-KRenIdAIKtoj"
# 删除 指定id数据
curl -X PUT  -H "Content-Type: application/json" "http://192.168.8.200:9200/su/i/AWwtxGO-KRenIdAIKtoj" --data '{"name":"f","age":22}'
# 修改,传入需要修改数据的id AWwtxGO-KRenIdAIKtoj
# 如果id不是想修改,在这里会根据传入的id新增一条或修改到其它id的数据。
curl -X POST -H "Content-Type: application/json" "http://192.168.8.200:9200/su/i/AWwtxGO-KRenIdAIKtoj/_update" --data '{"doc":{"name":"hf"}}'
# 局部修改使用post和_update
$ curl -X GET 'http://localhost:9200/_cat/indices?v'
// 查看所有Index
$ curl 'localhost:9200/_mapping?pretty=true'
// 列出索引类型
$ curl -X PUT 'localhost:9200/weather'
// 新建索引weather
$ curl -X DELETE 'localhost:9200/weather'
// 删除索引weather
$ ./bin/elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v5.6.8/elasticsearch-analysis-ik-5.6.8.zip
// 安装中文分词插件ik
// 根据es版本对应ik版本v5.6.8
$ curl -X PUT -H "Content-Type: application/json" 'localhost:9200/accounts' --data '
{
"mappings": {
"person": {
"properties": {
"user": {
"type": "text",
"analyzer": "ik_max_word",
"search_analyzer": "ik_max_word"
},
"title": {
"type": "text",
"analyzer": "ik_max_word",
"search_analyzer": "ik_max_word"
},
"desc": {
"type": "text",
"analyzer": "ik_max_word",
"search_analyzer": "ik_max_word"
}
}
}
}
}'
// 凡是需要搜索的中文字段,都要单独设置一下。
// 新建一个名称为accounts的 Index,里面有一个名称为person的 Type。person有三个字段。
// analyzer是字段文本的分词器,search_analyzer是搜索词的分词器。ik_max_word分词器是插件ik提供的,可以对文本进行最大数量的分词。
$ curl -X PUT -H "Content-Type: application/json" 'localhost:9200/accounts/person/1' --data '
{
"user": "张三",
"title": "工程师",
"desc": "数据库管理"
}'
// Index 里面新增一条记录 $ curl -X POST 'localhost:9200/accounts/person' -d '
{
"user": "李四",
"title": "工程师",
"desc": "系统管理"
}'
$ curl 'localhost:9200/accounts/person/1?pretty=true'
// 查看记录
$ curl -X DELETE 'localhost:9200/accounts/person/1'
// 删除记录
$ curl -X PUT 'localhost:9200/accounts/person/1' -d '
{
"user" : "张三",
"title" : "工程师",
"desc" : "数据库管理,软件开发"
}'
//更新记录,重新发一条数据
/*
"_version" : 2,
"result" : "updated",
"created" : false
*/
// 记录的 Id 没变,但是版本(version)从1变成2,操作类型(result)从created变成updated,created字段变成false,因为这次不是新建记录。
$ curl 'localhost:9200/accounts/person/_search'
// 查询数据,返回所有记录 // took字段表示该操作的耗时(单位为毫秒),
// timed_out字段表示是否超时,
// hits字段表示命中的记录,里面子字段的含义如下。
// total:返回记录数,本例是2条。
// max_score:最高的匹配程度,本例是1.0。
// hits:返回的记录组成的数组。
// 每条记录都有一个_score字段,表示匹配的程序,默认是按照这个字段降序排列。
$ curl 'localhost:9200/accounts/person/_search'  -d '
{
"query" : { "match" : { "desc" : "软件" }}
}'
// Match查询,desc字段 : 匹配条件。
$ curl 'localhost:9200/accounts/person/_search'  -d '
{
"query" : { "match" : { "desc" : "管理" }},
"size":
}'
// 默认一次返回10条结果,可以通过size字段改变这个设置。
$ curl 'localhost:9200/accounts/person/_search'  -d '
{
"query" : { "match" : { "desc" : "管理" }},
"from": ,
"size":
}'
// 可以通过from字段,指定位移。
// 从位置1开始(默认是从位置0开始),只返回一条结果。
$ curl 'localhost:9200/accounts/person/_search'  -d '
{
"query" : { "match" : { "desc" : "软件 系统" }}
}'
// 如果有多个搜索关键字, Elastic 认为它们是or关系。
// 软件 or 系统
$ curl 'localhost:9200/accounts/person/_search'  -d '
{
"query": {
"bool": {
"must": [
{ "match": { "desc": "软件" } },
{ "match": { "desc": "系统" } }
]
}
}
}'
// 如果要执行多个关键词的and搜索,必须使用布尔查询。

https://www.ruanyifeng.com/blog/2018/10/restful-api-best-practices.html

http://www.ruanyifeng.com/blog/2017/08/elasticsearch.html

https://www.elastic.co/guide/en/elasticsearch/reference/current/getting-started.html
https://www.elastic.co/cn/blog/a-practical-introduction-to-elasticsearch
https://creativecommons.org/licenses/by-nc-nd/3.0/deed.zh

ElasticSearch 增删改查的更多相关文章

  1. elasticsearch增删改查crudp-----1

    Elasticsearch一些增删改查的总结 环境Centos7+Es 5.x 简单介绍下ES的原理: 1,索引  --相当于传统关系型数据库的database或schema 2,类型  --相当于传 ...

  2. elasticsearch 增删改查底层原理

    elasticsearch专栏:https://www.cnblogs.com/hello-shf/category/1550315.html 一.预备知识 在对document的curd进行深度分析 ...

  3. Elasticsearch增删改查 之 —— mget多文档查询

    之前说过了针对单一文档的增删改查,基本也算是达到了一个基本数据库的功能.本篇主要描述的是多文档的查询,通过这个查询语法,可以根据多个文档的查询条件,返回多个文档集合. 更多内容可以参考我整理的ELK文 ...

  4. ES 17 - (底层原理) Elasticsearch增删改查索引数据的过程

    目录 1 增删改document的流程 1.1 协调节点 - Coordinating Node 1.2 增删改document的流程 2 查询document的流程 1 增删改document的流程 ...

  5. Elasticsearch增删改查 之 —— Get查询

    GET API是Elasticsearch中常用的操作,一般用于验证文档是否存在:或者执行CURD中的文档查询.与检索不同的是,GET查询是实时查询,可以实时查询到索引结果.而检索则是需要经过处理,一 ...

  6. Elasticsearch增删改查 之 —— Delete删除

    删除文档也算是常用的操作了...如果把Elasticsearch当做一款普通的数据库,那么删除操作自然就很常用了.如果仅仅是全文检索,可能就不会太常用到删除. Delete API 删除API,可以根 ...

  7. Java之Elasticsearch 增删改查

    <!--ELK --> <dependency> <groupId>org.elasticsearch.client</groupId> <art ...

  8. elasticsearch增删改查操作

    目录 1. 插入数据 2. 更改数据 3. 删除数据 4. 检索文档 1. 插入数据 关于下面的代码如何使用,可以借助于kibana的console,浏览器打开地址: http://xxx.xxx.x ...

  9. 阿里云 elasticsearch 增删改查

    kibana 控制台 # 查询所有数据 GET /yixiurds_dev/_search { "query": { "match_all": { } } } ...

随机推荐

  1. qemu源码分析

    参考:http://lists.gnu.org/archive/html/qemu-devel/2011-04/pdfhC5rVdz7U8.pdf 1. qemu与Bochs的区别: 1. Bochs ...

  2. ping命令的应用

    Ping命令是工作在 TCP/IP网络体系结构中应用层的一个服务命令, 主要功能是向特定的目的主机发送 ICMP(Iternet Control Message Protocol 因特网报文控制协议) ...

  3. 绿盟-WEB应用漏洞扫描系统

    ************************************************** WEB应用漏洞扫描系统 一.工具的介绍与使用 ************************** ...

  4. MySql 主从复制及深入了解

    分享一个不错的mysql文章 https://segmentfault.com/a/1190000008942618

  5. python中 try、except、finally执行顺序

    我们虽然经常用到try...except 作为异常补货,但是其实很少去研究try源码和机制,也许点进去看过,也是看不出个所以然来 class Exception(BaseException): &qu ...

  6. 在阿里云 既php和mysql装好之后,如何安装zabbix

    首先找到php.ini这个文件 命令如下 find / -name php.ini 然后参数修改为如下,不改装不了 max_execution_time = 300  memory_limit = 1 ...

  7. vue+element 构建的后台管理系统项目(1)新建项目

    1.运行 vue init webpack demo   这里的demo是你项目的名字 2.npm run dev 查看项目启动效果 3.安装Element cd 项目 cmd  运行 npm i e ...

  8. Ubuntu 16.04 PHP5.6

    Cannot add PPA: 'ppa:ondrej/php5-5.6' Ubuntu 16.04 PHP5.6 安装 Apache + PHP 5.6 + mysql 5.5 系统: Ubuntu ...

  9. Shell case in语句详解

    和其它编程语言类似,Shell 也支持两种分支结构(选择结构),分别是 if else 语句和 case in 语句.在<Shell if else>一节中我们讲解了 if else 语句 ...

  10. 区别 |python-pandas库set_index、reset_index用法区别

    1.set_index() 作用:DataFrame可以通过set_index方法,将普通列设置为单索引/复合索引. 格式:DataFrame.set_index(keys, drop=True, a ...