Created
February 18, 2014 16:20
-
-
Save antonydenyer/9074159 to your computer and use it in GitHub Desktop.
Automatic id generation and mapping _id NEST
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.Linq; | |
using NUnit.Framework; | |
namespace Nest.AutoId | |
{ | |
[ElasticType(Name = "data", IdProperty = "Id")] | |
public class DataForGet : DataForIndex | |
{ | |
public string Id { get; set; } | |
} | |
[ElasticType(Name = "data")] | |
public class DataForIndex | |
{ | |
public string Name { get; set; } | |
// some other fields... | |
} | |
[TestFixture] | |
public class ElasticsearchTests | |
{ | |
readonly ElasticClient client = new ElasticClient(new ConnectionSettings(new Uri("http://localhost:9200"))); | |
[Test] | |
public void index_an_item() | |
{ | |
var data = new DataForIndex | |
{ | |
Name = "Dave" | |
}; | |
client.Index(data, "index"); | |
} | |
[Test] | |
public void get_an_item() | |
{ | |
var item = client.Search<DataForGet>(x => x.Index("index")); | |
Console.WriteLine(string.Join(Environment.NewLine, item.Documents.Select(x => x.Id + " : " + x.Name))); | |
} | |
} | |
} |
this is not testable in it's entirety given .Select
is an extension method (i'm constrained to using just Moq). Is there an alternative? possibly with the mappings itself?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@TinTin04 you are correct here.
When working with autoassigned id's you will have to use the full
IHit<T>
object in DocumentsWithMetaData.