Esempio n. 1
0
        public override void Start()
        {
            base.Start();
            var body = new {
                aggs = new {
                    b = new {
                        max = new {
                            field = "tflbatchid"
                        }
                    },
                    k = new {
                        max = new {
                            field = "tflkey"
                        }
                    }
                },
                size = 0
            };
            var result  = _client.Search <DynamicResponse>(Context.Connection.Index, Context.TypeName(), body);
            var batchId = result.Body["aggregations"]["b"]["value"].Value;
            var key     = result.Body["aggregations"]["k"]["value"].Value;

            Context.Entity.BatchId  = (batchId == null ? 0 : (int)batchId) + 1;
            Context.Entity.Identity = (key == null ? 0 : (int)key);
            Context.Debug(() => $"Next TflBatchId: {Context.Entity.BatchId}.");
            Context.Debug(() => $"Last TflKey: {Context.Entity.Identity}.");

            var countBody = new { query = new { match_all = new { } } };

            Context.Entity.IsFirstRun = Context.Entity.MinVersion == null && _client.Count <DynamicResponse>(Context.Connection.Index, Context.TypeName(), countBody).Body["count"].Value == (long)0;
        }