Документация ElasticSearch далеко не приличная, поэтому я спрашиваю здесь после прочтения.
Я привел самый простой пример упругого поиска после просмотра их ужасной документации.
Я получил локальный клиентasticsearch (запускается на localhost: 9200) и библиотеку NEST, чтобы попытаться создать простую консольную программу, которая индексирует некоторые файлы и пытается искать их по имени.
Может ли кто-нибудь мне помочь и сказать, почему я не вижу результата?
using Nest;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ElasticHorror
{
class Program
{
static void Main(string[] args)
{
Uri connectionString = new Uri("http://localhost:9200");
//Client settings, index must be lowercase
var settings = new ConnectionSettings(connectionString).DefaultIndex("tests");
settings.PrettyJson();
settings.ThrowExceptions();
//Client initialization
var client = new ElasticClient(settings);
//Index creation, I use a forced bool for testing in a console program only ;)
bool firstRun = true;
if (firstRun)
{
foreach(string file in Directory.GetFiles(@"G:\SomeFolderWithFiles", "*.*", SearchOption.AllDirectories))
{
Console.WriteLine($"Indexing document {file}");
client.IndexDocument<FileProps>(new FileProps(new FileInfo(file)));
}
}
var searchResponse = client.Search<FileProps>(s => s.Query(
doc => doc.Term(t => t.Name, "Test")))
.Documents;
}
internal class FileProps
{
public FileProps(FileInfo x)
{
CreationTime = x.CreationTime;
Extension = x.Extension;
FullName = x.FullName;
Lenght = x.Length;
Name = x.Name;
Directory = x.DirectoryName;
}
[Date]
public DateTime CreationTime { get; private set; }
public string Extension { get; private set; }
public string FullName { get; private set; }
public long Lenght { get; private set; }
public string Name;
public string Directory;
}
}
}
Спасибо