Skip to content

Instantly share code, notes, and snippets.

@dbones
Last active August 29, 2015 14:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dbones/5a52387c85369d41b0b4 to your computer and use it in GitHub Desktop.
Save dbones/5a52387c85369d41b0b4 to your computer and use it in GitHub Desktop.
NEST mapping, index only the first name
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace TestIndex
{
using Nest;
class Program
{
static void Main(string[] args)
{
var node = new Uri("http://localhost:9200");
var settings = new ConnectionSettings(
node,
defaultIndex: "test"
);
var client = new ElasticClient(settings);
client.Map<Person>(m =>
m.IdField(f => f.Path("id"))
.IncludeInAll(false)
.SourceField(s=>s.Excludes(new []{"lastname"}))
.Properties(p =>
p.String(s => s.Name(n => n.Firstname).Analyzer("standard").Index(FieldIndexOption.Analyzed).Store(false))
//.String(s => s.Name(n => n.Lastname).Analyzer("standard").Index(FieldIndexOption.Analyzed).Store())
// .Object<string>(x=>x.Enabled(false).Name(n=>n.Lastname))
)
);
var person = new Person
{
Id = "3",
Firstname = "bob",
Lastname = "rundle"
};
var index = client.Index(person);
var result = client.Search<Person>(s => s.Query(q => q.Term(p => p.Firstname, "bob")).Fields(p=>p.Id));
var id = result.Hits.First().Fields.FieldValues<string[]>("id").First();
}
}
public class Person
{
public string Id { get; set; }
public string Firstname { get; set; }
public string Lastname { get; set; }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment