Skip to content

Instantly share code, notes, and snippets.

@Yegoroff
Yegoroff / app.config
Created March 13, 2013 23:07
AssemblyResolver for Newtonsoft.Json
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<!-- Commented out binding redirect.
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.8.0" newVersion="4.0.8.0" />
</dependentAssembly>
@Yegoroff
Yegoroff / gist:4959198
Created February 15, 2013 08:47
PlainElastic.Net QueryBuilder with Sort and ignore_unmapped parameter
SearchResult<Tweet> searchResult = client.Search(
new SearchCommand("twitter", "tweet"),
new QueryBuilder<Tweet>()
.Query(q => q
.Term(t => t
.Field(tweet => tweet.User)
.Value("testUser")
.Boost(2)
)
)
@Yegoroff
Yegoroff / IndexSettings.cs
Created July 11, 2012 23:27
PlainElastic.Net Index Settings sample
using System;
using PlainElastic.Net;
using PlainElastic.Net.IndexSettings;
namespace IndexSettigsSample
{
class Program
{
static void Main()
{
@Yegoroff
Yegoroff / MappingSample.cs
Last active October 7, 2015 02:58
PlainElastic.Net mapping builder sample
using System;
using System.Collections.Generic;
using System.Linq;
using PlainElastic.Net;
using PlainElastic.Net.Mappings;
using PlainElastic.Net.Queries;
using PlainElastic.Net.Serialization;
using PlainElastic.Net.Utils;
namespace MappingSample
@Yegoroff
Yegoroff / gist:3093936
Created July 11, 2012 22:02
PlainElastic.Net facet query builder sample
using System;
using PlainElastic.Net;
using PlainElastic.Net.Queries;
using PlainElastic.Net.Serialization;
using PlainElastic.Net.Utils;
namespace FacetQuerySample
{
class Item
@Yegoroff
Yegoroff / ConditionQueryBuilder.cs
Created May 21, 2012 23:17
PlainElastic.Net condition-less query builder sample
using System;
using System.Linq;
using PlainElastic.Net;
using PlainElastic.Net.Queries;
using PlainElastic.Net.Serialization;
using PlainElastic.Net.Utils;
namespace PlainSample
{
class Program
@Yegoroff
Yegoroff / QueryBuilderSample.cs
Created May 21, 2012 22:57
PlainElastic.Net query builder sample
using System;
using System.Linq;
using PlainElastic.Net;
using PlainElastic.Net.Queries;
using PlainElastic.Net.Serialization;
using PlainElastic.Net.Utils;
namespace PlainSample
{
class User
@Yegoroff
Yegoroff / gist:2585324
Created May 3, 2012 12:29
MongoDb PreserveValueIfNull
static class MongoSerializationExtensions
{
public static BsonMemberMap PreserveValueIfNull(this BsonMemberMap memberMap)
{
var originalSetter = memberMap.Setter;
Action<object, object> preserveSetter = (obj, value) => {
if (value != null)
originalSetter(obj, value);
};
@Yegoroff
Yegoroff / gist:2346762
Created April 9, 2012 21:49
Custom Property Mapping
var doc = new EsDocument(); // Some complex object that holds dictionary of runtime user-defined fields.
// doc.Fields = Dictionary<string, UserDefinedField>;
// where UserDefinedField.Name is equal to dictionary Key
// e.g. Fields["FName"] = new UserDefinedField{Name = "FName"};
// and UserDefinedField.Attributes is user-defined attributes that controls mapping.
// and UserDefinedField.ContainsAttribute(attribute) returns true if such attribute set for this field.
// Here we define custom field mapping for each user-defined field in doc object.
var properties = new List<CustomPropertyMap>();
@Yegoroff
Yegoroff / ESBulkSample.cs
Last active October 2, 2015 11:18
Elastic Search Bulk
// Sample of Bulk functionality
var connection = new ElasticConnection("localhost", 9200);
var serializer = new JsonNetSerializer();
var command = new BulkCommand(index: "myindex", type: "mytype");
// MANUAL BULK CONSTRUCTION.