Я использую следующий код для индексации документа и результатов тестирования, используя NEST в основном приложении .net.
Но это не возвращает никакой записи.
Так что я неправильно выполняю индексацию или у меня проблема с запросом.
Очень плохо знаком с упругим поиском. Так что не знаю, что не так со следующим кодом, так как я пытаюсь проиндексировать текстовый файл и ищу его для тестирования.
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;
}