首页   快速返回

elasticsearch7安装配置使用     所属分类 elasticsearch
下载不带jdk的版本
elasticsearch-7.0.0-no-jdk-darwin-x86_64.tar.gz

解压

./bin/elasticsearch
增加JAVA_HOME
JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home

java 安装路径 可通过 java -verbose  查看


配置文件修改
config/elasticsearch.yml


cluster.name: myes
node.name: myes-node1
network.host: 0.0.0.0
http.port: 9200
discovery.seed_hosts: ["127.0.0.1"]
cluster.initial_master_nodes: ["myes-node1"]


启动 es 
./elasticsearch -d
-d 表示后台启动

日志 ./logs/

http://127.0.0.1:9200/

discovery.seed_hosts 一定要配置 否则启动报错

the default discovery settings are unsuitable for production use; 
at least one of [discovery.seed_hosts, discovery.seed_providers, cluster.initial_master_nodes] must be configured

cluster.initial_master_nodes 必须配置 否则创建索引会报错
master_not_discovered_exception

PUT  /myindex001
{
    "acknowledged": true,
    "shards_acknowledged": true,
    "index": "myindex001"
}




创建 tsdb_index 用于保存时序数据

PUT tsdb_index 

{
  "mappings": {
    "properties": { 
      "instance":    { "type": "keyword"  }, 
      "service":     { "type": "keyword"  }, 
      "time":  {"type":   "date", "format": "epoch_millis"}
    },
    
    "dynamic_templates": [
      {
        "data_fields_to_double": {
          "match_mapping_type": "*",
          "mapping": {"type": "double"}
        }
      }
    ]
  }
  
}


instance  service time  之外的字段 全部为 double 


索引查看
http://127.0.0.1:9200/_cat/indices?v

health status index      uuid                   pri rep docs.count docs.deleted store.size pri.store.size
yellow open   tsdb_index MAJQCHInRa-ytaRpq1gENQ   1   1          0            0       283b           283b
yellow open   myindex001 pirJ04C-TN6lXO16DrHNDg   1   1          0            0       283b           283b

因为有一个副本没有分配 ,所以状态为 yellow


添加文档
POST /tsdb_index/_doc
{"instance":"127.0.0.1:9000","service":"service1","time":1555403952325,"metric1":"1","metric2":"3.3"}

7.0版本去掉了 type  ,统一使用 _doc 代替

指定 id 
POST /tsdb_index/_doc/1
{"instance":"127.0.0.1:9000","service":"service1","time":1555403952326,"metric1":"1","metric2":"3.3"}



可以使用 sql 查询数据

POST /_sql?format=txt
{
    "query": "SELECT * FROM tsdb_index"
}

select * from tsdb_index where instance='127.0.0.1:9000'

select * from tsdb_index where instance='127.0.0.1:9000' and metric2 > 5

select * from tsdb_index where instance='127.0.0.1:9000' and metric2 > 5 and time=1555403952325

select * from tsdb_index where instance='127.0.0.1:9000' and metric2 > 5 and time=1555403952326

select instance,max(metric1),avg(metric2),sum(metric3) from tsdb_index group by instance


select * from tsdb_index  order by time desc 

select * from tsdb_index  order by time desc  limit 2

上一篇     下一篇
elasticsearch7.0.0突出特征

不使用 select * 的七个理由

vi使用技巧

银行理财风险等级

HTTP协议中PUT和POST的区别

elasticsearch索引_source index store doc_values 参数实例