ElasticSearch documentation is far from decent, so I ask here after reading them.
I've put up the easiest elasticsearch example after looking at their horrific documentation.
I got local elasticsearch client (starts on localhost:9200) and NEST library to try and put up a simple console program that indexes some files and try to search them by name.
Can someone help me and tell me why I don't find any result?
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;
}
}
}
Thanks
bool firstRun = false; if (firstRun) { /* when will this run? */ }