//using iTextSharp.text;
//using iTextSharp.text.pdf;
using Nest;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication10
{
class Program
{
[ElasticsearchType(Name = "pdfs")]
public class Case
{
public string Author { get; set; }
public string CaseName { get; set; }
[Attachment(Store = true)]
public string attachfile { get; set; }
//[String(Name = "_content_type")]
public string Content { get; set; }
public Case()
{
}
//public override string ToString()
//{
// return "Case: " + Author + " - " + File.Name;
//}
}
//public class Attachment
//{
// [String(Name = "_content")]
// public string Content { get; set; }
// [String(Name = "_content_type")]
// public string ContentType { get; set; }
// [String(Name = "_name")]
// public string Name { get; set; }
//}
static void Main(string[] args)
{
var index = "pg";
var node = new Uri("http://localhost:9200");
var settings = new ConnectionSettings(node).DefaultIndex(index);
var client = new ElasticClient(settings);
// var attachment = new Attachment();
string path = @"C:\Elasticsearch_The Definitive Guide.pdf";
// attachment.Name = path;
//attachment.Content = Convert.ToBase64String(File.ReadAllBytes(path));
//Case.ContentType = "application/json";
//obj.attachfile= Convert.ToBase64String(File.ReadAllBytes(path));
Case obj = new Case();
obj.Content = Convert.ToBase64String(File.ReadAllBytes(path));
var doc2 = new Case()
{
Author = "Martin Luther 2",
CaseName = "Bank vs Martin",
attachfile = obj.attachfile
};
client.Map<Case>(m => m
.Properties(ps => ps
.String(s => s
.Name(f => f.CaseName)
.Index(FieldIndexOption.Analyzed)
.Store(true))
.Attachment(atm => atm
.Name(p => p.attachfile)
.FileField(f => f
.Name(p => p.attachfile)
.Index(FieldIndexOption.Analyzed)
.Store(true)
.TermVector(TermVectorOption.WithPositionsOffsets))
.AuthorField(af => af
.Name(p => p.Author)
.Store(true)
.Index(FieldIndexOption.Analyzed)
.TermVector(TermVectorOption.WithPositionsOffsets))))
);
var indexingthedoc = client.Index<Case>(doc2);
Console.Write(indexingthedoc.CallDetails);
Console.Read();
}
}
}