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 = "standard"
)]
public class Document
{
public int Id { get; set; }
[ElasticProperty(Store = true)]
public string Title { get; set; }
[ElasticProperty(Type = FieldType.attachment,
TermVector = TermVectorOption.with_positions_offsets)]
public string Content { get; set; }
}
I am working on the same so now i am trying this http://www.elasticsearch.cn/tutorials/2011/07/18/attachment-type-in-action.html
This article explains issue
pay attension that you should do correct mapping
I will try to figure out how to do that with NEST api and update this post
// I am using FSRiver plugin - https://github.com/dadoonet/fsriver/
Install the Attachment Plugin and restart ES
Create an Attachment Class that maps to the Attachment Plugin Documentation
Add a property on the Document class you are indexing with the name "File" and correct mapping
Create your index explicitly before you index any instances of your class. If you don't do this, it will use dynamic mapping and ignore your attribute mapping. If you change your mapping in the future, always recreate the index.
Index your item
Search on the File property
You need to add the mapping like below before you index items.