Curl命令来访问Elasticsearch?
嘻嘻发布于2020-03-10
最后更新于2020年3月8日
浏览Elasticsearch是一个基于Lucene库的搜索引擎。它提供了一个分布式的、支持多租户的全文搜索引擎,带有HTTP web接口和无模式的JSON文档。Elasticsearch提供了Kibana,用于Elasticsearch的开源数据可视化仪表板。
在特定的情况我们没有界面可以看,只能通过命令行来访问获取ES中数据和结构,这时Curl命令就派上用场了。
Curl请求格式
搜索请求可以使用搜索DSL(其中包括查询DSL)来执行。
GET /<index>/_search
{
"query": {<parameters>}
}
例子:
GET /twitter/_search
{
"query" : {
"term" : { "user" : "kimchy" }
}
}
常用的请求
- 获取
中索引结构 curl -XGET http://10.168.0.2:9200/<index>/_mapping?pretty
- 发送查询请求
curl -X POST http://10.168.0.2:9200/<index>/_search -H "Content-Type:application/json" -d '{"query": {"bool": {"filter": [{"terms": {"id": [24, 26 ] } } ] } } }'
- 复杂的查询请求
curl -X POST http://10.168.0.2:9200//_search -H "Content-Type:application/json" -d ‘ { "query": { "constant_score": { "filter": { "bool": { "filter": [ { "term": { "disabled": true } }, { "terms": { "id": [ 24, 902, 915 ] } } ], "must_not": [ { "terms": { "country_ex": [ "in" ] } } ] } } } }, "sort": { "id": { "order": "desc" } } }'