Skip to content

Instantly share code, notes, and snippets.

@marklin-latte
Last active August 29, 2015 14:08
Show Gist options
  • Save marklin-latte/d63be3c4926e7b0d671b to your computer and use it in GitHub Desktop.
Save marklin-latte/d63be3c4926e7b0d671b to your computer and use it in GitHub Desktop.
ElasticSearch-Use elasticsearch.net create attachment type of document
//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