XuLaLa.Tech

首页客户端下载Windows 使用V2Ray 教程SSR 教程Clash 教程

Curl命令来访问Elasticsearch?

2025.04.09

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" }
}
}

常用的请求

  1. 获取中索引结构
    curl -XGET http://10.168.0.2:9200/<index>/_mapping?pretty
  2. 发送查询请求
    curl -X POST http://10.168.0.2:9200/<index>/_search -H "Content-Type:application/json" -d '{"query": {"bool": {"filter": [{"terms": {"id": [24, 26 ] } } ] } } }'
  3. 复杂的查询请求
    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"
    }
    }
    }'
© 2010-2022 XuLaLa 保留所有权利 本站由 WordPress 强力驱动
请求次数:69 次,加载用时:0.665 秒,内存占用:32.19 MB