1.es ES因搜索而生,主要工作就是处理查询,返回结果
https://www.elastic.co/guide/en/elasticsearch/reference/current/index.html es 官网学习文档
开发要表结构文件。看层级和type 下面会使用
mappings 中的数据都支持查询关键字。
http://{ip}:{esport}/{index}
POST http://elasticsearch-explorer.test-b-okex.svc.test.local:9200/okb_block/_delete_by_query
{ "query": {"match_all": {} } }
POSThttp://elasticsearch-explorer.test-b-okex.svc.test.local:9200/okb_block_index/_delete_by_query
{ "query": {"match_all": {} } }
POSThttp://elasticsearch-explorer.test-b-okex.svc.test.local:9200/okb_transaction/_delete_by_query
{ "query": {"match_all": {} } }
GEThttp://elasticsearch-explorer.test-b-okex.svc.test.local:9200/okb_block_index/_search
GEThttp://elasticsearch-explorer.test-b-okex.svc.test.local:9200/okb_block/_search
GEThttp://elasticsearch-explorer.test-b-okex.svc.test.local:9200/okb_transaction/_search
查询
http://elasticsearch-explorer.test-a-oklink.svc.test.local:9200/okb_block_index/block_index/{block}
http://elasticsearch-explorer.test-a-oklink.svc.test.local:9200/okb_block/block/{has}
http://elasticsearch-explorer.test-a-oklink.svc.test.local:9200/okb_transaction/transaction/{has}
查询某个区块内的交易,和从。。到。。区块的 产生的交易
http://elasticsearch-explorer.test-a-oklink.svc.test.local:9200/okb_block/block/_search
ES提供了基于JSON的query DSL查询语言,有两种类型子句:
1. Leaf query。查找特定字段的特定值。如match、term、range查询。
2. Compound query。wrap other leaf or compound queries。以一种含有逻辑(如bool、dis_max查询)的方式组合多个查询,或改变查询行为(如constant_score查询)
原文:https://blog.csdn.net/feifantiyan/article/details/53995772
posthttp://elasticsearch-explorer.test-a-oklink.svc.test.local:9200/okb_transaction/_search
{"query":{"match":{"block_height": "4780"}}}
{"query":{"range": {"block_height":{"gte": 10,"lte": 20000}}}}
{"query":{"match":{"transaction_data.type": "cosmos-sdk/MsgSubmitProposal"}}}
{"query":{"terms":{"transaction_data.type":["cosmos-sdk/MsgSubmitProposal","okdex/MsgDexListSubmitProposal"]}}}
{"query":{"bool":{"filter":{"terms":{"transaction_data.type":["cosmos-sdk/MsgSubmitProposal","okdex/MsgDexListSubmitProposal"]}},"must_not":{"match":{"status":"SUCCESS"}}}}}
{"query":{"bool":{"filter":{"terms":{"transaction_data.type":["cosmos-sdk/MsgSubmitProposal","okdex/MsgDexListSubmitProposal"]}},"must":{"match":{"status":"SUCCESS"}}}}}
查询1000条数据,按照块高降序排列
{"query":{"bool":{}},"sort":[{"block_height":{"order":"desc"}}],"size":10000}
term 是精确匹配,上面两个交易类型是or 关系。只要精确匹配一个就会被选出
{"query":{"bool":{"filter":{"match":{"transaction_data.type":"cosmos-sdk/MsgSubmitProposal"}},"must_not":{"match":{"status":"SUCCESS"}}}}}
filter 选中符合条件的 mustnot 不符合后面条件的。 match/range/term 都可做后面条件
https://www.jianshu.com/p/d5583dff4157
因为match进行搜索的时候,会先进行分词拆分,拆完后,再来匹配,上面两个内容,他们title的词条为: love china hubei ,我们搜索的为love China 我们进行分词处理得到为love china ,并且属于或的关系,只要任何一个词条在里面就能匹配到。会按照空格拆分。
match_phrase 称为短语搜索,要求所有的分词必须同时出现在文档中,同时位置必须紧邻一致。
先看看term的定义,term是代表完全匹配,也就是精确查询,搜索前不会再对搜索词进行分词拆解。但是我只想精确匹配 love China这个,按照下面的写法不能查出来。term属于精确匹配,只能查单个词。我想用term匹配多个词怎么做?
可以使用terms来,terms里的[ ] 多个是或者的关系,只要满足其中一个词就可以。想要通知满足两个词的话,就得使用bool的must来做
{"query":{"bool":{"must":[{"terms":{"transaction_data.type":["cosmos-sdk/MsgSubmitProposal","okdex/MsgDexListSubmitProposal"]}},{"match":{"status":"SUCCESS"}}]}}}
es查询默认返回的是所有数据,使用_source可以指定返回指定字段的数据
{"query":{"range": {"last_transaction_time": {"gt":1565658000000 ,"lte": 1565661600000 }}},"_source": ["account_number", "balance"]}
前面查询条件,返回符合条件的所有数据。添加_source 指定只返回balance数据,如下
{
"_index": "ltc_address_1",
"_type": "address",
"_id": "LeQTsnAm3e5WHQrApx3wBr8JpKUgdyRwfh",
"_score": 1,
"_source": {
"balance": 0.7635146 }
统计求和。查找后按照fee 求和 sum_count这个位置可以随意自定义。
{"query":{"bool":{"filter":[{"range":{"blocktime":{"gt":1565776767,"lt":1565863167}}}]}},"size":0,"aggs":{"sum_count":{"sum":{"field":"fee"}}}}
结果返回
"hits": {
"total": 6869,
"max_score": 0,
"hits": []
},
"aggregations": {
"sum_count": {
"value": 468148092 }
}
}
Elasticsearch--Aggregation详细总结(聚合统计)
https://blog.csdn.net/donghaixiaolongwang/article/details/58597058
{"query":{"bool":{"filter":[{"range":{"blocktime":{"gt":1566976950,"lt":1567063350}}}]}},"size":0,"aggs":{"sum_transfer":{"sum":{"field":"real_transfer_value_sat"}},"sum_fee":{"sum":{"field":"fee"}}}}
{"query":{"bool":{}},"sort":[{"height":{"order":"desc"}}],"size":1008,"aggs":{"max_blocktime":{"max":{"field":"blocktime"}},"min_blocktime":{"min":{"field":"blocktime"}}}}
计数和去重统计
{"query":{"bool":{"filter":[{"range":{"blocktime":{"gt":${yes},"lte":${now}}}}]}},"size":0,"aggs":{"block_count":{"value_count":{"field":"height"}},"minpool_count": {"cardinality": { "field": "guessed_miner"}}}}
去重统计默认显示前十,添加size 如下显示前20个
{"query":{"bool":{"filter":[{"range":{"blocktime":{"gt":1567494812,"lte":1567581212}}}]}},"size":0,"aggs":{"block_count":{"value_count":{"field":"height"}},"minpool_count":{"cardinality":{"field":"guessed_miner"}},"group":{"terms":{"field":"guessed_miner","size":20}}}}
设置权重boost
{"query":{"bool":{"must":[{"range":{"real_transfer_value":{"from":500,"to":null,"include_lower":true,"include_upper":true,"boost":1.0}}},{"range":{"blocktime":{"from":1563707220,"to":1563793620,"include_lower":true,"include_upper":true,"boost":1.0}}}],"adjust_pure_negative":true,"boost":1.0}}}
2.redis
桌面图形化工具 Another Redis DeskTop Manager
redis-explorer.test-a-oklink.svc.test.local 6379
删除数据
cd /usr/local/redis-5.0.5/src/
./redis-cli -hredis-explorer.test-a-oklink.svc.test.local keys "*"| xargs ./redis-cli -hredis-explorer.test-a-oklink.svc.test.local del