Last active
August 29, 2015 14:08
-
-
Save marklin-latte/d63be3c4926e7b0d671b to your computer and use it in GitHub Desktop.
ElasticSearch-Use elasticsearch.net create attachment type of document
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//oepn file and convert to base64 | |
FileStream inFile = System.IO.File.Open(@"c:\\testtest.docx", FileMode.OpenOrCreate, FileAccess.Read); | |
byte[] binaryData = new Byte[inFile.Length]; | |
inFile.Read(binaryData, 0, (int)inFile.Length); | |
inFile.Close(); | |
var base64String = System.Convert.ToBase64String(binaryData, 0, binaryData.Length); | |
//---------------------------------------------------------------------- | |
//create elasticsearch connect | |
var client = new ElasticsearchClient(); | |
var myJson = new | |
{ | |
file = base64String | |
}; | |
//(Index,Type,Id,document) | |
client.Index("test", "attachment", "1", myJson); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment