Last active
August 29, 2015 14:18
-
-
Save dbones/5a52387c85369d41b0b4 to your computer and use it in GitHub Desktop.
NEST mapping, index only the first name
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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