ESQuery.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. using Elasticsearch.Net;
  2. using System;
  3. namespace JiaZhiQuan.Common.ElasticSearch
  4. {
  5. public static class ESQuery
  6. {
  7. /// <summary>
  8. /// 统计某个帖子的真实操作数量和模拟操作数量(适用于统计文章的阅读量和分享量)
  9. /// </summary>
  10. /// <param name="id">文章id</param>
  11. /// <returns></returns>
  12. public static PostData StatRealAndMockPostNumberCount(long id)
  13. {
  14. var query = new
  15. {
  16. size = 0,
  17. query = new
  18. {
  19. @bool = new
  20. {
  21. must = new object[]
  22. {
  23. new { term = new { postId = id } },
  24. new { range = new { createAt = new { lt = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")} } }
  25. },
  26. must_not = new object[]
  27. {
  28. new{ term = new { notValidRecord = true } }
  29. }
  30. }
  31. },
  32. aggs = new
  33. {
  34. mockCount = new { filter = new { term = new { isMock = new { value = true } } } },
  35. realCount = new { filter = new { term = new { isMock = new { value = false } } } }
  36. }
  37. };
  38. return PostData.Serializable(query);
  39. }
  40. }
  41. }