惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Security Latest
Security Latest
Recorded Future
Recorded Future
人人都是产品经理
人人都是产品经理
S
SegmentFault 最新的问题
Hacker News - Newest:
Hacker News - Newest: "LLM"
C
CXSECURITY Database RSS Feed - CXSecurity.com
博客园 - 三生石上(FineUI控件)
博客园 - 聂微东
P
Privacy & Cybersecurity Law Blog
WordPress大学
WordPress大学
Know Your Adversary
Know Your Adversary
Spread Privacy
Spread Privacy
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
量子位
L
LINUX DO - 热门话题
L
Lohrmann on Cybersecurity
博客园 - Franky
酷 壳 – CoolShell
酷 壳 – CoolShell
T
Tor Project blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
雷峰网
雷峰网
阮一峰的网络日志
阮一峰的网络日志
V
Visual Studio Blog
T
Threatpost
T
Tenable Blog
有赞技术团队
有赞技术团队
大猫的无限游戏
大猫的无限游戏
Engineering at Meta
Engineering at Meta
GbyAI
GbyAI
C
Cisco Blogs
H
Heimdal Security Blog
Attack and Defense Labs
Attack and Defense Labs
A
About on SuperTechFans
Last Week in AI
Last Week in AI
N
News and Events Feed by Topic
T
Threat Research - Cisco Blogs
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
I
Intezer
V
V2EX
Cyberwarzone
Cyberwarzone
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
B
Blog RSS Feed
V
Vulnerabilities – Threatpost
N
Netflix TechBlog - Medium
T
The Blog of Author Tim Ferriss
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
U
Unit 42
PCI Perspectives
PCI Perspectives
P
Privacy International News Feed
D
Docker

博客园 - Hey,Coder!

Elasticsearch ILM 与 Data Stream 概念及实例说明文档 portainer httphelper封装 Ocelot + Consul + SignalR 粘性会话 正交软件架构 docker postgresql17 主从复制 rabbitmq总结与c#示例 docker rabbitmq quartz dashboard docker consul registrator 服务自动注册consul 微服务动态扩容 ubuntu24.04 安装docker RAG 检索增强生成 软考 - 架构设计师 知识点总结 c# MailKit3.4.3 发送邮件、附件 nginx 反向代理postgresql c# 信号量 elsa 3.5 中间件记录最后执行的节点数据 xp密钥 c# System.Text.Json 反序列化Dictionary<string,object>时未转换基础类型的处理方法 docker配置代理 openclaw 接入 LMStudio的模型服务 wpf canvas 移动 缩放 windows平台openclaw搭建 wpf scrollerview触摸滚动 c# 动态切换sqlsugar连接字符串 c# es 封装Elastic.Clients.Elasticsearch c# scrollerview滚动到指定元素位置 WPF 重写Expander 基于elsa工作流封装一套变量、组件的体系 常用活动重写 DynamicExpresso 轻量级动态表达式库 c# elsa 3.5.2 程序化工作流常用功能及自定义中间件 leaflet docker 连接老版本的sqlserver ssl错误 c# quartz 动态创建任务 控制任务运行和停止 依赖注入 cefsharp 模拟点击 批量重置数据库的数据 docker 复制远程镜像本地并创建容器 c# newtonsoft dynamic
c# Elastic.Clients.Elasticsearch 动态查询
Hey,Coder! · 2026-03-03 · via 博客园 - Hey,Coder!
ElasticsearchClientSettings elasticsearchClientSettings = new ElasticsearchClientSettings(new StaticNodePool(urls.Select((string h) => new Uri(h)).ToArray())).Authentication(new BasicAuthentication(username, password));
  if (!string.IsNullOrWhiteSpace(defaultIndex))
  {
      elasticsearchClientSettings.DefaultIndex(defaultIndex);
  }

  var client=  new ElasticsearchClient(elasticsearchClientSettings);
  var query = BuildQueryDescriptor(dto);
  var data = client.SearchAsync<LogEntity>(s => s
                                .Indices(LogDocumentName)
                                .From((dto.PageIndex - 1) * dto.PageSize)
                                .Size(dto.PageSize)
                                .Query(query)
                                );
  data.Wait();


 private Action<QueryDescriptor<LogEntity>> BuildQueryDescriptor(LogSearchInDto condition)
 {
     var mustQueries = new List<Action<QueryDescriptor<LogEntity>>>
     {
     };
     // StartDate
     if (condition.StartTime.HasValue)
     {
         // 时区已经是UTC, ELK中的时区也是UTC, 直接使用即可,否则需转时区
         mustQueries.Add(m =>
             m.Range(r =>
                 r.Date(d =>
                     d.Field(i => i.LogTime).Gte(DateMath.Anchored(condition.StartTime.Value)))));
     }
     // EndDate
     if (condition.EndTime.HasValue)
     {
         mustQueries.Add(m =>
             m.Range(r =>
                 r.Date(d =>
                     d.Field(i => i.LogTime).Lte(DateMath.Anchored(condition.EndTime.Value)))));
     }

     // 关键字检索SearchText
     if (!string.IsNullOrWhiteSpace(condition.Keywords))
     {
         mustQueries.Add(m => m.Match(c => c.Field("body.keyword").Query(condition.Keywords)));
     }

     Action<QueryDescriptor<LogEntity>> retQuery = q => q.Bool(b => b.Filter(mustQueries.ToArray()));

     return retQuery;
 }