日志检索场景ES->Doris迁移最佳实践:函数篇

函数列表

  1. 函数:term
  2. 函数功能说明:查询某个字段里含有某个关键词的文档
  3. 参数说明:
  4. 返回值说明:
  5. ES使用示例:
{
  "query": {
    "term": {
      "title":   "blog"
    }
  }
}
  1. Doris使用示例:
select * from httplogs where title = 'blog';

  1. 函数:terms
  2. 函数功能说明:查询某个字段里含有多个关键词的文档
  3. 参数说明:
  4. 返回值说明:
  5. ES使用示例:
{
  "query": {
    "terms": {
      "title":  [ "blog","page"]
    }
  }
}
  1. Doris使用示例:
select * from httplogs where title IN ('blog', 'page');

  1. 函数:match
  2. 函数功能说明:match首选对字段进行分词操作,然后再查询
  3. 参数说明:
  4. 返回值说明:
  5. ES使用示例:
{
  "query": {
    "match": {
      "title":  "blog page"   
    }
  }
}

说明:和term区别可以理解为term是精确查询,这边match模糊查询;match会对my ss分词为两个单词,然后term对认为这是一个单词
5. Doris使用示例:

 select * from httplogs where request MATCH 'blog page';

  1. 函数:should
  2. 函数功能说明:至少有一个查询条件匹配
  3. 参数说明:
  4. 返回值说明:
  5. ES使用示例:
{
"bool": {
"should": [
      { "term": { "title": "error" }},
      { "term": { "title": "exption" }} ]
  }
}
  1. Doris使用示例:
select * from httplogs where title = 'error' or  title = 'exption';

  1. 函数:must
  2. 函数功能说明:查询指定文档一定要被包含
  3. 参数说明:
  4. 返回值说明:
  5. ES使用示例:
{
  "query": {
    "bool": {
      "must": [
        {"match": {
          "title": "page"
        }},
        {
          "match": {
            "content": "beijing"
          }
        }
      ]
    }
  }
}
  1. Doris使用示例:
select * from httplogs where title MATCH 'title' and  content MATCH 'exption';

  1. 函数:must not
  2. 函数功能说明:
  3. 参数说明:
  4. 返回值说明:
  5. ES使用示例:
{
  "query": {
    "bool": {
      "must_not": [
        {"match": {
          "title": "page"
        }},
        {
          "match": {
            "content": "beijing"
          }
        }
      ]
    }
  }
}
  1. Doris使用示例:
select * from httplogs where 
!(title MATCH 'title') 
and  !(content MATCH 'exption');

  1. 函数:exists
  2. 函数功能说明:查找文档中是否包含指定字段或没有某个字段
  3. 参数说明:
  4. 返回值说明:
  5. ES使用示例:
{
  "query": {
    "exists": { 
      "field": "title"
    }
  }
}
  1. Doris使用示例:
select * from httplogs where title IS NOT NULL;

  1. 函数:sum
  2. 函数功能说明:
  3. 参数说明:
  4. 返回值说明:
  5. ES使用示例:
{
  "aggs": {
    "hat_prices": { "sum": { "field": "price" } }
  }
}
  1. Doris使用示例:
select sum(price) from example_table

  1. 函数:date_histogram
  2. 函数功能说明:按照日期时间聚合分析数据
  3. 参数说明:
  4. 返回值说明:
  5. ES使用示例:
    GET cars/index/_search
{
  "size":0,
  "aggs": {
    "sales": {
      "date_histogram": {//按照日期时间聚合分析数据
        "field": "event_time",//分组字段
        "interval": "1d",//安天分组
        "format": "yyyy-MM-dd",//日期格式
        "min_doc_count": 0// 没有数据的日志返回0
      }
    }
  }
}
  1. Doris使用示例:
select DAY_FLOOR(event_time) as day
 from car group by day;
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值