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