Hi All,
I'm trying to reproduce a console application which watches a folder and any new additions of documents to the folder are to be Indexed to ES .
It is working fine If I move/add 3-4 documents at a time and able to index. But if I move around 30 documents at a time, It is not indexing all the documents, instead indexing only one. But If I run the code with break points , then even 30 documents are also getting indexed.
Can some one help me in solving this.
static void OnCreated(object sender, FileSystemEventArgs e)
{
Console.WriteLine("File Created: Path: {0}, \n Name: {1}", e.FullPath, e.Name);
Indexdoc(e.FullPath);
}
If I dont call the Indexdoc(e.FullPath) method in the above code and instead print the changes, it is showing all the filenames added perfectly. so there is no problem with the filesystemwatcher. I think indexing documents is taking time to generate response and come back to onCreated method.
public static void Indexdoc(string newFilePath)
{
List<Document> list = new List<Document>(); //list of Document class objects
List<string> filesList = new List<string>(); //list of files in the path received on method call
string path = string.Empty;
client = ConfigSettings.connection();
if (newFilePath == null) //for FULL Indexing
{
//some code here
}
else //for new files indexing
{
filesList.Add(newFilePath); //adds only one file everytime the method is called.
//the newFilePath will be of type C:/Documents/abc.txt
}
try
{
foreach (string file in filesList)
{
Attachment attach = new Attachment
{
Name = Path.GetFileNameWithoutExtension(file),
Content = Convert.ToBase64String(File.ReadAllBytes(file)),
ContentType = Path.GetExtension(file)
};
var doc = new Document()
{
Title = Path.GetFileNameWithoutExtension(file),
FilePath = Path.GetFullPath(file), //added to get the path of the file
File = attach
};
list.Add(doc);
}
}
catch (Exception e)
{
Console.WriteLine(e.Message.ToString());
}
var response = client.IndexMany(list, "trial");
}
Can some one help me in solving this.
TIA