栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 前沿技术 > 大数据 > 大数据系统

Elasticsearch DSL语句

Elasticsearch DSL语句

官网

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

}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/433689.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号