• 数据接口示例


    1.数据写入:
    
    zjtest7-frontend:/usr/local/logstash-2.3.4/config# curl -XPOST http://192.168.32.80:9200/logstash-2015.06.21/testlog -d '{
    "date" :"19999999999",
    "user":"scan188",
    "mesg":"first message into Elasticsearch"
    }'
    {"_index":"logstash-2015.06.21","_type":"testlog","_id":"AVbklB1aEY-onx06xxpY","_version":1,"_shards":{"total":2,"successful":2,"failed":0},"created":true}zjtest7-frontend:/usr/local/logstash-
    
    2.3.4/config# 
    
    
    2.获取数据:
    
    zjtest7-frontend:/usr/local/logstash-2.3.4/config# curl -XGET http://192.168.32.80:9200/logstash-2015.06.21/testlog/AVbklB1aEY-onx06xxpY
    {"_index":"logstash-2015.06.21","_type":"testlog","_id":"AVbklB1aEY-onx06xxpY","_version":1,"found":true,"_source":{
    "date" :"19999999999",
    "user":"scan188",
    "mesg":"first message into Elasticsearch"
    }}zjtest7-frontend:/usr/local/logstash-2.3.4/config# 
    
    
    _source 里的内容,正是之前写入的数据。
    
    }}zjtest7-frontend:/usr/local/logstash-2.3.4/config# curl -XGET http://192.168.32.80:9200/logstash-2015.06.21/testlog/AVbklB1aEY-onx06xxpY/_source
    {
    "date" :"19999999999",
    "user":"scan188",
    "mesg":"first message into Elasticsearch"
    
    来指明要获取的数据部分。
    
    
    
    3.数据删除
    
    
    
    删除2天前的数据:
    [root@dr-mysql01 sbin]# cat del_index.sh 
    .~ /.bash_profile
    v_date=`date +%Y.%m.%d --date='2 days ago'`;
    echo $v_date
     curl -XDELETE http://192.168.32.80:9200/logstash-*-$v_date
    
    9.2 搜索请求:
    
    }}]}}zjtest7-frontend:/usr/local/logstash-2.3.4/config# curl -XGET http://192.168.32.80:9200/logstash-2015.06.21/testlog/_search?q=first
    {"took":3,"timed_out":false,"_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":1,"max_score":0.30685282,"hits":[{"_index":"logstash-2015.06.21","_type":"testlog","_id":"AVbklB1aEY-
    
    onx06xxpY","_score":0.30685282,"_source":{
    "date" :"19999999999",
    "user":"scan188",
    "mesg":"first message into Elasticsearch"
    
    
    搜索条件为first
    
    
    
    1.querystring 语法:
    
    
    上例中,?q=后面写的就是querystring 语法,鉴于这部分内容会在Kibana上经常使用,这里详细解析一下语法:
    
    1.全文检索:直接写搜索的单词,如上例中的first
    
    
    2.单字段的全文搜索:在搜索单词之前加上字段名和冒号,比如,如果知道单词first 肯定出现在mesg字段,可以写作mesg:first
    
    }}]}}zjtest7-frontend:/usr/local/logstash-2.3.4/config# curl -XGET http://192.168.32.80:9200/logstash-2015.06.21/testlog/_search?q=mesg:first
    {"took":3,"timed_out":false,"_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":1,"max_score":0.30685282,"hits":[{"_index":"logstash-2015.06.21","_type":"testlog","_id":"AVbklB1aEY-
    
    onx06xxpY","_score":0.30685282,"_source":{
    "date" :"19999999999",
    "user":"scan188",
    "mesg":"first message into Elasticsearch"
    }}]}}zjtest7-frontend:/usr/local/logstash-2.3.4/config# 
    
    
    3.单字段的精确检索:在搜索单词前后加双引号,比如user:"chenlin7"
    
    zjtest7-frontend:/usr/local/logstash-2.3.4/config# curl -XGET http://192.168.32.80:9200/logstash-2015.06.21/testlog/_search?q=user:"scan188"
    {"took":2,"timed_out":false,"_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":1,"max_score":0.30685282,"hits":[{"_index":"logstash-2015.06.21","_type":"testlog","_id":"AVbklB1aEY-
    
    onx06xxpY","_score":0.30685282,"_source":{
    "date" :"19999999999",
    "user":"scan188",
    "mesg":"first message into Elasticsearch"
    }}]}}zjtest7-frontend:/usr/local/logstash-2.3.4/config# 
    
    
    
    
    
    
    

  • 相关阅读:
    AES算法加解密Java工具类AESUtil
    并发与高并发(二十二)高并发の服务降级与服务熔断思路
    并发与高并发(二十一) 高并发の应用限流思路
    并发与高并发(二十)高并发の应用拆分思路
    da5_模块
    day5_集合
    day5_递归调用
    day5_判断价格输入是否是正整数或正小数
    day5_函数_判断小数
    day5_函数_文件读写_用一个函数来满足文件的读或者写_应用默认参数
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13350311.html
Copyright © 2020-2023  润新知