EsClientManager.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. using Nest;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. namespace XYY.Common.Standard
  8. {
  9. public class EsClientManager
  10. {
  11. public class ChargesLog
  12. {
  13. public string Number
  14. {
  15. get; set;
  16. }
  17. public long Millise
  18. {
  19. get; set;
  20. }
  21. public string Time
  22. {
  23. get; set;
  24. }
  25. public Dictionary<string, long> TimeList
  26. {
  27. get; set;
  28. }
  29. public long TimeLong
  30. {
  31. get; set;
  32. }
  33. }
  34. private readonly static object lockObj = null;
  35. static EsClientManager()
  36. {
  37. lockObj = new object();
  38. }
  39. private static ElasticClient _weightLogClient;
  40. public static ElasticClient WeightLogClient
  41. {
  42. get
  43. {
  44. if (_weightLogClient == null)
  45. {
  46. lock (lockObj)
  47. {
  48. if (_weightLogClient == null)
  49. {
  50. string addr = "http://120.24.149.148:9526";
  51. Uri node = new Uri(addr);
  52. var settings = new ConnectionSettings(node).DefaultMappingFor<ChargesLog>(x =>
  53. x.IndexName("chargeslog")
  54. .TypeName("log")
  55. .IdProperty(y => y.Number));
  56. _weightLogClient = new ElasticClient(settings);
  57. }
  58. }
  59. }
  60. return _weightLogClient;
  61. }
  62. }
  63. }
  64. }