Index Warmers with ElasticsearchCRUD

This article shows how to use index warmers with ElasticsearchCRUD. Warmers are useful for the most used queries, and can help with performance. A warmer can be added when creating an index, added any time after or deleted from an index. Warmers can also be added globally or per index type.


Other Tutorials:

Part 1: ElasticsearchCRUD introduction
Part 2: MVC application search with simple documents using autocomplete, jQuery and jTable
Part 3: MVC Elasticsearch CRUD with nested documents
Part 4: Data Transfer from MS SQL Server using Entity Framework to Elasticsearch
Part 5: MVC Elasticsearch with child, parent documents
Part 6: MVC application with Entity Framework and Elasticsearch
Part 7: Live Reindex in Elasticsearch
Part 8: CSV export using Elasticsearch and Web API
Part 9: Elasticsearch Parent, Child, Grandchild Documents and Routing
Part 10: Elasticsearch Type mappings with ElasticsearchCRUD
Part 11: Elasticsearch Synonym Analyzer using ElasticsearchCRUD
Part 12: Using Elasticsearch German Analyzer
Part 13: MVC google maps search using Elasticsearch
Part 14: Search Queries and Filters with ElasticsearchCRUD
Part 15: Elasticsearch Bulk Insert
Part 16: Elasticsearch Aggregations With ElasticsearchCRUD
Part 17: Searching Multiple Indices and Types in Elasticsearch
Part 18: MVC searching with Elasticsearch Highlighting
Part 19: Index Warmers with ElasticsearchCRUD

Adding a warmer when creating an index

A warmer can be added to an index when creating it. The IndexCreate method provides a Warmers property function for this. The Warmers list can accept queries or aggregations.

new IndexDefinition
	IndexWarmers = new IndexWarmers
		Warmers = new List<IndexWarmer>
			new IndexWarmer("filter_mph")
				Query= new Query(
					new Filtered(
						new Filter(
							new RangeFilter("speeddoublemph")
								GreaterThanOrEqualTo= 50.0

The index put with the warmer is set to Elasticsearch in a HTTP PUT request

PUT http://localhost:9200/fastestanimals HTTP/1.1
Content-Type: application/json
Host: localhost:9200
Content-Length: 198
Expect: 100-continue

	"settings": {
		"analysis": {
		"number_of_shards": 5,
		"number_of_replicas": 1
	"aliases": {
	"warmers": {
		"filter_mph": {
			"source": {
				"query": {
					"filtered": {
						"filter": {
							"range": {
								"speeddoublemph": {
									"gte": 50.0

Creating a warmer for an existing index

A warmer can be added to an index using the WarmerCreate method. If the index parameter is defined, it is and to the index with the all name.

_context.WarmerCreate(new Warmer("all")
	Query = new Query(
		new MatchAllQuery()
}, "fastestanimals");

The warmer is added to the index using a HTTP PUT request

PUT http://localhost:9200/fastestanimals/_warmer/all HTTP/1.1
Content-Type: text/plain; charset=utf-8
Host: localhost:9200
Content-Length: 26
Expect: 100-continue


Deleting a warmer

A warmer can also be deleted from a index:

_context.WarmerDelete("all", "fastestanimals");

Sent as follows:

DELETE http://localhost:9200/fastestanimals/_warmer/all HTTP/1.1
Host: localhost:9200
Content-Length: 0


One comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: