在shell中写curl语句进行elasticSearch数据查询

1,查询已有的index
curl -XGET ‘http://ip:9200/itcast/account/_search’ >> a.log

{"took":2,"timed_out":false,"_shards":{"total":5,"successful":5,"skipped":0,"failed":0},"hits":{"total":998,"max_score":1.0,"hits":[{"_index":"itcast","_type":"account","_id":"25","_score":1.0,"_source":{"account_number":25,"balance":40540,"firstname":"Virginia","lastname":"Ayala","age":39,"gender":"F","address":"171 Putnam Avenue","employer":"Filodyne","email":"[email protected]","city":"Nicholson","state":"PA"}},{"_index":"itcast","_type":"account","_id":"99","_score":1.0,"_source":{"account_number":99,"balance":47159,"firstname":"Ratliff","lastname":"Heath","age":39,"gender":"F","address":"80............}[root@hadoop-01 filebeat} #

可以发现最后没有换行

#!/bin/bash
curl -XGET ‘http://ip:9200/itcast/account/_search’ >> a.log
echo -e >> a.log (可以实现两次查询的结果之间进行了换行)

2,如果同时需要傳送request parameter跟json,
json資料則放入-d的参数,用單引號含起來(如果json內容是用單引號,-d的参数則改用雙引號包覆),且添加 ”Content-Type:application/json”跟”Accept:application/json” 表明请求格式

#! /bin/bash

curl -XGET 'http://IP:9200/itcast/account/_search' -H "Content-Type:application/json"  -H "Accept:application/json"  -d '
{
"query": {
  "bool": {
    "must": {
      "term": {
        "age" : "32"
        }
      }
    }
  }
}'   >> ./es.log
echo -e >> ./es.log

之前没有指定 "Content-Type:application/json”跟”Accept:application/json” ,发送的请求始终 相应为406

{“error”:“Content-Type header [application/x-www-form-urlencoded] is not supported”,“status”:406}
原来是:【6.x 版本的ES严格控制了Content-Type 问题,application/x-www-form-urlencoded不支持JSON格式的内容体

你可能感兴趣的:(elk)