https://www.elastic.co/guide/cn/elasticsearch/guide/current/_search_lite.html
注意的地方有时候没有代码提示,是因为你没有加大括号。
轻量搜索查询指定文件路径的所有条目
GET crm-daemon-2021.11.04/_search
{
"query": {
"match": {
"log.file.path": "/home/data/logs/crm/crm_error.log"
}
}
}
更复杂的搜索
多个字段匹配查询
GET crm-daemon-2021.11.04/_search
{
"query" : {
"bool": {
"must": [
{
"match": {
"log.file.path": "/home/data/logs/crm/crm_error.log"
}},
{
"match": {
"agent.hostname": "xx-server-prd-01"
}
}
]
}
}
}
合并查询语句
{
"bool": {
"must": { "match": { "tweet": "elasticsearch" }},
"must_not": { "match": { "name": "mary" }},
"should": { "match": { "tweet": "full text" }},
"filter": { "range": { "age" : { "gt" : 30 }} }
}
}
组合查询
在 组合过滤器 中,我们讨论过如何使用 bool 过滤器通过 and 、 or 和 not 逻辑组合将多个过滤器进行组合。在查询中, bool 查询有类似的功能,只有一个重要的区别。
过滤器做二元判断:文档是否应该出现在结果中?但查询更精妙,它除了决定一个文档是否应该被包括在结果中,还会计算文档的 相关程度 。
与过滤器一样, bool 查询也可以接受 must 、 must_not 和 should 参数下的多个查询语句。
GET crm-daemon-2021.11.04/_search
{
"query": {
"bool": {
"should": [
{ "match": { "log.file.path":"/home/data/logs/crm/crm_error.log" }},
{ "match": {"agent.hostname":"xx-server-prd-01"}}
]
}
}
}
根据时间查询:
GET member-daemon-2021.11.04/_search
{
"query": {"bool": {"must": [
{
"match": {
"log.file.path": "/home/data/logs/member/error/api_services_error"
}
},{"range": {
"@timestamp": {
"gte": "now-10m"
}
}}
]}
},"size": 0
}



