转载:https://blog.csdn.net/hanyuyang19940104/article/details/81743459
快速取出ES索引中该索引所有字段名称
# 快速取出ES索引中该索引所有字段名称
# 1、通过命令 GET 索引名称/_mapping 获取该索引所有字段信息
# 2、取出"properties"中所有字段,如test_dict中
# 3、通过test_dict.keys()获取所有字段值
# 4、转化为list, list(test_dict.keys()),输出结果可以直接用于获取数据的所有字段
test_dict = {
"field0": {
"type": "keyword"
},
"@timestamp": {
"type": "date"
},
"field1": {
"type": "keyword"
},
"field2": {
"type": "keyword"
}
}
print(list(test_dict.keys()))
curl -XGET http://localhost:9200/reconciliation_wallet_litecoin/_mapping?pretty
elasticsearch常用操作命令
https://blog.51cto.com/6226001001/2104383
1.获取所有所有
curl -XGET http://localhost:9200/_cat/indices?v
2.获取某个索引
curl -XGET http://localhost:9200/_cat/indices/reconciliation_exchange
3.elasticsearch 查询数据
curl 'localhost:9200/bank/_search?q=*&pretty'
返回所有bank中的索引数据。其中 q=* 表示匹配索引中所有的数据。
等价于:
curl -H'Content-Type: application/json' -XPOST 'localhost:9200/reconciliation_wallet_litecoin/_search?pretty' -d '
{
"query": { "match_all": {} }
}'
匹配所有数据,但只返回1个:
注意:如果siez不指定,则默认返回10条数据。
curl -H'Content-Type: application/json' -XPOST 'localhost:9200/reconciliation_wallet_litecoin/_search?pretty' -d '
{
"query": { "match_all": {} },
"size": 1
}'
返回从11到20的数据。(索引下标从0开始):
curl -H'Content-Type: application/json' -XPOST 'localhost:9200/reconciliation_wallet_litecoin/_search?pretty' -d '
{
"query": { "match_all": {} },
"from": 10,
"size": 10
}'
匹配所有的索引中的数据,按照@timestamp字段降序排序,并且返回前10条(如果不指定size,默认最多返回10条):
curl -H'Content-Type: application/json' -XPOST 'localhost:9200/reconciliation_wallet_litecoin/_search?pretty' -d '
{
"query": { "match_all": {} },
"sort": { "@timestamp": { "order": "desc" } },
"size": 2
}'