使用linux命令查询es报错

近期遇到一个问题,生产环境没有elasticsearch-head,需要用linux命令查询es,所以我从网上搜索到查询的命令执行,但是却报403:

报错信息:

{"error":{"root_cause":[{"type":"transport_exception","reason":"Forbidden"}],"type":"transport_exception","reason":"Forbidden"},"status":403}

因为在测试环境使用elasticsearch-head查询时是有用户名密码的,想着应该是用户名密码的原因于是直接在地址后面追加了用户名密码:

 curl http://ip:9200?auth_user=user&auth_password=password

结果还是报同样的错误。

后来终于找到需要在命令后面直接添加用户名密码 curl -u user:password

如下是查询某个索引数据,其他正常查询索引的命令就不一一列举了从网上都可以搜到。

curl -u 用户名:密码 -XGET 'http://ip:9200/索引名/_search' -H 'content-Type:application/json' -d '{
    "query": {
        "bool": {
            "must": [
                {
                    "match_all": {}
                }
            ],
            "must_not": [],
            "should": []
        }
    },
    "from": 0,
    "size": 25000, --查询条数
    "sort": [],
    "aggs": {}
}'

猜你喜欢

转载自blog.csdn.net/knowwait/article/details/125869610