【发布时间】:2016-04-15 01:30:20
【问题描述】:
我是 Elasticsearch 和 Nest 的新手,遇到了问题。我想要做的是创建一个索引并索引一个带有嵌套字段的文档。
[ElasticsearchType]
public class TestType
{
[Nest.String(Store = true, Index = FieldIndexOption.Analyzed )]
public string Text { get; set; }
[Nested(IncludeInAll = true)]
public List<NestedTestType> Nests { get; set; } = new List<NestedTestType>();
public string Id { get; set; }
}
[ElasticsearchType]
public class NestedTestType
{
[Nest.String(Store = true, Index = FieldIndexOption.Analyzed)]
public string Value { get; set; }
[Nest.String(Store = false)]
public string NotStoredValue { get; set; }
}
在函数中是
var connectionPool = new Elasticsearch.Net.SniffingConnectionPool(poolUris);
var settings = new ConnectionSettings(connectionPool);
client = new ElasticClient(settings);
string testIndexName = "test";
var createIndeReponse = client.CreateIndex(testIndexName);
var mappingResponse = client.Map<TestType>(m => m.Index(testIndexName).AutoMap());
mappingResponse = client.Map<NestedTestType>(m => m.Index(testIndexName).AutoMap());
TestType testData = new TestType() { Text = "Hello world" };
testData.Nests.Add( new NestedTestType() { Value = "In the list", NotStoredValue = "Not stored"} );
IndexRequest<TestType> indexRequest = new IndexRequest<TestType>(testIndexName, "test_type");
indexRequest.Document = testData;
IIndexResponse iir = client.Index(indexRequest);
但是,最后一行的 iir 包含错误“对象映射 [嵌套] 无法从嵌套更改为非嵌套”
我的问题是:
建立索引的正确方法是什么? 我在哪里可以找到对我有进一步帮助的文档?
【问题讨论】:
-
可以分享一下你的索引映射吗(localhost:9200/test/_mapping)?
标签: elasticsearch nest