使用cURL尝试ElasticSearch
测试环境:debian 9
官网提供了 deb,rpm,源码下载
官方下载地址:https://www.elastic.co/downloads/elasticsearch
通过源码安装会遇到一些小问题,为了方便,我直接下载deb安装(需要提前安装jdk)。
可以通过 service elasticsearch start/stop 启动关闭服务,默认监听了 9200端口,可以更改配置文件
通过deb安装的配置文件在:/etc/elasticsearch/elasticsearch.yml
如果要在localhost外连接elasticsearch ,更改配置文件中的 network.host:0.0.0.0
如果一起顺利就可以开始测试了
查看es基本信息
curl localhost: 列出所有的Index
curl -X GET 'http://localhost:9200/_cat/indices?v' 列举每个Index下的Type
curl 'localhost:9200/_mapping?pretty=true' 添加Index
curl -X PUT 'localhost:9200/weather' 删除Index
curl -X DELETE 'localhost:9200/weather' 安装中文分词插件ik (安装完需要重启es)
elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v6.5.4/elasticsearch-analysis-ik-6.5.4.zip 创建一个Index,并设置其结构和分词
curl -X PUT -H 'Content-Type: application/json' 'localhost:9200/accounts' -d '
{
"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"
}
}
}
}
}' 向Index增加记录
PUT方式
curl -X PUT -H 'Content-Type: application/json' 'localhost:9200/accounts/person/1' -d '
{
"user": "张三",
"title": "工程师"
}' POST方式(POST方式不需要传id,id随机生成)
curl -X POST -H 'Content-Type: application/json' 'localhost:9200/accounts/person' -d '
{
"user": "李四",
"title": "工程师"
}'
注意:如果没有先创建 Index(这个例子是accounts),直接执行上面的命令,Elastic 也不会报错,而是直接生成指定的 Index。所以,打字的时候要小心,不要写错 Index 的名称。 查看指定条目的记录
curl 'localhost:9200/accounts/person/1?pretty=true' 删除一条记录
curl -X DELETE 'localhost:9200/accounts/person/1' 更新一条记录
curl -X PUT -H 'Content-Type: application/json' 'localhost:9200/accounts/person/1' -d '
{
"user" : "张三",
"title" : "软件开发"
}' 查询所有记录
curl 'localhost:9200/accounts/person/_search?pretty=true' 简单查询
curl -H 'Content-Type: application/json' 'localhost:9200/accounts/person/_search?pretty=true' -d '
{
"query" : { "match" : { "title" : "工程" }},
"from": , #0开始
"size": , #返回几条数据
}' OR查询
curl -H 'Content-Type: application/json' 'localhost:9200/accounts/person/_search?pretty=true' -d '
{
"query" : { "match" : { "title" : "工程 哈哈" }}
}' AND查询
curl -H 'Content-Type: application/json' 'localhost:9200/accounts/person/_search?pretty=true' -d '
{
"query": {
"bool": {
"must": [
{ "match": { "title": "工程" } },
{ "match": { "title": "哈哈" } }
]
}
}
}'
使用cURL尝试ElasticSearch的更多相关文章
- Curl操作Elasticsearch的常用方法
Elasticsearch对于文档操作,提供了以下几种API,本文就说明如何使用curl方式来调用这些API. API种类 单文档操作API 1.* Index API 索引文档 * 为文档创建索引 ...
- elasticsearch(5) curl 操作elasticsearch
创建索引之前可以对索引做初始化操作, 比如指定shards数量以及replicas的数量. library为索引的名称 CURL -XPUT 'http://192.168.1.10:9200 ...
- curl operate elasticsearch
export elasticsearchwebaddress=localhost:9200# 1. Add documentcurl -X PUT "$elasticsearchwebadd ...
- Curl实现ElasticSearch的增删改查
一.添加数据(laravel必须安装Curl扩展) $data = [ 'username'=>"张三", 'sex'=>"女", 'age'=&g ...
- window下使用curl操作elasticsearch
1.下载curlzip,https://curl.haxx.se/download.html; 2.解压,在bin文件夹中找到curl.exe,右键“以管理员身份运行”,cmd e: 换盘符:出现E: ...
- Elasticsearch之CURL命令的DELETE
也可以看我写的下面的博客 Elasticsearch之curl删除 Elasticsearch之curl删除索引库 删除,某一条数据,如下 [hadoop@master elasticsearch-] ...
- Elasticsearch Java 虚拟机配置详解
Elasticsearch对Java虚拟机进行了预先的配置.通常情况下,因为这些配置的选择还是很谨慎的,所以你不需要太关心,并且你能立刻使用ElasticSearch. 但是,当你监视ElasticS ...
- Elasticsearch Java虚拟机配置详解(转)
引言: 今天,事情终于发生了.Java6(Mustang),是2006年早些时候出来的,至今仍然应用在众多生产环境中,现在终于走到了尽头.已经没有什么理由阻止迁移到Java7(Dolphin)上了. ...
- Elasticsearch教程-从入门到精通(转载)
转载,原文地址:http://mageedu.blog.51cto.com/4265610/1714522?utm_source=tuicool&utm_medium=referral 各位运 ...
随机推荐
- 机器学习之AdaBoost原理与代码实现
AdaBoost原理与代码实现 本文系作者原创,转载请注明出处: https://www.cnblogs.com/further-further-further/p/9642899.html 基本思路 ...
- 开辟sys节点用户层直接操作物理地址(比/dev/mem方便)
在调试驱动程序时, 经常要设置主控器寄存器参数或者运行时读取寄存器值debug问题, 每次修改驱动读取寄存器值都要编译一次驱动再insmod, 十分不方便, 哪怕驱动提供一个节点 如dev/mem给应 ...
- C#保留2位小数几种场景总结
场景1: C#保留2位小数,.ToString("f2")确实可以,但是如果这个数字本来就小数点后面三位比如1.253,那么转化之后就会变成1.25.可不可以刚好保留到最后一位不是 ...
- 分布式缓存Hazelcast案例一
分布式缓存Hazelcast案例一 Hazelcast IMDG Architecture 今天先到这儿,希望对您技术领导力, 企业管理,物联网, 系统架构设计与评估,团队管理, 项目管理, 产品管 ...
- mysql命令查看表结构及注释
使用如下命令:select table_schema,table_name,column_name,column_type,column_key,is_nullable,column_default, ...
- 微信H5页面 会被软键盘顶起来
问题描述:H5页面在微信中打开,input输入框获取焦点时,页面被软键盘顶上去:关闭软键盘时,页面不会自动下来(恢复初始状态) H5页面在微信中初始状态如下图: input输入框获取焦点时,页面被软键 ...
- deepin linux学习笔记
目录 deepin linux学习笔记 前言 linux常用命令 ls 显示文件夹内容 cd 切换当前目录 pwd 查看当前工作目录 mkdir 新建文件夹 rm 删除文件或文件夹 mv 移动文件 c ...
- Powershell Linux正式版可用,启动名称有变
CentOS yum install powershell 但并没有powershell这个可执行文件.通过搜索可以发现在powershell目录里有pwsh可执行文件,那么以后就要用pwsh执行了. ...
- Jenkins分布式部署配置
为什要使用Jenkins分布式? 利用jenkins分布式来构建job,当job量足够大的时候,可以有效的缓解jenkins-master上的压力,提高并行job数量, 减少job处于pending状 ...
- mysql7笔记----存储过程实例
mysql创建存储过程 DROP PROCEDURE IF EXISTS getCreateTimes /*前面要写DELIMITER $$ 或DELIMITER // */ DELIMITER $$ ...