弹性搜索(使用 NEST)returns MatchAll() 上的 0 个结果
Elastic search (using NEST) returns 0 results on MatchAll()
我正在使用以下代码在 .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;
}
问题与默认索引名称有关。弹性搜索不支持 大写的索引名称 。
所以“ProjectDocuments”导致了问题。将其更改为“project_documents”并开始工作。
我正在使用以下代码在 .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;
}
问题与默认索引名称有关。弹性搜索不支持 大写的索引名称 。
所以“ProjectDocuments”导致了问题。将其更改为“project_documents”并开始工作。