wget -qo – https://artifacts.elastic.co/gpg-key-elasticsearch | sudo apt-key add –
apt-get install apt-transport-https
echo “deb https://artifacts.elastic.co/packages/7.x/apt stable main” | sudo tee -a /etc/apt/sources.list.d/elastic-7.x.list
sudo apt-get update && sudo apt-get install elasticsearch

编辑配置文件:
/etc/elasticsearch/elasticsearch.yml
network.host: 127.0.0.1
network.bind_host: 127.0.0.1
transport.tcp.port: 9300
http.port: 9200
/usr/share/elasticsearch/bin/elasticsearch -d

es中使用restful api对数据进行增删查改

1)get:查询数据
2)post:插入或更改数据
3)put:创建库或表
4)delete:删除库

index:数据库
type:表
document:行
field:列,字段
mapping:元信息

创建数据库:http://localhost:9200/sinamail/ put
查看所有数据库:http://localhost:9200/_cat/indices/ get
删除数据库:http://localhost:9200/sinamail/ delete

旧版本创建表,并且定义字段:http://localhost:9200/sinamail/webmail/_mapping put

插入数据:
http://localhost:9200/sinamail/webmail/ post
{
“accesslog”: “测试一下”
}
查询数据:
http://localhost:9200/sinamail/_search post
{“query”:{“bool”:{“must”:[{“match”:{“accesslog”:”测试下”}}]}},”from”:0,”size”:10}

使用curl命令操作数据:
curl http://127.0.0.1:9200 查看状态
curl -xput http://127.0.0.1:9200/sinamail 创建数据库
curl http://127.0.0.1:9200/_cat/indices/ 查看所有数据库
创建表,并且定义字段

curl -xput http://127.0.0.1:9200/sinamail/webmail/_mapping -d '{
  "webmail": {
    "properties": {
      "accesslog": {
        "type": "string"
      }
    }
  }
}'  

 

插入数据

curl -xpost http://127.0.0.1:9200/sinamail/webmail -d '{
    "accesslog":"我是一个好人的测试"
}'  

 

查询数据

curl -xpost http://127.0.0.1:9200/sinamail/_search -d '{
    "query":{
        "bool":{
            "must":[{"match":{"accesslog":"测我试下"}}]}},"from":0,"size":10
}'