KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I'm trying to index a pdf document with elasticsearch/NEST. The file is indexed but search results returns with 0 hits. I need the search result to return only the document Id and the highlight result (without the base64 content) Here is the code: I'll appreciate any help here, Thanks, class Program { static void Main(string[] args) { // create es client string index = "myindex"; var settings = new ConnectionSettings("localhost", 9200) .SetDefaultIndex(index); var es = new ElasticClient(settings); // delete index if any es.DeleteIndex(index); // index document string path = "test.pdf"; var doc = new Document() { Id = 1, Title = "test", Content = Convert.ToBase64String(File.ReadAllBytes(path)) }; var parameters = new IndexParameters() { Refresh = true }; if (es.Index<Document>(doc, parameters).OK) { // search in document string query = "semantic"; // test.pdf contains the string "semantic" var result = es.Search<Document>(s => s .Query(q => q.QueryString(qs => qs .Query(query) ) ) .Highlight(h => h .PreTags("<b>") .PostTags("</b>") .OnFields( f => f .OnField(e => e.Content) .PreTags("<em>") .PostTags("</em>") ) ) ); if (result.Hits.Total == 0) { } } } } [ElasticType( Name = "document", SearchAnalyzer = "standard", IndexAnalyzer = "stan
Tags (comma-separated)
Save Edits
Cancel