elasticsearch 使用ingest attachment进行批量索引(大约40K类型的.docx文件)的嵌套方式是什么?,elasticsearch,logstash,elastic-stack,elasticsearch,Logstash,Elastic Stack" /> elasticsearch 使用ingest attachment进行批量索引(大约40K类型的.docx文件)的嵌套方式是什么?,elasticsearch,logstash,elastic-stack,elasticsearch,Logstash,Elastic Stack" />

elasticsearch 使用ingest attachment进行批量索引(大约40K类型的.docx文件)的嵌套方式是什么?

elasticsearch 使用ingest attachment进行批量索引(大约40K类型的.docx文件)的嵌套方式是什么?,elasticsearch,logstash,elastic-stack,elasticsearch,Logstash,Elastic Stack,我非常熟悉麋鹿堆栈,目前正在使用Elastic search 6.6。我们的用例是对大约40K.docx文件的内容搜索 (由投资组合经理上传为研究报告。 允许的最大文件大小为10 MB,但大多数文件大小为几Kb)。 我已经使用ingest附件插件为样本测试文件编制索引,并且我还能够使用KIBANA搜索内容 例如:POST/attachment\u test/my\u type/\u search?pretty=true { “查询”:{ “匹配”:{ “附件.内容”:“摩根大通” } } }

我非常熟悉麋鹿堆栈,目前正在使用Elastic search 6.6。我们的用例是对大约40K.docx文件的内容搜索 (由投资组合经理上传为研究报告。 允许的最大文件大小为10 MB,但大多数文件大小为几Kb)。 我已经使用ingest附件插件为样本测试文件编制索引,并且我还能够使用KIBANA搜索内容 例如:POST/attachment\u test/my\u type/\u search?pretty=true

