elasticsearch简单操作(一)
2024-08-25 15:44:17
1、增加记录
例如1:向指定的 /Index/Type 发送 PUT 请求,就可以在 Index 里面新增一条记录。比如,向/accounts/person
发送请求,就可以新增一条人员记录。
curl -X POST 'localhost:9200/accounts/person/2' -d '{"user":"张三","title": "工程师","desc":"系统管理"}'
系统提示如下错误:
{"error":"Content-Type header [application/x-www-form-urlencoded] is not supported","status":406}
需要制定插入数据格式:如下
curl -H "Content-Type: application/json" -X POST 'localhost:9200/accounts/person/2' -d '{"user":"张三","title": "工程师","desc":"系统管理"}'
系统提示:
{"_index":"accounts","_type":"person","_id":"2","_version":1,"result":"created","_shards":{"total":2,"successful":1,"failed":0},"_seq_no":0,"_primary_term":1}
说明插入成功
例如2:
curl -H "Content-Type: application/json" -X PUT 'localhost:9200/accounts/person/4' -d '{"user":"李四","title": "软件工程师","desc":"系理集成"}'
系统提示:
{"_index":"accounts","_type":"person","_id":"","_version":,"result":"created","_shards":{"total":,"successful":,"failed":},"_seq_no":,"_primary_term":}
说明插入成功。
可以使用PUT、POST插入数据,需要制定插入数据的数据格式,用 -H "Content-Type: application/json"制定为json格式。
2、数据查询
curl 'localhost:9200/accounts/person/4?pretty'
系统返回:
{
"_index" : "accounts",
"_type" : "person",
"_id" : "",
"_version" : ,
"found" : true,
"_source" : {
"user" : "李四",
"title" : "软件工程师",
"desc" : "系理集成"
}
}
说明查询成功。如果查询一个不存在id的记录,如命令:
curl 'localhost:9200/accounts/person/5?pretty'
id等于5的person因为没有对应的记录,所以,系统返回:
{
"_index" : "accounts",
"_type" : "person",
"_id" : "",
"found" : false
}
3、删除记录
删除记录就是发出 DELETE 请求。
最新文章
- [转] dpkg-deb命令
- hdu 2874 Connections between cities [LCA] (lca->;rmq)
- JS-010-覆盖率测试工具 JSCoverage 初识
- list.clear()和list=null的区别
- NOIP2011 计算系数
- WPF之Treeview控件简单用法
- 使用require.js时,解决AMD封装jquery1.4.1的问题。
- 3450: Tyvj1952 Easy
- C#基本功之委托和事件
- BSA Network Shell系列-nlogin命令
- Zsh安装及常用操作
- react_app 项目开发
- <;自动化测试方案_1>;第一章、为什么要做自动化测试?(Why)
- 二、xadmin----简单使用
- Mongoose简介
- 【SCOI2010】序列操作
- 蜕变成蝶~Linux设备驱动之异步通知和异步I/O
- 响铃:蜗牛读书“文”、网易云信“武”:游戏之外网易的AB面
- 第六章 对象作用域与servlet事件监听器
- Retrofit2使用初探
热门文章
- A Java Runtime Environment (JRE) or Java Development Kit (JDK) must be available in order to run Eclipse. No Java virtual machine was found after searching the following locations: /usr/local/eclipse/
- C#-循环语句(六)
- Windows Server 2016-Active Directory复制概念(一)
- Unity与安卓开发的一些路径知识
- Gradle: Gradle Wrapper
- php的register_long_arrays可以关闭以提高性能
- C语言经典例题(菜鸟教程100例)
- python3编写网络爬虫23-分布式爬虫
- 【Linux基础】awk命令
- 轮播图插件swiper 的使用