日志检索场景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 dayfrom car group by day;