{
“查询”:{
“匹配”:{
“附件.内容”:“摩根大通”
}
}
}
将预期结果返回给我。 我的疑问是:

  • 使用ingest插件,我们需要将数据推送到插件。我正在使用VS2017和弹性嵌套dll。这意味着,我必须以编程方式读取40K文档,并使用NEST命令将它们推送到ES

  • 我已经通过了Fscrawler项目,知道它可以达到目的,但我将它作为我的最后手段

  • 如果我使用方法1(代码),是否有批量上传API可用于将多个附件一起发布到ES(成批)


  • 最后,我使用C代码将40K个文件上传到弹性索引中:

    私有静态void PopulateIndex(ElasticClient)
    {
    var directory=System.Configuration.ConfigurationManager.AppSettings[“CallReportPath”].ToString();
    var callreportscolection=Directory.GetFiles(Directory,*.doc”);//这将获取doc和docx
    //callReportsCollection.ToList().AddRange(Directory.GetFiles(Directory,*.doc));
    ConcurrentBag reportsBag=新的ConcurrentBag(callReportsCollection);
    int i=0;
    var callReportElasticDataSet=new-DLCallReportSearch().GetCallReportDetailsForElastic();//.AsEnumerable();//.Take(50.CopyToDataTable();
    尝试
    {
    Parallel.ForEach(reportsBag,callReport=>
    //ForEach(callreportscolection,callReport=>
    {
    var base64File=Convert.ToBase64String(File.ReadAllBytes(callReport));
    var fileSavedName=callReport.Replace(目录“”);
    //var dt=dLCallReportSearch.GetCallFileName(fileSavedName.Replace(“,”);//将文件名中的“替换为”;
    var rows=callReportElasticDataSet.Select(“像“%”+fileSavedName.Replace(“”,“”)+“”)这样的调用保存文件;
    if(rows!=null&&rows.Count()>0)
    {
    var row=rows.FirstOrDefault();
    //foreach(数据行中的行)
    //{
    i++;
    client.Index(新文档
    {
    Id=i,
    DocId=Convert.ToInt32(行[“CALL_ID”].ToString()),
    Path=行[“调用保存文件”]。ToString().Replace(CallReportPath,”),
    Title=row[“CALL_FILE”].ToString().Replace(CallReportPath,”),
    Author=行[“用户名”]。ToString(),
    DateOfMeeting=string.IsNullOrEmpty(第[“CALL\u DT”].ToString())行?(DateTime?)null:Convert.ToDateTime(第[“CALL\u DT”].ToString()行),
    位置=行[“调用位置”]。ToString(),
    UploadDate=string.IsNullOrEmpty(第[“调用报告”].ToString())?(日期时间?)null:Convert.ToDateTime(第[“调用报告”].ToString())行,
    CompanyName=行[“COMP_NAME”]。ToString(),
    CompanyId=Convert.ToInt32(行[“COMP_ID”].ToString()),
    Country=行[“COU_NAME”]。ToString(),
    CountryCode=行[“COU_CD”]。ToString(),
    RegionCode=行[“区域代码”]。ToString(),
    RegionName=行[“REGION_NAME”]。ToString(),
    扇区代码=行[“扇区CD”]。ToString(),
    SectorName=行[“扇区名称”]。ToString(),
    Content=base64File
    },p=>p.Pipeline(“附件”);
    //}
    }
    });
    }
    捕获(例外情况除外)
    {
    掷骰子;
    }
    }
    
    可能重复@mihomir,谢谢我看了一下。所以Logstash不是前进的方向。我编辑了我的问题,但我对第3点的疑问仍然没有回答。使用插入附件插件插入40K文件的最佳方式是什么?
     private static void PopulateIndex(ElasticClient client)
        {
            var directory =System.Configuration.ConfigurationManager.AppSettings["CallReportPath"].ToString();
            var callReportsCollection = Directory.GetFiles(directory, "*.doc"); //this will fetch both doc and docx
            //callReportsCollection.ToList().AddRange(Directory.GetFiles(directory, "*.doc"));
            ConcurrentBag<string> reportsBag = new ConcurrentBag<string>(callReportsCollection);
            int i = 0;
            var callReportElasticDataSet = new DLCallReportSearch().GetCallReportDetailsForElastic();//.AsEnumerable();//.Take(50).CopyToDataTable();
            try
            {
                Parallel.ForEach(reportsBag, callReport =>
                //Array.ForEach(callReportsCollection,callReport=>
                {
                    var base64File = Convert.ToBase64String(File.ReadAllBytes(callReport));
                    var fileSavedName = callReport.Replace(directory, "");
                    // var dt = dLCallReportSearch.GetCallFileName(fileSavedName.Replace("'", "''"));//replace the ' in a file name with '';
                    var rows = callReportElasticDataSet.Select("CALL_SAVE_FILE like '%" + fileSavedName.Replace("'", "''") + "'");
                    if (rows != null && rows.Count() > 0)
                    {
                        var row = rows.FirstOrDefault();
                        //foreach (DataRow row in rows)
                        //{
                        i++;
                        client.Index(new Document
                        {
                            Id = i,
                            DocId = Convert.ToInt32(row["CALL_ID"].ToString()),
                            Path = row["CALL_SAVE_FILE"].ToString().Replace(CallReportPath, ""),
                            Title = row["CALL_FILE"].ToString().Replace(CallReportPath, ""),
                            Author = row["USER_NAME"].ToString(),
                            DateOfMeeting = string.IsNullOrEmpty(row["CALL_DT"].ToString()) ? (DateTime?)null : Convert.ToDateTime(row["CALL_DT"].ToString()),
                            Location = row["CALL_LOCATION"].ToString(),
                            UploadDate = string.IsNullOrEmpty(row["CALL_REPORT_DT"].ToString()) ? (DateTime?)null : Convert.ToDateTime(row["CALL_REPORT_DT"].ToString()),
                            CompanyName = row["COMP_NAME"].ToString(),
                            CompanyId = Convert.ToInt32(row["COMP_ID"].ToString()),
                            Country = row["COU_NAME"].ToString(),
                            CountryCode = row["COU_CD"].ToString(),
                            RegionCode = row["REGION_CODE"].ToString(),
                            RegionName = row["REGION_NAME"].ToString(),
                            SectorCode = row["SECTOR_CD"].ToString(),
                            SectorName = row["SECTOR_NAME"].ToString(),
                            Content = base64File
                        }, p => p.Pipeline("attachments"));
                        //}
                    }
                });
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }