使用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 各位运 ...
随机推荐
- python中的编码与解码
编码与解码 首先,明确一点,计算机中存储的信息都是二进制的 编码/解码本质上是一种映射(对应关系),比如‘a’用ascii编码则是65,计算机中存储的就是00110101,但是显示的时候不能显 ...
- [深度概念]·K-Fold 交叉验证 (Cross-Validation)的理解与应用
K-Fold 交叉验证 (Cross-Validation)的理解与应用 我的网站 1.K-Fold 交叉验证概念 在机器学习建模过程中,通行的做法通常是将数据分为训练集和测试集.测试集是与训练独立的 ...
- Java基础系列-Comparable和Comparator
原创文章,转载请标注出处:<Java基础系列-Comparable和Comparator> 一.概述 Java中的排序是由Comparable和Comparator这两个接 ...
- #6 判断一个数是否为2的n次方
「ALBB面试题」 [题目] 如何判断一个数是否为2的n次方 [题目分析] 看到这种题,相信大家第一反应就是循环除2,这样做肯定是可以得出结果的:但是这种做法无疑大大增加了计算机的运行时间,一个非常大 ...
- 💈 线程间互访助手类 (EN)
Conmajia © 2012, 2018 Published on August 5th, 2012 Updated on February 2nd, 2019 Introduction While ...
- [翻译]在Windows版或MacOS版的Microsoft Edge上安装一个谷歌浏览器拓展
原文:Install a Chrome Web Store extension on Microsoft Edge for Windows and MacOS 拓展阅读:What to expect ...
- 学JAVA第十五天,方法重载及构造方法进一步了解
由于星期五生病了,所以就没写.今天上课,又来写了!!! 先来说方法的重载. 方法的重载就是有两个方法的方法名相同,但参数不一致,参数个数不一致,或参数的类型不一样. package pkg9;publ ...
- 前端_Bootstrap简单使用
首先说一下简单使用方法: 1.首先上官网下载Bootstrap(就是一些js文件和一些css文件) ,网址: https://v3.bootcss.com/getting-started/#downl ...
- unity transform 常用操作
1.寻找物体 1.1 寻找满足条件的子物体 ` public static Transform FindObj(Transform transform, Func<Transform, bool ...
- java的设计模式 - Builder模式
Builder 模式的目的? 构造对象的方式过于复杂,不如将之抽离出来.比如,构造器参数过多 这样说也有点抽象,举个例子吧. 举个例子 比如 非常热门的消息队列RabbitMQ 的 AMQP.Basi ...