在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":"virginiaayala@filodyne.com","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格式的内容体

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值