Skip to content

nickelbob/elasticsearch-watcher-net

 
 

Repository files navigation

elasticsearch-watcher-net

Repository for the Elasticsearch Watcher extension library for NEST.

elasticsearch-net MyGet Build Status

Watcher is a plugin for Elasticsearch that provides alerting and notifications based on changes in your data. This library extends NEST, allowing you to interface with the Watcher plugin.

Installation

PM> Install-Package Nest.Watcher -IncludePrerelease

Compatibility Matrix

NEST.Watcher NEST Watcher
1.0.0-beta1 ≥ 1.5.1 1.0.0-Beta1
1.0.0-beta2 ≥ 1.5.1 1.0.0

Usage

Once the package is installed, there is no need to include any additional namespaces as the extension methods are part of the Nest namespace and will immediately become available on any ElasticClient instance.

Put watch example

var client = new ElasticClient();

var response = client.PutWatch("my-watch", p => p
		.Trigger(t => t
			.Schedule(s => s
				.Hourly(h => h
					.Minute(0, 15)
				)
			)
		)
		.Input(i => i
			.Search(srch => srch
				.Request(r => r
					.Body<object>(b => b
						.MatchAll()
					)
				)
			)
		)
		.Condition(c => c.Always())	
		.Actions(a => a
			.Add("test_index", new IndexAction { Index = "my-index", DocType = "my-type" })
		)

Just like the core NEST client, an object initializer syntax is also available for all Watcher API methods:

var request = new PutWatchRequest(watchId)
	{
		Trigger = new TriggerContainer
		{
			Schedule = new ScheduleContainer(
				new HourlySchedule
				{
					Minute = new int[] { 0, 15 }
				}
			)
		},
		Input = new SearchInput
		{
			Request = new SearchInputRequest
			{
				Body = new SearchRequest { Query = new QueryContainer(new MatchAllQuery()) }
			}
		},
		Condition = new AlwaysCondition(),
		Actions = new Dictionary<string, IAction>
		{
			{ "test_index", new IndexAction { Index = "my-index", DocType = "my-type" } }
		}
	};

var response = client.PutWatch(request);

...and async support for all methods as well:

var response = client.PutWatchAsync(request);

Getting a watch

var response = client.GetWatch("my-watch");

Executing a watch

var response = client.ExecuteWatch("my-watch", w => w
		.TriggerEvent(t => t
			.Schedule(schd => schd
				.ScheduledTime(new DateTime(2015, 05, 05, 20, 58, 02))
				.TriggeredTime(new DateTime(2015, 05, 05, 20, 58, 02))
			)
		)
		.AlternativeInput(i => i
			.Add("foo", "bar")
		)
		.IgnoreCondition()
		.RecordExecution(true)
	);

More examples

See the tests for more examples. Also, refer to the official Watcher documentation for the full API.

License

This software is Copyright (c) 2014-2015 by Elasticsearch BV.

This is free software, licensed under: The Apache License Version 2.0.

About

Elasticsearch Watcher extensions for NEST

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C# 94.5%
  • F# 3.7%
  • Other 1.8%