12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- using Elasticsearch.Net;
- using System;
- namespace JiaZhiQuan.Common.ElasticSearch
- {
- public static class ESQuery
- {
- /// <summary>
- /// 统计某个帖子的真实操作数量和模拟操作数量(适用于统计文章的阅读量和分享量)
- /// </summary>
- /// <param name="id">文章id</param>
- /// <returns></returns>
- public static PostData StatRealAndMockPostNumberCount(long id)
- {
- var query = new
- {
- size = 0,
- query = new
- {
- @bool = new
- {
- must = new object[]
- {
- new { term = new { postId = id } },
- new { range = new { createAt = new { lt = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")} } }
- },
- must_not = new object[]
- {
- new{ term = new { notValidRecord = true } }
- }
- }
- },
- aggs = new
- {
- mockCount = new { filter = new { term = new { isMock = new { value = true } } } },
- realCount = new { filter = new { term = new { isMock = new { value = false } } } }
- }
- };
- return PostData.Serializable(query);
- }
- }
- }
|