Elasticsearch Nest不插入文档

时间:2018-11-30 15:18:27

标签: c# elasticsearch asp.net-web-api nest

我有两种 POCO类型  PdfIndex和PieceEM:

 public class PdfIndex
 {
    public string Path { get; set; }
    public PieceEM Pdf { get; set; }
 }

还有PieceEM:

public class PieceEM
{
    public string Id { get; set; }
    public string Content { get; set; }
    public string Language { get; set; }
    public string Profession { get; set; }
    public string DeparmentOfPiece { get; set; }
    public string PieceType { get; set; }
    public string PricingType { get; set; }
    public string PieceId { get; set; }
    public string Author { get; set; }
}

所有pdf均已读取但未编入索引。 代码不会失败,仅此地址没有数据 http://localhost:9200/fullegalpieces/_search?pretty=true

这是我的索引代码:

public void IndexPiece(IEnumerable<PdfIndex> pdfIndexes)
    {
        foreach (var pdfIndex in pdfIndexes)
        {
            if (!File.Exists(pdfIndex.Path)) continue;

            var pdfReader = new PdfReader(pdfIndex.Path);
            string text = string.Empty;
            for (int page = 1; page <= pdfReader.NumberOfPages; page++)
            {
                text += PdfTextExtractor.GetTextFromPage(pdfReader, page);
            }
            pdfReader.Close();

            PieceEM _pdf = pdfIndex.Pdf;
            _pdf.Content = IndexDocumentHelper.RemoveSpecialChar(text);
            _pdf.Content += _pdf.Author;

            _elasticClient.Index(_pdf, i => i
            .Type<PieceEM>());
        }
    }

路径正确。 该pdf文件在本地存在, 而我的发布操作在这里:

     [HttpPost]
    public void IndexPiece(List<PdfIndex> pdfIndexes)
    {
        var elastic = new ElasticHelper.ElasticSearchHelper("http://localhost:9200/", "fullegalpieces");
        elastic.IndexPiece(new List<PdfIndex> {
            new PdfIndex
            {
                Path = @"C:\Users\Yılmaz\Desktop\özgeçmiş.pdf",
                Pdf = new PieceEM
                {
                    Id = "042f01f8-befc-40a7-9339-fa4fffe2c4e0",
                    PieceId = "bd7aaa9c-7c81-4675-a037-0fa56ad09003",
                    Language = "1",
                    PieceType ="2",
                    PricingType = "1",
                    Profession = "1",
                    Author = "ykaraagac",
                    DeparmentOfPiece = "1"
                }
            }
        });


    }

我有类似的例子,但这是行不通的。 我能做什么?

谢谢。

1 个答案:

答案 0 :(得分:0)

我检查了本地日志文件,然后看到了:

我索引了不同的POCO类型,而不是PieceEM