ElasticSearch
POST _bulk
批量插入的时候,index的id和返回结果中index的id保持一致
_search
复合查询 Bool Query (must, must_not, should)
查询结果_shards是分片信息,hits中的hits是返回的源数据
只显示部分字段:
除了query,要加入"_source"
{
"query":{
"bool":{
"must":[
],
"should":[
{
"term":{
"msgId":"f805c3a0dcdca54f7100"
}
}
],
"must_not":[
]
}
},
"from":0,
"size":1,
"sort":[
],
"_source":[
"msgId"
]
}
查询的结果中,hits -> hits -> _source中只有msgId
复合查询中可以在range字段中加入范围,详见es service类的aggsSearch方法
聚合查询:对查询的数据进行聚合操作。aggs中加入perCounts->terms(terms中加入需要聚合的字段和size),
查询结果的doc_count为查到的数量
查询的json中,from表示从第几行开始,size表示查询多少条文档
这便是matchPhraseQuery和matchQuery等的区别,
1、在使用matchQuery等时,即使你传入的是“小别克老”,在执行查询时,“小别克老”会被分词器分词,例如paoding解析成“小别/别克/老”,
2、使用matchPhraseQuery时,“小别克老”并不会被分词器分词,而是直接以一个短语的形式查询,而如果你在创建索引所使用的field的value中没有这么一个短语(顺序无差,且连接在一起),那么将查询不出任何结果。
es用curl查询数据:
curl -XGET bjfk-rs11150.yz02:9239/infra-sms-sendverify-2020-07-28/log/_search?pretty -H'content-Type:application/json' -d '{"query":{"bool":{"must":[{"term":{"provider":{"value":"RONGLIAN"}}},{"term":{"verified":{"value":true}}},{"range":{"sendTime":{"from":1595941320000,"to":1595941920000,"include_lower":true,"include_upper":true,"boost":1.0}}}]}}}'
174
curl -XGET bjfk-rs11150.yz02:9239/infra-sms-sendverify-2020-10-28/log/_search?pretty -H'content-Type:application/json' -d '{"query":{"bool":{"must":[{"term":{"fullNumber":{"value":"+8618811_cf5efcc40950a68fa4a44de6547bc27f"}}}]}}}'
curl -XGET bjfk-rs11150.yz02:9239/infra-sms-sendverify-2020-10-19/log/_search?pretty -H'content-Type:application/json' -d '{"query":{"bool":{"must":[{"term":{"bizName":{"value":"BULLDOG_SMS_COMMON_SGP"}}}]}}}'
curl -XGET bjfk-rs11150.yz02:9239/infra-sms-sendverify-2020-10-19/log/_search?pretty -H'content-Type:application/json' -d '{"query":{"bool":{"must":[{"term":{"bizName":{"value":"BULLDOG_SMS_COMMON_SGP"}}},{"term":{"verified":{"value":true}}}]}}}'
curl -XGET bjfk-rs11150.yz02:9239/infra-sms-sendverify-2020-10-19/log/_search?pretty -H'content-Type:application/json' -d '{"query":{"bool":{"must":[{"term":{"bizName":{"value":"BULLDOG_SMS_COMMON_SGP"}}},{"term":{"verified":{"value":true}}}]}}}'
curl -XGET bjfk-rs11150.yz02:9239/infra-sms-send-2021-02-04/log/_search?pretty -H'content-Type:application/json' -d '{"query":{"bool":{"must":[{"term":{"fullNumber":{"value":"+8618713_3278b006b2871053f1ab3fd464d60da6"}}}]}}}'
curl -XGET bjfk-rs11150.yz02:9239/infra-sms-verify-2020-11-05/log/_search?pretty -H'content-Type:application/json' -d '{"query":{"bool":{"must":[{"term":{"verifyHash":{"value":"cd22bb5ffa55283ccbc22ab9135ebb75:f19"}}},{"term":{"fullNumber":{"value":"+8615600_6bb30dff8c8eec122c1c87616a0e96f3"}}}]}}}'
curl -XGET bjfk-rs11150.yz02:9239/infra-sms-send-2020-11-05/log/_search?pretty -H'content-Type:application/json' -d '{"query":{"bool":{"must":[{"term":{"verifyHash":{"value":"cd22bb5ffa55283ccbc22ab9135ebb75:f19"}}},{"term":{"fullNumber":{"value":"+8618713_3278b006b2871053f1ab3fd464d60da6"}}}]}}}'
curl删除索引
curl -XDELETE bjfk-rs11150.yz02:9239/infra-sms-callback-2020-07-09
curl查询索引明细
curl -XGET "bjfk-rs11150.yz02:9239/infra-sms-send-2020-12-15/_mapping?pretty"
es查询 build request时如果size为0,则不会查到明细 只能查到total
查看es版本:curl -XGET 'bjfk-rs11150.yz02:9239'