使用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 各位运 ...
随机推荐
- 如何在linux下使用git管理上传代码&误删文件修复
首先需要安装git,sudo apt-get install git,这时就可以下载代码了. 然后先在gituhub上新建一个仓库,然后先在本地建一个git目录,git init 然后再配置用户名和邮 ...
- Spring Boot配置定时任务
在项目开发过程中,经常需要定时任务来做一些内容,比如定时进行数据统计(阅读量统计),数据更新(生成每天的歌单推荐)等. Spring Boot默认已经实现了,我们只需要添加相应的注解就可以完成定时任务 ...
- .NET ClrProfiler ILRewrite 商业级APM原理
Demo:https://github.com/caozhiyuan/ClrProfiler.Trace 背景 为了实现自动.无依赖地跟踪分析应用程序性能(达到商业级APM效果),作者希望能动态修改应 ...
- 为何IntelliJ IDEA比Eclipse更好
阅读本文大概需要 4.2 分钟. 本文为译文,翻译:彭博 https://www.oschina.net/news/26929 争论 有一些没有唯一正确答案的“永恒”的问题,例如,更好的是:Windo ...
- k8s集群监控(十一)--技术流ken
Weave Scope 在我之前的docker监控中<Docker容器监控(十)--技术流ken>就已经提到了weave scope. Weave Scope 是 Docker 和 K ...
- dotnet core 微服务教程
这个教程主要是对于第一次使用dotnet core开发的同学. 运行环境是在centos 7 , 使用了docker容器. 即这是一篇运行在linux的docker容器上的微服务的简单应用. 一. 安 ...
- Java UrlRewriter伪静态技术运用深入分析
通常我们为了更好的缓解服务器压力,和增强搜索引擎的友好面,都将文章内容生成静态页面. 但是有时为了能实时的显示一些信息,或者还想运用动态脚本解决一些问题,不能用静态的方式来展示网站内容,必须用到动态页 ...
- git操作常用命令
一.使用git 1.git是什么? Git是目前世界上最先进的分布式版本控制系统. SVN与Git的最主要的区别? SVN是集中式版本控制系统,版本库是集中放在中央服务器的,而干活的时候,用的都是自己 ...
- AFO && OI回忆录
技不如人,甘拜下风 今天是2019.4.6,联考第一天,菜鸡attack原题爆炸(其实是都不会)心灰意冷(其实并没有很难过)写下了这篇文章 T1 2h写个跟\(k\)无关的假算法写到最后发现是三个lo ...
- socket通信如何处理每次包长度不定问题
说起来,这是一个漫长的问题: 客户端和服务器通信的结构是:包头+数据长度+数据 客户端请求服务器发送200包数据.包头=request:长度=4(一个int),数据=200: 服务器在收到客户端的请求 ...