I used NEST for indexing documents to ElasticSearch. Here is the code
snippet.
try
{
Task<IBulkResponse> bulkResponse;
foreach (string currentItem in files)
{
log.Info("Started indexing information into
elasticSearch" + currentItem);
byte[] fileArray = File.ReadAllBytes(currentItem);
int entityId = IndexerHelper.GetEntityId(currentItem);
string myType = IndexerHelper.GetTypeName(currentItem);
bulkRequest.Index<Attachments>(m => m.Object(new
Attachments
{
AttachmentContenttype =
IndexerHelper.GetContentType(currentItem),
AttachmentEncodedfile =
Convert.ToBase64String(fileArray, 0,
fileArray.Length,Base64FormattingOptions.InsertLineBreaks),
AttachmentFullpath = currentItem,
AttachmentLastmodified =
File.GetLastWriteTime(currentItem),
AttachmentParentId =
IndexerHelper.GetParentId(currentItem)
})
.Index(indexName)
.Type(myType)
.Id(entityId)
);
bulkCount++;
if (bulkRequestSize == bulkCount)
{
bulkResponse = esBulkClient.BulkAsync(bulkRequest);
bulkCount = 0;
bulkRequest = new BulkDescriptor();
}
fileArray = null;
}
bulkResponse = esBulkClient.BulkAsync(bulkRequest);
foreach (BulkOperationResponseItem item in
bulkResponse.Result.Items)
{
if (item.OK == false && item.Error != null)
{
log.Error("Not indexed ID:" + item.Id + " of Type:"
+ item.Type);
log.Error(" Error is:" + item.Error);
}
}
On Mon, Mar 31, 2014 at 3:42 PM, Binh Ly <[email protected]> wrote:
> Can you show the code of how you index the pdf as well as the mapping?
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "elasticsearch" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/elasticsearch/RU5a2wSZCYc/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/elasticsearch/babcf89c-c808-4787-a6e0-69e5c5967328%40googlegroups.com<https://groups.google.com/d/msgid/elasticsearch/babcf89c-c808-4787-a6e0-69e5c5967328%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>
--
R R R
--
You received this message because you are subscribed to the Google Groups
"elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/elasticsearch/CAOLrPN7JFp1wwKmktk%3Dqn-Tm7oNgBVQ%3DmtM6E0MdVFDSu0bn6g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.