【发布时间】:2019-11-08 17:15:09
【问题描述】:
我正在使用以下代码在 .net 核心应用程序中使用 NEST 来索引文档和测试结果。 但它没有返回任何记录。
所以要么我做错了索引,要么我有查询问题。
弹性搜索非常新。所以不知道下面的代码有什么问题,因为我正在尝试索引文本文件的文本并搜索它进行测试。
private static void Index()
{
var settings = new ConnectionSettings().DefaultIndex("ProjectDocuments");
var client = new ElasticClient(settings);
//First, you need to make the routing required when you are creating your index, like this:
client.CreateIndex("ProjectDocuments", d => d
.Mappings(mapping => mapping
.Map<Document>(map => map
.RoutingField(routing => routing
.Required(true))
.AutoMap())
));
Routing routingFromInt = 1;
Document document = new Document()
{
Id = 1,
Content = "Some Text File Text"
};
IIndexResponse result = client.Index<Document>(document, selector => selector
.Id(1)
.Routing(routingFromInt));
//TODO: Following returns 0. so might be issue with indexing itself.
ISearchResponse<Document> searchResponse = client.Search<Document>(query => query.Query(q => q.MatchAll()).Routing(routingFromInt));
var documents = searchResponse.Documents;
}
【问题讨论】:
标签: c# elasticsearch nest