Skip to content

Instantly share code, notes, and snippets.

View ThomasArdal's full-sized avatar
🎢

Thomas Ardal ThomasArdal

🎢
View GitHub Profile
@ThomasArdal
ThomasArdal / Elasticsearch install script
Created May 5, 2014 11:46
Script to setup Elasticsearch on Linux
#!/usr/bin/env bash
# update apt
sudo apt-get update
# install java
sudo apt-get install openjdk-7-jre-headless -y
# install elasticsearch
wget https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-1.1.1.deb
@ThomasArdal
ThomasArdal / Vagrant up output
Created May 5, 2014 11:49
Output from Vagrant when installing Elasticsearch
Bringing machine 'default' up with 'virtualbox' provider...
[default] Importing base box 'precise32'...
...
[default] Machine booted and ready!
...
Setting up openjdk-7-jre-headless (7u55-2.4.7-1ubuntu1~0.12.04.2) ...
...
--2014-05-05 07:50:35-- https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-1.1.1.deb
...
sudo /etc/init.d/elasticsearch start
@ThomasArdal
ThomasArdal / Customer.cs
Created June 12, 2014 18:33
Elasticsearch migration c# example
namespace ConsoleApplication1
{
public class Customer
{
public int Zipcode { get; set; }
}
}
@ThomasArdal
ThomasArdal / gist:ce32939ef1a5a079fed5
Created June 16, 2014 06:20
Create a new versioned Elasticsearch index
var connectionSettings = new ConnectionSettings(new Uri("http://localhost:9200/"));
connectionSettings.SetDefaultIndex("customers");
var elasticClient = new ElasticClient(connectionSettings);
elasticClient.CreateIndex("customers-v1");
elasticClient.Alias(x => x.Add(a => a.Alias("customers").Index("customers-v1")));
elasticClient.Map<Customer>(d =>
d.Properties(p => p.Number(n => n.Name(name => name.Zipcode).Index(NonStringIndexOption.not_analyzed))));
@ThomasArdal
ThomasArdal / gist:ee68ca8bf6638beeaac7
Created June 16, 2014 06:21
Index a new customer using Elasticsearch
elasticClient.Index(new Customer { Zipcode = 8000 });
@ThomasArdal
ThomasArdal / gist:7f8c77306550948277ec
Created June 16, 2014 06:21
Reindex versioned Elasticsearch index
var reindex =
elasticClient.Reindex<Customer>(r =>
r.FromIndex("customers-v1")
.ToIndex("customers-v2")
.Query(q => q.MatchAll())
.Scroll("10s")
.CreateIndex(i =>
i.AddMapping<Customer>(m =>
m.Properties(p =>
p.String(n => n.Name(name => name.Zipcode).Index(FieldIndexOption.not_analyzed))))));
@ThomasArdal
ThomasArdal / gist:9f8b039637e9bb826f53
Created June 16, 2014 06:22
Delete Elasticsearch index and create alias
elasticClient.DeleteIndex(d => d.Index("customers-v1"));
elasticClient.Alias(x => x.Add(a => a.Alias("customers").Index("customers-v2")));
@ThomasArdal
ThomasArdal / gist:edb530911d051dae8ceb
Last active August 29, 2015 14:06
Example of doing aggregated search using Elasticsearch and NEST
var result = elasticClient.Search<ErrorDocument>(search => search
.SearchType(SearchType.Count)
.Query(q => q
.Range(range => range
.OnField(field => field.Time)
.GreaterOrEquals(DateTime.UtcNow.AddHours(-24))
.LowerOrEquals(DateTime.UtcNow)
)
)
.Aggregations(a => a
@ThomasArdal
ThomasArdal / project.csproj
Last active August 29, 2015 14:06
Debug property group
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
@ThomasArdal
ThomasArdal / project.csproj
Last active August 29, 2015 14:06
Debug Property Group With Experimental
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<LangVersion>Experimental</LangVersion>