查询时间很长

时间:2015-02-03 15:24:47

标签: c# visual-studio elasticsearch nest

我是弹性搜索世界的新手,我正试图用NEST aPI在c#中编码。

我成功地用一些内容索引了一些文档,但是当我尝试搜索时,研究需要大约4秒。

我使用visual studio 2012

我希望你能帮助我:)。

[ElasticType(Name = "document")]
public class Document
{
    public int Id { get; set; }

    [ElasticProperty(Store = true)]
    public string Titre { get; set; }

    [ElasticProperty(Type = FieldType.Attachment, TermVector = TermVectorOption.WithPositionsOffsets, Store = true)]
    public Attachment File { get; set; }
}

public class Attachment
{
    [ElasticProperty(Name = "_content")]
    public string Content { get; set; }

    [ElasticProperty(Name = "_content_type")]
    public string ContentType { get; set; }

    [ElasticProperty(Name = "_name")]
    public string Name { get; set; }
}

static int i = 0;
static int j = 0;

这是我班级的声明

static void Main(string[] args)
{
    //New connection
    //var node = new Uri("http://serv-intra:9200");

    var node = new Uri("http://localhost:9200/");

    var settings = new ConnectionSettings(
        node,
        defaultIndex: "document"
        );

    var client = new ElasticClient(settings);

    //Creation of my index with mapping
    //client.CreateIndex("document", c => c
    //  .AddMapping<Document>(m => m.MapFromAttributes())
    //  );

    //function for index
    //feignasse(client);

    var query = Query<Document>.Term("_all", "chu");

    var searchResults = client.Search<Document>(s => s
            .From(0)
            .Size(200)
            .Query(query)
    );
}

protected static void feignasse(ElasticClient client)
{
    // Create new stopwatch
    Stopwatch stopwatch = new Stopwatch();

    // Begin timing
    stopwatch.Start();

    Indexation(@"\\serv-intra\Documents", client);

    // Stop timing
    stopwatch.Stop();
}

//This is my function for index
protected static void Indexation(string path, ElasticClient client)
{
    string[] rootDirectories = Directory.GetDirectories(path);

    string[] rootFiles = Directory.GetFiles(path);

    foreach (string nomfich in rootFiles)
    {

        if (nomfich.Length < 256)
        {
            FileInfo file = new FileInfo(nomfich);

            var attachement = new Attachment();
            attachement.Content = Convert.ToBase64String(File.ReadAllBytes(nomfich));
            attachement.Name = file.Name;
            attachement.ContentType = GetMimeType(file.Extension);

            var document = new Document
            {
                Id = i,
                Titre = file.Name,
                File = attachement,

            };

            var index = client.Index(document);
            i++;
        }
        else
        {
            j++;
        }
    }

    foreach (string newPath in rootDirectories)
    {
        Indexation(newPath, client);
    }

所以我解释一下,在我的服务器中我有一个文档的共享,我只是为了抓住我的所有文档和索引然后在弹性搜索中旅行他

我必须使用0副本和5个分片

谢谢你

0 个答案:

没有答案